1
/* $Xorg: do_text.c,v 1.4 2000/08/17 19:54:10 cpqbld Exp $ */
2
/*****************************************************************************
3
Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
7
Permission to use, copy, modify, and distribute this software and its
8
documentation for any purpose and without fee is hereby granted,
9
provided that the above copyright notice appear in all copies and that
10
both that copyright notice and this permission notice appear in
11
supporting documentation, and that the name of Digital not be
12
used in advertising or publicity pertaining to distribution of the
13
software without specific, written prior permission.
15
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23
******************************************************************************/
24
/* $XFree86: xc/programs/x11perf/do_text.c,v 1.9 2002/12/04 10:28:08 eich Exp $ */
29
static char **charBuf;
30
static XFontStruct *font, *bfont;
31
static int height, ypos;
32
static XTextItem *items;
33
static int charsPerLine, totalLines;
40
InitText(XParms xp, Parms p, int reps)
46
font = XLoadQueryFont(xp->d, p->font);
48
printf("Could not load font '%s', benchmark omitted\n", p->font);
53
if (p->bfont != NULL) {
54
bfont = XLoadQueryFont(xp->d, p->bfont);
56
printf("Could not load font '%s', benchmark omitted\n", p->bfont);
62
height = (font->max_bounds.ascent + font->max_bounds.descent) + 1;
64
int h = (bfont->max_bounds.ascent + bfont->max_bounds.descent) + 1;
69
XChangeGC(xp->d, xp->fggc, GCFont, &gcv);
70
XChangeGC(xp->d, xp->bggc, GCFont, &gcv);
72
charsPerLine = p->objects;
73
charsPerLine = (charsPerLine + 3) & ~3;
74
p->objects = charsPerLine;
76
totalLines = '\177' - ' ' + 1;
77
if (totalLines > reps) totalLines = reps;
79
charBuf = (char **) malloc(totalLines*sizeof (char *));
81
items = (XTextItem *) malloc(totalLines*SEGS*sizeof (XTextItem));
83
for (i = 0; i != totalLines; i++) {
84
charBuf[i] = (char *) malloc (sizeof (char)*charsPerLine);
86
for (j = 0; j != charsPerLine; j++) {
88
if (ch == '\177') ch = ' '; else ch++;
91
items[i*SEGS+0].chars = &(charBuf[i][0]);
92
items[i*SEGS+0].nchars = charsPerLine/4;
93
items[i*SEGS+0].delta = 0;
94
items[i*SEGS+0].font = font->fid;
95
items[i*SEGS+1].chars = &(charBuf[i][charsPerLine/4]);
96
items[i*SEGS+1].nchars = charsPerLine/2;
97
items[i*SEGS+1].delta = 3;
98
items[i*SEGS+1].font = bfont->fid;
99
items[i*SEGS+2].chars = &(charBuf[i][3*charsPerLine/4]);
100
items[i*SEGS+2].nchars = charsPerLine/4;
101
items[i*SEGS+2].delta = 3;
102
items[i*SEGS+2].font = font->fid;
109
#define GetRealChar(font, totalChars, ch) \
117
if (font->per_char == NULL) break; \
118
pci = &(font->per_char[ch]); \
119
} while ( (pci->lbearing | pci->rbearing | pci->width \
120
| pci->ascent | pci->descent | pci->attributes) == 0); \
124
InitText16(XParms xp, Parms p, int reps)
127
register char *pbuf0, *pbuf1, *pbuf2;
129
int rows, columns, totalChars, ch;
130
int brows, bcolumns = 0, btotalChars = 0, bch = 0;
132
font = XLoadQueryFont(xp->d, p->font);
134
printf("Could not load font '%s', benchmark omitted\n", p->font);
137
rows = font->max_byte1 - font->min_byte1 + 1;
138
columns = font->max_char_or_byte2 - font->min_char_or_byte2 + 1;
139
totalChars = rows * columns;
144
if (p->bfont != NULL) {
145
bfont = XLoadQueryFont(xp->d, p->bfont);
147
printf("Could not load font '%s', benchmark omitted\n", p->bfont);
150
brows = bfont->max_byte1 - bfont->min_byte1 + 1;
151
bcolumns = bfont->max_char_or_byte2 - bfont->min_char_or_byte2 + 1;
152
btotalChars = brows * bcolumns;
154
if (brows > totalLines) totalLines = brows;
158
height = (font->max_bounds.ascent + font->max_bounds.descent) + 1;
160
int h = (bfont->max_bounds.ascent + bfont->max_bounds.descent) + 1;
164
gcv.font = font->fid;
165
XChangeGC(xp->d, xp->fggc, GCFont, &gcv);
166
XChangeGC(xp->d, xp->bggc, GCFont, &gcv);
168
charsPerLine = p->objects;
170
if (totalLines > reps) totalLines = reps;
173
charsPerLine = (charsPerLine + 3) & ~3; /* make a multiple of four */
174
p->objects = charsPerLine;
176
items = (XTextItem *) malloc(totalLines*SEGS*sizeof (XTextItem));
178
for (i = 0; i < totalLines; i++) {
179
pbuf0 = items[i*SEGS+0].chars =
180
(char *) malloc (sizeof (char)*charsPerLine/2);
181
items[i*SEGS+0].nchars = charsPerLine/4;
182
items[i*SEGS+0].delta = 0;
183
items[i*SEGS+0].font = font->fid;
184
pbuf1 = items[i*SEGS+1].chars =
185
(char *) malloc (sizeof (char)*charsPerLine);
186
items[i*SEGS+1].nchars = charsPerLine/2;
187
items[i*SEGS+1].delta = 3;
188
items[i*SEGS+1].font = bfont->fid;
189
pbuf2 = items[i*SEGS+2].chars =
190
(char *) malloc (sizeof (char)*charsPerLine/2);
191
items[i*SEGS+2].nchars = charsPerLine/4;
192
items[i*SEGS+2].delta = 3;
193
items[i*SEGS+2].font = font->fid;
194
for (j = 0; j < charsPerLine/4; j++) {
195
GetRealChar(font, totalChars, ch);
196
*pbuf0++ = ch / columns + font->min_byte1;
197
*pbuf0++ = ch % columns + font->min_char_or_byte2;
198
GetRealChar(font, totalChars, ch);
199
*pbuf2++ = ch / columns + font->min_byte1;
200
*pbuf2++ = ch % columns + font->min_char_or_byte2;
202
for (j = 0; j < charsPerLine/2; j++) {
203
GetRealChar(bfont, btotalChars, bch);
204
*pbuf1++ = bch / bcolumns + bfont->min_byte1;
205
*pbuf1++ = bch % bcolumns + bfont->min_char_or_byte2;
209
charBuf = (char **) malloc(totalLines*sizeof (char *));
210
for (i = 0; i < totalLines; i++) {
211
pbuf0 = charBuf[i] = (char *) malloc (sizeof (char)*charsPerLine*2);
212
for (j = 0; j < charsPerLine; j++) {
213
GetRealChar(font, totalChars, ch);
214
*pbuf0++ = ch / columns + font->min_byte1;
215
*pbuf0++ = ch % columns + font->min_char_or_byte2;
223
DoText(XParms xp, Parms p, int reps)
225
int i, line, startLine;
229
for (i = 0; i != reps; i++) {
231
xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine);
233
if (ypos > HEIGHT - height) {
234
/* Wraparound to top of window */
237
startLine = (startLine + 1) % totalLines;
239
line = (line + 1) % totalLines;
245
DoText16(XParms xp, Parms p, int reps)
247
int i, line, startLine;
251
for (i = 0; i < reps; i++) {
253
xp->d, xp->w, xp->fggc, XPOS, ypos, (XChar2b *)charBuf[line], charsPerLine);
255
if (ypos > HEIGHT - height) {
256
/* Wraparound to top of window */
259
startLine = (startLine + 1) % totalLines;
261
line = (line + 1) % totalLines;
267
DoPolyText(XParms xp, Parms p, int reps)
269
int i, line, startLine;
273
for (i = 0; i != reps; i++) {
275
xp->d, xp->w, xp->fggc, XPOS, ypos, &items[line*SEGS], SEGS);
277
if (ypos > HEIGHT - height) {
278
/* Wraparound to top of window */
281
startLine = (startLine + 1) % totalLines;
283
line = (line + 1) % totalLines;
289
DoPolyText16(XParms xp, Parms p, int reps)
291
int i, line, startLine;
295
for (i = 0; i != reps; i++) {
297
xp->d, xp->w, xp->fggc, XPOS, ypos, (XTextItem16 *)&items[line*SEGS], SEGS);
299
if (ypos > HEIGHT - height) {
300
/* Wraparound to top of window */
303
startLine = (startLine + 1) % totalLines;
305
line = (line + 1) % totalLines;
311
DoImageText(XParms xp, Parms p, int reps)
313
int i, line, startLine;
317
for (i = 0; i != reps; i++) {
319
xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine);
321
if (ypos > HEIGHT - height) {
322
/* Wraparound to top of window */
324
startLine = (startLine + 17) % totalLines;
327
line = (line + 1) % totalLines;
333
DoImageText16(XParms xp, Parms p, int reps)
335
int i, line, startLine;
339
for (i = 0; i != reps; i++) {
341
xp->d, xp->w, xp->fggc, XPOS, ypos, (XChar2b *)charBuf[line], charsPerLine);
343
if (ypos > HEIGHT - height) {
344
/* Wraparound to top of window */
346
startLine = (startLine + 17) % totalLines;
349
line = (line + 1) % totalLines;
355
ClearTextWin(XParms xp, Parms p)
357
XClearWindow(xp->d, xp->w);
361
EndText(XParms xp, Parms p)
365
if(font==NULL)return;
366
for (i = 0; i != totalLines; i++)
371
XFreeFont(xp->d, font);
373
XFreeFont(xp->d, bfont);
377
EndText16(XParms xp, Parms p)
381
if(font==NULL)return;
383
for (i = 0; i < totalLines; i++) {
384
free(items[i*SEGS+0].chars);
385
free(items[i*SEGS+1].chars);
386
free(items[i*SEGS+2].chars);
390
for (i = 0; i < totalLines; i++) {
395
XFreeFont(xp->d, font);
397
XFreeFont(xp->d, bfont);
402
#include <X11/extensions/Xrender.h>
403
#include <X11/Xft/Xft.h>
405
static XftFont *aafont;
406
static XftDraw *aadraw;
407
static XftColor aacolor;
410
InitAAText(XParms xp, Parms p, int reps)
416
aafont = XftFontOpenName (xp->d, DefaultScreen (xp->d), p->font);
420
printf("Could not load font '%s', benchmark omitted\n",
425
aadraw = XftDrawCreate (xp->d, xp->w,
431
printf ("Cannot create XftDraw object\n");
432
XftFontClose (xp->d, aafont);
438
color.alpha = 0xffff;
439
if (!XftColorAllocValue (xp->d,
444
printf ("Cannot allocate black\n");
445
XftFontClose (xp->d, aafont);
446
XftDrawDestroy (aadraw);
453
height = aafont->height;
455
charsPerLine = p->objects;
456
charsPerLine = (charsPerLine + 3) & ~3;
457
p->objects = charsPerLine;
459
totalLines = '\177' - ' ' + 1;
460
if (totalLines > reps) totalLines = reps;
462
charBuf = (char **) malloc(totalLines*sizeof (char *));
464
for (i = 0; i != totalLines; i++) {
465
charBuf[i] = (char *) malloc (sizeof (char)*charsPerLine);
467
for (j = 0; j != charsPerLine; j++) {
469
if (ch == '\177') ch = ' '; else ch++;
476
DoAAText(XParms xp, Parms p, int reps)
478
int i, line, startLine;
482
for (i = 0; i != reps; i++) {
483
XftDrawString8 (aadraw, &aacolor, aafont,
484
XPOS, ypos, (unsigned char *) charBuf[line], charsPerLine);
486
if (ypos > HEIGHT - height) {
487
/* Wraparound to top of window */
490
startLine = (startLine + 1) % totalLines;
492
line = (line + 1) % totalLines;
498
EndAAText(XParms xp, Parms p)
503
for (i = 0; i != totalLines; i++)
506
XftDrawDestroy (aadraw);
507
XftFontClose (xp->d, aafont);