do_text.c revision c37a63b8
1264fa531Smrg/* $Xorg: do_text.c,v 1.4 2000/08/17 19:54:10 cpqbld Exp $ */
2264fa531Smrg/*****************************************************************************
3264fa531SmrgCopyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
4264fa531Smrg
5264fa531Smrg                        All Rights Reserved
6264fa531Smrg
7264fa531SmrgPermission to use, copy, modify, and distribute this software and its
8264fa531Smrgdocumentation for any purpose and without fee is hereby granted,
9264fa531Smrgprovided that the above copyright notice appear in all copies and that
10264fa531Smrgboth that copyright notice and this permission notice appear in
11264fa531Smrgsupporting documentation, and that the name of Digital not be
12264fa531Smrgused in advertising or publicity pertaining to distribution of the
13264fa531Smrgsoftware without specific, written prior permission.
14264fa531Smrg
15264fa531SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16264fa531SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17264fa531SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18264fa531SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19264fa531SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20264fa531SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21264fa531SmrgSOFTWARE.
22264fa531Smrg
23264fa531Smrg******************************************************************************/
24264fa531Smrg/* $XFree86: xc/programs/x11perf/do_text.c,v 1.7 2001/01/17 23:45:12 dawes Exp $ */
25264fa531Smrg
26264fa531Smrg#include "x11perf.h"
27264fa531Smrg#include <stdio.h>
28264fa531Smrg
29264fa531Smrgstatic char **charBuf;
30264fa531Smrgstatic XFontStruct *font, *bfont;
31264fa531Smrgstatic int height, ypos;
32264fa531Smrgstatic XTextItem *items;
33264fa531Smrgstatic int charsPerLine, totalLines;
34264fa531Smrg
35264fa531Smrg#define XPOS 20
36264fa531Smrg#define SEGS 3
37264fa531Smrg
38264fa531Smrg
39264fa531Smrgint
40264fa531SmrgInitText(XParms xp, Parms p, int reps)
41264fa531Smrg{
42264fa531Smrg    int		i, j;
43264fa531Smrg    char	ch;
44264fa531Smrg    XGCValues   gcv;
45264fa531Smrg
46264fa531Smrg    font = XLoadQueryFont(xp->d, p->font);
47264fa531Smrg    if (font == NULL) {
48264fa531Smrg	printf("Could not load font '%s', benchmark omitted\n", p->font);
49264fa531Smrg	return 0;
50264fa531Smrg    }
51264fa531Smrg
52264fa531Smrg    bfont = NULL;
53264fa531Smrg    if (p->bfont != NULL) {
54264fa531Smrg	bfont = XLoadQueryFont(xp->d, p->bfont);
55264fa531Smrg	if (bfont == NULL) {
56264fa531Smrg	    printf("Could not load font '%s', benchmark omitted\n", p->bfont);
57264fa531Smrg	    return 0;
58264fa531Smrg	}
59264fa531Smrg    }
60264fa531Smrg
61264fa531Smrg    ypos = XPOS;
62264fa531Smrg    height = (font->max_bounds.ascent + font->max_bounds.descent) + 1;
63264fa531Smrg    if (bfont != NULL) {
64264fa531Smrg	int     h = (bfont->max_bounds.ascent + bfont->max_bounds.descent) + 1;
65264fa531Smrg	if (h > height)
66264fa531Smrg	    height = h;
67264fa531Smrg    }
68264fa531Smrg    gcv.font = font->fid;
69264fa531Smrg    XChangeGC(xp->d, xp->fggc, GCFont, &gcv);
70264fa531Smrg    XChangeGC(xp->d, xp->bggc, GCFont, &gcv);
71264fa531Smrg
72264fa531Smrg    charsPerLine = p->objects;
73264fa531Smrg    charsPerLine = (charsPerLine + 3) & ~3;
74264fa531Smrg    p->objects = charsPerLine;
75264fa531Smrg
76264fa531Smrg    totalLines = '\177' - ' ' + 1;
77264fa531Smrg    if (totalLines > reps) totalLines = reps;
78264fa531Smrg
79264fa531Smrg    charBuf = (char **) malloc(totalLines*sizeof (char *));
80264fa531Smrg    if (p->special)
81264fa531Smrg	items = (XTextItem *) malloc(totalLines*SEGS*sizeof (XTextItem));
82264fa531Smrg
83264fa531Smrg    for (i = 0; i != totalLines; i++) {
84264fa531Smrg	charBuf[i] = (char *) malloc (sizeof (char)*charsPerLine);
85264fa531Smrg	ch = i + ' ';
86264fa531Smrg	for (j = 0; j != charsPerLine; j++) {
87264fa531Smrg	    charBuf[i][j] = ch;
88264fa531Smrg	    if (ch == '\177') ch = ' '; else ch++;
89264fa531Smrg	}
90264fa531Smrg	if (p->special) {
91264fa531Smrg	    items[i*SEGS+0].chars = &(charBuf[i][0]);
92264fa531Smrg	    items[i*SEGS+0].nchars = charsPerLine/4;
93264fa531Smrg	    items[i*SEGS+0].delta = 0;
94264fa531Smrg	    items[i*SEGS+0].font = font->fid;
95264fa531Smrg	    items[i*SEGS+1].chars = &(charBuf[i][charsPerLine/4]);
96264fa531Smrg	    items[i*SEGS+1].nchars = charsPerLine/2;
97264fa531Smrg	    items[i*SEGS+1].delta = 3;
98264fa531Smrg	    items[i*SEGS+1].font = bfont->fid;
99264fa531Smrg	    items[i*SEGS+2].chars = &(charBuf[i][3*charsPerLine/4]);
100264fa531Smrg	    items[i*SEGS+2].nchars = charsPerLine/4;
101264fa531Smrg	    items[i*SEGS+2].delta = 3;
102264fa531Smrg	    items[i*SEGS+2].font = font->fid;
103264fa531Smrg	}
104264fa531Smrg    }
105264fa531Smrg    return reps;
106264fa531Smrg}
107264fa531Smrg
108264fa531Smrg
109264fa531Smrg#define GetRealChar(font, totalChars, ch)				\
110264fa531Smrg{									\
111264fa531Smrg    XCharStruct *pci;							\
112264fa531Smrg    do {								\
113264fa531Smrg	ch--;								\
114264fa531Smrg	if (ch < 0) {							\
115264fa531Smrg	    ch = totalChars-1;						\
116264fa531Smrg	}								\
117264fa531Smrg	if (font->per_char == NULL) break;				\
118264fa531Smrg	pci = &(font->per_char[ch]);					\
119264fa531Smrg    } while ( (pci->lbearing | pci->rbearing | pci->width		\
120264fa531Smrg             | pci->ascent | pci->descent | pci->attributes) == 0);     \
121264fa531Smrg} /* GetRealChar */
122264fa531Smrg
123264fa531Smrgint
124264fa531SmrgInitText16(XParms xp, Parms p, int reps)
125264fa531Smrg{
126264fa531Smrg    register int	i, j;
127264fa531Smrg    register char	*pbuf0, *pbuf1, *pbuf2;
128264fa531Smrg    XGCValues   	gcv;
129264fa531Smrg    int			rows, columns, totalChars, ch;
130264fa531Smrg    int			brows, bcolumns = 0, btotalChars = 0, bch = 0;
131264fa531Smrg
132264fa531Smrg    font = XLoadQueryFont(xp->d, p->font);
133264fa531Smrg    if (font == NULL) {
134264fa531Smrg	printf("Could not load font '%s', benchmark omitted\n", p->font);
135264fa531Smrg	return 0;
136264fa531Smrg    }
137264fa531Smrg    rows = font->max_byte1 - font->min_byte1 + 1;
138264fa531Smrg    columns = font->max_char_or_byte2 - font->min_char_or_byte2 + 1;
139264fa531Smrg    totalChars = rows * columns;
140264fa531Smrg    totalLines = rows;
141264fa531Smrg    ch = totalChars;
142264fa531Smrg
143264fa531Smrg    bfont = NULL;
144264fa531Smrg    if (p->bfont != NULL) {
145264fa531Smrg	bfont = XLoadQueryFont(xp->d, p->bfont);
146264fa531Smrg	if (bfont == NULL) {
147264fa531Smrg	    printf("Could not load font '%s', benchmark omitted\n", p->bfont);
148264fa531Smrg	    return 0;
149264fa531Smrg	}
150264fa531Smrg	brows = bfont->max_byte1 - bfont->min_byte1 + 1;
151264fa531Smrg	bcolumns = bfont->max_char_or_byte2 - bfont->min_char_or_byte2 + 1;
152264fa531Smrg	btotalChars = brows * bcolumns;
153264fa531Smrg	bch = btotalChars;
154264fa531Smrg	if (brows > totalLines) totalLines = brows;
155264fa531Smrg    }
156264fa531Smrg
157264fa531Smrg    ypos = XPOS;
158264fa531Smrg    height = (font->max_bounds.ascent + font->max_bounds.descent) + 1;
159264fa531Smrg    if (bfont != NULL) {
160264fa531Smrg	int     h = (bfont->max_bounds.ascent + bfont->max_bounds.descent) + 1;
161264fa531Smrg	if (h > height)
162264fa531Smrg	    height = h;
163264fa531Smrg    }
164264fa531Smrg    gcv.font = font->fid;
165264fa531Smrg    XChangeGC(xp->d, xp->fggc, GCFont, &gcv);
166264fa531Smrg    XChangeGC(xp->d, xp->bggc, GCFont, &gcv);
167264fa531Smrg
168264fa531Smrg    charsPerLine = p->objects;
169264fa531Smrg
170264fa531Smrg    if (totalLines > reps) totalLines = reps;
171264fa531Smrg
172264fa531Smrg    if (p->special) {
173264fa531Smrg	charsPerLine = (charsPerLine + 3) & ~3;	/* make a multiple of four */
174264fa531Smrg	p->objects = charsPerLine;
175264fa531Smrg
176264fa531Smrg	items = (XTextItem *) malloc(totalLines*SEGS*sizeof (XTextItem));
177264fa531Smrg
178264fa531Smrg	for (i = 0; i < totalLines; i++) {
179264fa531Smrg	    pbuf0 = items[i*SEGS+0].chars =
180264fa531Smrg			    (char *) malloc (sizeof (char)*charsPerLine/2);
181264fa531Smrg	    items[i*SEGS+0].nchars = charsPerLine/4;
182264fa531Smrg	    items[i*SEGS+0].delta = 0;
183264fa531Smrg	    items[i*SEGS+0].font = font->fid;
184264fa531Smrg	    pbuf1 = items[i*SEGS+1].chars =
185264fa531Smrg			    (char *) malloc (sizeof (char)*charsPerLine);
186264fa531Smrg	    items[i*SEGS+1].nchars = charsPerLine/2;
187264fa531Smrg	    items[i*SEGS+1].delta = 3;
188264fa531Smrg	    items[i*SEGS+1].font = bfont->fid;
189264fa531Smrg	    pbuf2 = items[i*SEGS+2].chars =
190264fa531Smrg			    (char *) malloc (sizeof (char)*charsPerLine/2);
191264fa531Smrg	    items[i*SEGS+2].nchars = charsPerLine/4;
192264fa531Smrg	    items[i*SEGS+2].delta = 3;
193264fa531Smrg	    items[i*SEGS+2].font = font->fid;
194264fa531Smrg	    for (j = 0; j < charsPerLine/4; j++) {
195264fa531Smrg		GetRealChar(font, totalChars, ch);
196264fa531Smrg		*pbuf0++ = ch / columns + font->min_byte1;
197264fa531Smrg		*pbuf0++ = ch % columns + font->min_char_or_byte2;
198264fa531Smrg		GetRealChar(font, totalChars, ch);
199264fa531Smrg		*pbuf2++ = ch / columns + font->min_byte1;
200264fa531Smrg		*pbuf2++ = ch % columns + font->min_char_or_byte2;
201264fa531Smrg	    }
202264fa531Smrg	    for (j = 0; j < charsPerLine/2; j++) {
203264fa531Smrg		GetRealChar(bfont, btotalChars, bch);
204264fa531Smrg		*pbuf1++ = bch / bcolumns + bfont->min_byte1;
205264fa531Smrg		*pbuf1++ = bch % bcolumns + bfont->min_char_or_byte2;
206264fa531Smrg	    }
207264fa531Smrg	}
208264fa531Smrg    } else {
209264fa531Smrg	charBuf = (char **) malloc(totalLines*sizeof (char *));
210264fa531Smrg	for (i = 0; i < totalLines; i++) {
211264fa531Smrg	    pbuf0 = charBuf[i] = (char *) malloc (sizeof (char)*charsPerLine*2);
212264fa531Smrg	    for (j = 0; j < charsPerLine; j++) {
213264fa531Smrg		GetRealChar(font, totalChars, ch);
214264fa531Smrg		*pbuf0++ = ch / columns + font->min_byte1;
215264fa531Smrg		*pbuf0++ = ch % columns + font->min_char_or_byte2;
216264fa531Smrg	    }
217264fa531Smrg	}
218264fa531Smrg    }
219264fa531Smrg    return reps;
220264fa531Smrg}
221264fa531Smrg
222264fa531Smrgvoid
223264fa531SmrgDoText(XParms xp, Parms p, int reps)
224264fa531Smrg{
225264fa531Smrg    int     i, line, startLine;
226264fa531Smrg
227264fa531Smrg    startLine = 0;
228264fa531Smrg    line = 0;
229264fa531Smrg    for (i = 0; i != reps; i++) {
230264fa531Smrg	XDrawString(
231264fa531Smrg	    xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine);
232264fa531Smrg	ypos += height;
233264fa531Smrg	if (ypos > HEIGHT - height) {
234264fa531Smrg	    /* Wraparound to top of window */
235264fa531Smrg	    ypos = XPOS;
236264fa531Smrg	    line = startLine;
237264fa531Smrg	    startLine = (startLine + 1) % totalLines;
238264fa531Smrg	}
239264fa531Smrg	line = (line + 1) % totalLines;
240264fa531Smrg	CheckAbort ();
241264fa531Smrg    }
242264fa531Smrg}
243264fa531Smrg
244264fa531Smrgvoid
245264fa531SmrgDoText16(XParms xp, Parms p, int reps)
246264fa531Smrg{
247264fa531Smrg    int     i, line, startLine;
248264fa531Smrg
249264fa531Smrg    startLine = 0;
250264fa531Smrg    line = 0;
251264fa531Smrg    for (i = 0; i < reps; i++) {
252264fa531Smrg	XDrawString16(
253264fa531Smrg	    xp->d, xp->w, xp->fggc, XPOS, ypos, (XChar2b *)charBuf[line], charsPerLine);
254264fa531Smrg	ypos += height;
255264fa531Smrg	if (ypos > HEIGHT - height) {
256264fa531Smrg	    /* Wraparound to top of window */
257264fa531Smrg	    ypos = XPOS;
258264fa531Smrg	    line = startLine;
259264fa531Smrg	    startLine = (startLine + 1) % totalLines;
260264fa531Smrg	}
261264fa531Smrg	line = (line + 1) % totalLines;
262264fa531Smrg	CheckAbort ();
263264fa531Smrg    }
264264fa531Smrg}
265264fa531Smrg
266264fa531Smrgvoid
267264fa531SmrgDoPolyText(XParms xp, Parms p, int reps)
268264fa531Smrg{
269264fa531Smrg    int     i, line, startLine;
270264fa531Smrg
271264fa531Smrg    startLine = 0;
272264fa531Smrg    line = 0;
273264fa531Smrg    for (i = 0; i != reps; i++) {
274264fa531Smrg	XDrawText(
275264fa531Smrg	    xp->d, xp->w, xp->fggc, XPOS, ypos, &items[line*SEGS], SEGS);
276264fa531Smrg	ypos += height;
277264fa531Smrg	if (ypos > HEIGHT - height) {
278264fa531Smrg	    /* Wraparound to top of window */
279264fa531Smrg	    ypos = XPOS;
280264fa531Smrg	    line = startLine;
281264fa531Smrg	    startLine = (startLine + 1) % totalLines;
282264fa531Smrg	}
283264fa531Smrg	line = (line + 1) % totalLines;
284264fa531Smrg	CheckAbort ();
285264fa531Smrg    }
286264fa531Smrg}
287264fa531Smrg
288264fa531Smrgvoid
289264fa531SmrgDoPolyText16(XParms xp, Parms p, int reps)
290264fa531Smrg{
291264fa531Smrg    int     i, line, startLine;
292264fa531Smrg
293264fa531Smrg    startLine = 0;
294264fa531Smrg    line = 0;
295264fa531Smrg    for (i = 0; i != reps; i++) {
296264fa531Smrg	XDrawText16(
297264fa531Smrg	    xp->d, xp->w, xp->fggc, XPOS, ypos, (XTextItem16 *)&items[line*SEGS], SEGS);
298264fa531Smrg	ypos += height;
299264fa531Smrg	if (ypos > HEIGHT - height) {
300264fa531Smrg	    /* Wraparound to top of window */
301264fa531Smrg	    ypos = XPOS;
302264fa531Smrg	    line = startLine;
303264fa531Smrg	    startLine = (startLine + 1) % totalLines;
304264fa531Smrg	}
305264fa531Smrg	line = (line + 1) % totalLines;
306264fa531Smrg	CheckAbort ();
307264fa531Smrg    }
308264fa531Smrg}
309264fa531Smrg
310264fa531Smrgvoid
311264fa531SmrgDoImageText(XParms xp, Parms p, int reps)
312264fa531Smrg{
313264fa531Smrg    int     i, line, startLine;
314264fa531Smrg
315264fa531Smrg    startLine = 0;
316264fa531Smrg    line = 0;
317264fa531Smrg    for (i = 0; i != reps; i++) {
318264fa531Smrg	XDrawImageString(
319264fa531Smrg	    xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine);
320264fa531Smrg	ypos += height;
321264fa531Smrg	if (ypos > HEIGHT - height) {
322264fa531Smrg	    /* Wraparound to top of window */
323264fa531Smrg	    ypos = XPOS;
324264fa531Smrg	    startLine = (startLine + 17) % totalLines;
325264fa531Smrg	    line = startLine;
326264fa531Smrg	}
327264fa531Smrg	line = (line + 1) % totalLines;
328264fa531Smrg	CheckAbort ();
329264fa531Smrg    }
330264fa531Smrg}
331264fa531Smrg
332264fa531Smrgvoid
333264fa531SmrgDoImageText16(XParms xp, Parms p, int reps)
334264fa531Smrg{
335264fa531Smrg    int     i, line, startLine;
336264fa531Smrg
337264fa531Smrg    startLine = 0;
338264fa531Smrg    line = 0;
339264fa531Smrg    for (i = 0; i != reps; i++) {
340264fa531Smrg	XDrawImageString16(
341264fa531Smrg	    xp->d, xp->w, xp->fggc, XPOS, ypos, (XChar2b *)charBuf[line], charsPerLine);
342264fa531Smrg	ypos += height;
343264fa531Smrg	if (ypos > HEIGHT - height) {
344264fa531Smrg	    /* Wraparound to top of window */
345264fa531Smrg	    ypos = XPOS;
346264fa531Smrg	    startLine = (startLine + 17) % totalLines;
347264fa531Smrg	    line = startLine;
348264fa531Smrg	}
349264fa531Smrg	line = (line + 1) % totalLines;
350264fa531Smrg	CheckAbort ();
351264fa531Smrg    }
352264fa531Smrg}
353264fa531Smrg
354264fa531Smrgvoid
355264fa531SmrgClearTextWin(XParms xp, Parms p)
356264fa531Smrg{
357264fa531Smrg    XClearWindow(xp->d, xp->w);
358264fa531Smrg}
359264fa531Smrg
360264fa531Smrgvoid
361264fa531SmrgEndText(XParms xp, Parms p)
362264fa531Smrg{
363264fa531Smrg    int i;
364264fa531Smrg
365264fa531Smrg    if(font==NULL)return;
366264fa531Smrg    for (i = 0; i != totalLines; i++)
367264fa531Smrg	free(charBuf[i]);
368264fa531Smrg    free(charBuf);
369264fa531Smrg    if (p->special)
370264fa531Smrg	free(items);
371264fa531Smrg    XFreeFont(xp->d, font);
372264fa531Smrg    if (bfont != NULL)
373264fa531Smrg	XFreeFont(xp->d, bfont);
374264fa531Smrg}
375264fa531Smrg
376264fa531Smrgvoid
377264fa531SmrgEndText16(XParms xp, Parms p)
378264fa531Smrg{
379264fa531Smrg    int i;
380264fa531Smrg
381264fa531Smrg    if(font==NULL)return;
382264fa531Smrg    if (p->special) {
383264fa531Smrg	for (i = 0; i < totalLines; i++) {
384264fa531Smrg	    free(items[i*SEGS+0].chars);
385264fa531Smrg	    free(items[i*SEGS+1].chars);
386264fa531Smrg	    free(items[i*SEGS+2].chars);
387264fa531Smrg	}
388264fa531Smrg	free(items);
389264fa531Smrg    } else {
390264fa531Smrg	for (i = 0; i < totalLines; i++) {
391264fa531Smrg	    free(charBuf[i]);
392264fa531Smrg	}
393264fa531Smrg	free(charBuf);
394264fa531Smrg    }
395264fa531Smrg    XFreeFont(xp->d, font);
396264fa531Smrg    if(bfont != NULL) {
397264fa531Smrg	XFreeFont(xp->d, bfont);
398264fa531Smrg    }
399264fa531Smrg}
400264fa531Smrg
401264fa531Smrg#ifdef XFT
402264fa531Smrg#include <X11/extensions/Xrender.h>
403264fa531Smrg#include <X11/Xft/Xft.h>
404264fa531Smrg
405264fa531Smrgstatic XftFont	*aafont;
406264fa531Smrgstatic XftDraw	*aadraw;
407264fa531Smrgstatic XftColor	aacolor;
408264fa531Smrg
409264fa531Smrgint
410264fa531SmrgInitAAText(XParms xp, Parms p, int reps)
411264fa531Smrg{
412264fa531Smrg    int			i, j;
413264fa531Smrg    char		ch;
414264fa531Smrg    XRenderColor	color;
415264fa531Smrg
416264fa531Smrg    aafont = XftFontOpenName (xp->d, DefaultScreen (xp->d), p->font);
417264fa531Smrg
418264fa531Smrg    if (aafont == NULL)
419264fa531Smrg    {
420264fa531Smrg	printf("Could not load font '%s', benchmark omitted\n",
421264fa531Smrg	       p->font);
422264fa531Smrg	return 0;
423264fa531Smrg    }
424264fa531Smrg
425264fa531Smrg    aadraw = XftDrawCreate (xp->d, xp->w,
426264fa531Smrg			    xp->vinfo.visual,
427264fa531Smrg			    xp->cmap);
428264fa531Smrg
429264fa531Smrg    if (!aadraw)
430264fa531Smrg    {
431264fa531Smrg	printf ("Cannot create XftDraw object\n");
432264fa531Smrg	XftFontClose (xp->d, aafont);
433264fa531Smrg	return 0;
434264fa531Smrg    }
435264fa531Smrg    color.red = 0;
436264fa531Smrg    color.green = 0;
437264fa531Smrg    color.blue = 0;
438264fa531Smrg    color.alpha = 0xffff;
439264fa531Smrg    if (!XftColorAllocValue (xp->d,
440264fa531Smrg			     xp->vinfo.visual,
441264fa531Smrg			     xp->cmap,
442264fa531Smrg			     &color, &aacolor))
443264fa531Smrg    {
444264fa531Smrg	printf ("Cannot allocate black\n");
445264fa531Smrg	XftFontClose (xp->d, aafont);
446264fa531Smrg	XftDrawDestroy (aadraw);
447c37a63b8Smrg	aafont = NULL;
448c37a63b8Smrg	aadraw = NULL;
449264fa531Smrg	return 0;
450264fa531Smrg    }
451264fa531Smrg
452264fa531Smrg    ypos = XPOS;
453264fa531Smrg    height = aafont->height;
454264fa531Smrg
455264fa531Smrg    charsPerLine = p->objects;
456264fa531Smrg    charsPerLine = (charsPerLine + 3) & ~3;
457264fa531Smrg    p->objects = charsPerLine;
458264fa531Smrg
459264fa531Smrg    totalLines = '\177' - ' ' + 1;
460264fa531Smrg    if (totalLines > reps) totalLines = reps;
461264fa531Smrg
462264fa531Smrg    charBuf = (char **) malloc(totalLines*sizeof (char *));
463264fa531Smrg
464264fa531Smrg    for (i = 0; i != totalLines; i++) {
465264fa531Smrg	charBuf[i] = (char *) malloc (sizeof (char)*charsPerLine);
466264fa531Smrg	ch = i + ' ';
467264fa531Smrg	for (j = 0; j != charsPerLine; j++) {
468264fa531Smrg	    charBuf[i][j] = ch;
469264fa531Smrg	    if (ch == '\177') ch = ' '; else ch++;
470264fa531Smrg	}
471264fa531Smrg    }
472264fa531Smrg    return reps;
473264fa531Smrg}
474264fa531Smrg
475264fa531Smrgvoid
476264fa531SmrgDoAAText(XParms xp, Parms p, int reps)
477264fa531Smrg{
478264fa531Smrg    int     i, line, startLine;
479264fa531Smrg
480264fa531Smrg    startLine = 0;
481264fa531Smrg    line = 0;
482264fa531Smrg    for (i = 0; i != reps; i++) {
483264fa531Smrg	XftDrawString8 (aadraw, &aacolor, aafont,
484264fa531Smrg		       XPOS, ypos, (unsigned char *) charBuf[line], charsPerLine);
485264fa531Smrg	ypos += height;
486264fa531Smrg	if (ypos > HEIGHT - height) {
487264fa531Smrg	    /* Wraparound to top of window */
488264fa531Smrg	    ypos = XPOS;
489264fa531Smrg	    line = startLine;
490264fa531Smrg	    startLine = (startLine + 1) % totalLines;
491264fa531Smrg	}
492264fa531Smrg	line = (line + 1) % totalLines;
493264fa531Smrg	CheckAbort ();
494264fa531Smrg    }
495264fa531Smrg}
496264fa531Smrg
497264fa531Smrgvoid
498264fa531SmrgEndAAText(XParms xp, Parms p)
499264fa531Smrg{
500264fa531Smrg    int i;
501264fa531Smrg
502264fa531Smrg    if(!aadraw)return;
503264fa531Smrg    for (i = 0; i != totalLines; i++)
504264fa531Smrg	free(charBuf[i]);
505264fa531Smrg    free(charBuf);
506264fa531Smrg    XftDrawDestroy (aadraw);
507264fa531Smrg    XftFontClose (xp->d, aafont);
508264fa531Smrg    XftColorFree (xp->d,
509264fa531Smrg		  xp->vinfo.visual,
510264fa531Smrg		  xp->cmap,
511264fa531Smrg		  &aacolor);
512264fa531Smrg}
513264fa531Smrg
514264fa531Smrg#endif
515