1264fa531Smrg/***************************************************************************** 2264fa531SmrgCopyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. 3264fa531Smrg 4264fa531Smrg All Rights Reserved 5264fa531Smrg 6dfac8f13SmrgPermission to use, copy, modify, and distribute this software and its 7dfac8f13Smrgdocumentation for any purpose and without fee is hereby granted, 8264fa531Smrgprovided that the above copyright notice appear in all copies and that 9dfac8f13Smrgboth that copyright notice and this permission notice appear in 10264fa531Smrgsupporting documentation, and that the name of Digital not be 11264fa531Smrgused in advertising or publicity pertaining to distribution of the 12dfac8f13Smrgsoftware without specific, written prior permission. 13264fa531Smrg 14264fa531SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 15264fa531SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 16264fa531SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 17264fa531SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 18264fa531SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 19264fa531SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20264fa531SmrgSOFTWARE. 21264fa531Smrg 22264fa531Smrg******************************************************************************/ 23264fa531Smrg 24264fa531Smrg#include "x11perf.h" 25264fa531Smrg#include <stdio.h> 26dfac8f13Smrg#include "bitmaps.h" 27264fa531Smrg 28264fa531Smrgstatic char **charBuf; 29264fa531Smrgstatic XFontStruct *font, *bfont; 30264fa531Smrgstatic int height, ypos; 31264fa531Smrgstatic XTextItem *items; 32264fa531Smrgstatic int charsPerLine, totalLines; 33264fa531Smrg 34264fa531Smrg#define XPOS 20 35264fa531Smrg#define SEGS 3 36264fa531Smrg 37264fa531Smrg 38dfac8f13Smrgint 39533545b5SmrgInitText(XParms xp, Parms p, int64_t reps) 40264fa531Smrg{ 41264fa531Smrg XGCValues gcv; 42264fa531Smrg 43264fa531Smrg font = XLoadQueryFont(xp->d, p->font); 44264fa531Smrg if (font == NULL) { 45264fa531Smrg printf("Could not load font '%s', benchmark omitted\n", p->font); 46264fa531Smrg return 0; 47264fa531Smrg } 48264fa531Smrg 49264fa531Smrg bfont = NULL; 50264fa531Smrg if (p->bfont != NULL) { 51264fa531Smrg bfont = XLoadQueryFont(xp->d, p->bfont); 52264fa531Smrg if (bfont == NULL) { 53264fa531Smrg printf("Could not load font '%s', benchmark omitted\n", p->bfont); 54264fa531Smrg return 0; 55264fa531Smrg } 56264fa531Smrg } 57264fa531Smrg 58264fa531Smrg ypos = XPOS; 59264fa531Smrg height = (font->max_bounds.ascent + font->max_bounds.descent) + 1; 60264fa531Smrg if (bfont != NULL) { 61264fa531Smrg int h = (bfont->max_bounds.ascent + bfont->max_bounds.descent) + 1; 62264fa531Smrg if (h > height) 63264fa531Smrg height = h; 64264fa531Smrg } 65264fa531Smrg gcv.font = font->fid; 66264fa531Smrg XChangeGC(xp->d, xp->fggc, GCFont, &gcv); 67264fa531Smrg XChangeGC(xp->d, xp->bggc, GCFont, &gcv); 68264fa531Smrg 69dfac8f13Smrg SetFillStyle(xp, p); 70dfac8f13Smrg 71264fa531Smrg charsPerLine = p->objects; 72264fa531Smrg charsPerLine = (charsPerLine + 3) & ~3; 73264fa531Smrg p->objects = charsPerLine; 74264fa531Smrg 75264fa531Smrg totalLines = '\177' - ' ' + 1; 76264fa531Smrg if (totalLines > reps) totalLines = reps; 77264fa531Smrg 78c9e4df9bSmrg charBuf = malloc(totalLines * sizeof (char *)); 79264fa531Smrg if (p->special) 80c9e4df9bSmrg items = malloc(totalLines * SEGS * sizeof (XTextItem)); 81264fa531Smrg 82c9e4df9bSmrg for (int i = 0; i != totalLines; i++) { 83c9e4df9bSmrg char ch; 84c9e4df9bSmrg 85c9e4df9bSmrg charBuf[i] = malloc (sizeof (char) * charsPerLine); 86264fa531Smrg ch = i + ' '; 87c9e4df9bSmrg for (int j = 0; j != charsPerLine; j++) { 88264fa531Smrg charBuf[i][j] = ch; 89264fa531Smrg if (ch == '\177') ch = ' '; else ch++; 90264fa531Smrg } 91264fa531Smrg if (p->special) { 92264fa531Smrg items[i*SEGS+0].chars = &(charBuf[i][0]); 93264fa531Smrg items[i*SEGS+0].nchars = charsPerLine/4; 94264fa531Smrg items[i*SEGS+0].delta = 0; 95264fa531Smrg items[i*SEGS+0].font = font->fid; 96264fa531Smrg items[i*SEGS+1].chars = &(charBuf[i][charsPerLine/4]); 97264fa531Smrg items[i*SEGS+1].nchars = charsPerLine/2; 98264fa531Smrg items[i*SEGS+1].delta = 3; 99264fa531Smrg items[i*SEGS+1].font = bfont->fid; 100264fa531Smrg items[i*SEGS+2].chars = &(charBuf[i][3*charsPerLine/4]); 101264fa531Smrg items[i*SEGS+2].nchars = charsPerLine/4; 102264fa531Smrg items[i*SEGS+2].delta = 3; 103264fa531Smrg items[i*SEGS+2].font = font->fid; 104264fa531Smrg } 105264fa531Smrg } 106264fa531Smrg return reps; 107264fa531Smrg} 108264fa531Smrg 109264fa531Smrg 110264fa531Smrg#define GetRealChar(font, totalChars, ch) \ 111264fa531Smrg{ \ 112264fa531Smrg XCharStruct *pci; \ 113264fa531Smrg do { \ 114264fa531Smrg ch--; \ 115264fa531Smrg if (ch < 0) { \ 116264fa531Smrg ch = totalChars-1; \ 117264fa531Smrg } \ 118264fa531Smrg if (font->per_char == NULL) break; \ 119264fa531Smrg pci = &(font->per_char[ch]); \ 120264fa531Smrg } while ( (pci->lbearing | pci->rbearing | pci->width \ 121264fa531Smrg | pci->ascent | pci->descent | pci->attributes) == 0); \ 122264fa531Smrg} /* GetRealChar */ 123264fa531Smrg 124dfac8f13Smrgint 125533545b5SmrgInitText16(XParms xp, Parms p, int64_t reps) 126264fa531Smrg{ 127264fa531Smrg XGCValues gcv; 128264fa531Smrg int rows, columns, totalChars, ch; 129264fa531Smrg int brows, bcolumns = 0, btotalChars = 0, bch = 0; 130264fa531Smrg 131264fa531Smrg font = XLoadQueryFont(xp->d, p->font); 132264fa531Smrg if (font == NULL) { 133264fa531Smrg printf("Could not load font '%s', benchmark omitted\n", p->font); 134264fa531Smrg return 0; 135264fa531Smrg } 136264fa531Smrg rows = font->max_byte1 - font->min_byte1 + 1; 137264fa531Smrg columns = font->max_char_or_byte2 - font->min_char_or_byte2 + 1; 138264fa531Smrg totalChars = rows * columns; 139264fa531Smrg totalLines = rows; 140264fa531Smrg ch = totalChars; 141264fa531Smrg 142264fa531Smrg bfont = NULL; 143264fa531Smrg if (p->bfont != NULL) { 144264fa531Smrg bfont = XLoadQueryFont(xp->d, p->bfont); 145264fa531Smrg if (bfont == NULL) { 146264fa531Smrg printf("Could not load font '%s', benchmark omitted\n", p->bfont); 147264fa531Smrg return 0; 148264fa531Smrg } 149264fa531Smrg brows = bfont->max_byte1 - bfont->min_byte1 + 1; 150264fa531Smrg bcolumns = bfont->max_char_or_byte2 - bfont->min_char_or_byte2 + 1; 151264fa531Smrg btotalChars = brows * bcolumns; 152264fa531Smrg bch = btotalChars; 153264fa531Smrg if (brows > totalLines) totalLines = brows; 154264fa531Smrg } 155264fa531Smrg 156264fa531Smrg ypos = XPOS; 157264fa531Smrg height = (font->max_bounds.ascent + font->max_bounds.descent) + 1; 158264fa531Smrg if (bfont != NULL) { 159264fa531Smrg int h = (bfont->max_bounds.ascent + bfont->max_bounds.descent) + 1; 160264fa531Smrg if (h > height) 161264fa531Smrg height = h; 162264fa531Smrg } 163264fa531Smrg gcv.font = font->fid; 164264fa531Smrg XChangeGC(xp->d, xp->fggc, GCFont, &gcv); 165264fa531Smrg XChangeGC(xp->d, xp->bggc, GCFont, &gcv); 166264fa531Smrg 167264fa531Smrg charsPerLine = p->objects; 168264fa531Smrg 169264fa531Smrg if (totalLines > reps) totalLines = reps; 170264fa531Smrg 171264fa531Smrg if (p->special) { 172264fa531Smrg charsPerLine = (charsPerLine + 3) & ~3; /* make a multiple of four */ 173264fa531Smrg p->objects = charsPerLine; 174264fa531Smrg 175c9e4df9bSmrg items = malloc(totalLines * SEGS * sizeof (XTextItem)); 176c9e4df9bSmrg 177c9e4df9bSmrg for (int i = 0; i < totalLines; i++) { 178c9e4df9bSmrg char *pbuf0, *pbuf1, *pbuf2; 179264fa531Smrg 180264fa531Smrg pbuf0 = items[i*SEGS+0].chars = 181c9e4df9bSmrg malloc (sizeof (char) * charsPerLine/2); 182264fa531Smrg items[i*SEGS+0].nchars = charsPerLine/4; 183264fa531Smrg items[i*SEGS+0].delta = 0; 184264fa531Smrg items[i*SEGS+0].font = font->fid; 185264fa531Smrg pbuf1 = items[i*SEGS+1].chars = 186c9e4df9bSmrg malloc (sizeof (char) * charsPerLine); 187264fa531Smrg items[i*SEGS+1].nchars = charsPerLine/2; 188264fa531Smrg items[i*SEGS+1].delta = 3; 189264fa531Smrg items[i*SEGS+1].font = bfont->fid; 190264fa531Smrg pbuf2 = items[i*SEGS+2].chars = 191c9e4df9bSmrg malloc (sizeof (char) * charsPerLine/2); 192264fa531Smrg items[i*SEGS+2].nchars = charsPerLine/4; 193264fa531Smrg items[i*SEGS+2].delta = 3; 194264fa531Smrg items[i*SEGS+2].font = font->fid; 195c9e4df9bSmrg for (int j = 0; j < charsPerLine/4; j++) { 196264fa531Smrg GetRealChar(font, totalChars, ch); 197264fa531Smrg *pbuf0++ = ch / columns + font->min_byte1; 198264fa531Smrg *pbuf0++ = ch % columns + font->min_char_or_byte2; 199264fa531Smrg GetRealChar(font, totalChars, ch); 200264fa531Smrg *pbuf2++ = ch / columns + font->min_byte1; 201264fa531Smrg *pbuf2++ = ch % columns + font->min_char_or_byte2; 202264fa531Smrg } 203c9e4df9bSmrg for (int j = 0; j < charsPerLine/2; j++) { 204264fa531Smrg GetRealChar(bfont, btotalChars, bch); 205264fa531Smrg *pbuf1++ = bch / bcolumns + bfont->min_byte1; 206264fa531Smrg *pbuf1++ = bch % bcolumns + bfont->min_char_or_byte2; 207264fa531Smrg } 208264fa531Smrg } 209264fa531Smrg } else { 210c9e4df9bSmrg charBuf = malloc(totalLines * sizeof (char *)); 211c9e4df9bSmrg for (int i = 0; i < totalLines; i++) { 212c9e4df9bSmrg char *pbuf0 = charBuf[i] = 213c9e4df9bSmrg malloc (sizeof (char) * charsPerLine * 2); 214c9e4df9bSmrg for (int j = 0; j < charsPerLine; j++) { 215264fa531Smrg GetRealChar(font, totalChars, ch); 216264fa531Smrg *pbuf0++ = ch / columns + font->min_byte1; 217264fa531Smrg *pbuf0++ = ch % columns + font->min_char_or_byte2; 218264fa531Smrg } 219264fa531Smrg } 220264fa531Smrg } 221264fa531Smrg return reps; 222264fa531Smrg} 223264fa531Smrg 224dfac8f13Smrgvoid 225533545b5SmrgDoText(XParms xp, Parms p, int64_t reps) 226264fa531Smrg{ 227c9e4df9bSmrg int line, startLine; 228264fa531Smrg 229264fa531Smrg startLine = 0; 230264fa531Smrg line = 0; 231c9e4df9bSmrg for (int i = 0; i != reps; i++) { 232264fa531Smrg XDrawString( 233264fa531Smrg xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine); 234264fa531Smrg ypos += height; 235264fa531Smrg if (ypos > HEIGHT - height) { 236264fa531Smrg /* Wraparound to top of window */ 237264fa531Smrg ypos = XPOS; 238264fa531Smrg line = startLine; 239264fa531Smrg startLine = (startLine + 1) % totalLines; 240264fa531Smrg } 241264fa531Smrg line = (line + 1) % totalLines; 242264fa531Smrg CheckAbort (); 243264fa531Smrg } 244264fa531Smrg} 245264fa531Smrg 246dfac8f13Smrgvoid 247533545b5SmrgDoText16(XParms xp, Parms p, int64_t reps) 248264fa531Smrg{ 249c9e4df9bSmrg int line, startLine; 250264fa531Smrg 251264fa531Smrg startLine = 0; 252264fa531Smrg line = 0; 253c9e4df9bSmrg for (int i = 0; i < reps; i++) { 254264fa531Smrg XDrawString16( 255264fa531Smrg xp->d, xp->w, xp->fggc, XPOS, ypos, (XChar2b *)charBuf[line], charsPerLine); 256264fa531Smrg ypos += height; 257264fa531Smrg if (ypos > HEIGHT - height) { 258264fa531Smrg /* Wraparound to top of window */ 259264fa531Smrg ypos = XPOS; 260264fa531Smrg line = startLine; 261264fa531Smrg startLine = (startLine + 1) % totalLines; 262264fa531Smrg } 263264fa531Smrg line = (line + 1) % totalLines; 264264fa531Smrg CheckAbort (); 265264fa531Smrg } 266264fa531Smrg} 267264fa531Smrg 268dfac8f13Smrgvoid 269533545b5SmrgDoPolyText(XParms xp, Parms p, int64_t reps) 270264fa531Smrg{ 271c9e4df9bSmrg int line, startLine; 272264fa531Smrg 273264fa531Smrg startLine = 0; 274264fa531Smrg line = 0; 275c9e4df9bSmrg for (int i = 0; i != reps; i++) { 276264fa531Smrg XDrawText( 277264fa531Smrg xp->d, xp->w, xp->fggc, XPOS, ypos, &items[line*SEGS], SEGS); 278264fa531Smrg ypos += height; 279264fa531Smrg if (ypos > HEIGHT - height) { 280264fa531Smrg /* Wraparound to top of window */ 281264fa531Smrg ypos = XPOS; 282264fa531Smrg line = startLine; 283264fa531Smrg startLine = (startLine + 1) % totalLines; 284264fa531Smrg } 285264fa531Smrg line = (line + 1) % totalLines; 286264fa531Smrg CheckAbort (); 287264fa531Smrg } 288264fa531Smrg} 289264fa531Smrg 290dfac8f13Smrgvoid 291533545b5SmrgDoPolyText16(XParms xp, Parms p, int64_t reps) 292264fa531Smrg{ 293c9e4df9bSmrg int line, startLine; 294264fa531Smrg 295264fa531Smrg startLine = 0; 296264fa531Smrg line = 0; 297c9e4df9bSmrg for (int i = 0; i != reps; i++) { 298264fa531Smrg XDrawText16( 299264fa531Smrg xp->d, xp->w, xp->fggc, XPOS, ypos, (XTextItem16 *)&items[line*SEGS], SEGS); 300264fa531Smrg ypos += height; 301264fa531Smrg if (ypos > HEIGHT - height) { 302264fa531Smrg /* Wraparound to top of window */ 303264fa531Smrg ypos = XPOS; 304264fa531Smrg line = startLine; 305264fa531Smrg startLine = (startLine + 1) % totalLines; 306264fa531Smrg } 307264fa531Smrg line = (line + 1) % totalLines; 308264fa531Smrg CheckAbort (); 309264fa531Smrg } 310264fa531Smrg} 311264fa531Smrg 312dfac8f13Smrgvoid 313533545b5SmrgDoImageText(XParms xp, Parms p, int64_t reps) 314264fa531Smrg{ 315c9e4df9bSmrg int line, startLine; 316264fa531Smrg 317264fa531Smrg startLine = 0; 318264fa531Smrg line = 0; 319c9e4df9bSmrg for (int i = 0; i != reps; i++) { 320264fa531Smrg XDrawImageString( 321264fa531Smrg xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine); 322264fa531Smrg ypos += height; 323264fa531Smrg if (ypos > HEIGHT - height) { 324264fa531Smrg /* Wraparound to top of window */ 325264fa531Smrg ypos = XPOS; 326264fa531Smrg startLine = (startLine + 17) % totalLines; 327264fa531Smrg line = startLine; 328264fa531Smrg } 329264fa531Smrg line = (line + 1) % totalLines; 330264fa531Smrg CheckAbort (); 331264fa531Smrg } 332264fa531Smrg} 333264fa531Smrg 334dfac8f13Smrgvoid 335533545b5SmrgDoImageText16(XParms xp, Parms p, int64_t reps) 336264fa531Smrg{ 337c9e4df9bSmrg int line, startLine; 338264fa531Smrg 339264fa531Smrg startLine = 0; 340264fa531Smrg line = 0; 341c9e4df9bSmrg for (int i = 0; i != reps; i++) { 342264fa531Smrg XDrawImageString16( 343264fa531Smrg xp->d, xp->w, xp->fggc, XPOS, ypos, (XChar2b *)charBuf[line], charsPerLine); 344264fa531Smrg ypos += height; 345264fa531Smrg if (ypos > HEIGHT - height) { 346264fa531Smrg /* Wraparound to top of window */ 347264fa531Smrg ypos = XPOS; 348264fa531Smrg startLine = (startLine + 17) % totalLines; 349264fa531Smrg line = startLine; 350264fa531Smrg } 351264fa531Smrg line = (line + 1) % totalLines; 352264fa531Smrg CheckAbort (); 353264fa531Smrg } 354264fa531Smrg} 355264fa531Smrg 356dfac8f13Smrgvoid 357264fa531SmrgClearTextWin(XParms xp, Parms p) 358264fa531Smrg{ 359264fa531Smrg XClearWindow(xp->d, xp->w); 360264fa531Smrg} 361264fa531Smrg 362dfac8f13Smrgvoid 363264fa531SmrgEndText(XParms xp, Parms p) 364264fa531Smrg{ 365264fa531Smrg if(font==NULL)return; 366c9e4df9bSmrg for (int 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 376dfac8f13Smrgvoid 377264fa531SmrgEndText16(XParms xp, Parms p) 378264fa531Smrg{ 379264fa531Smrg if(font==NULL)return; 380264fa531Smrg if (p->special) { 381c9e4df9bSmrg for (int i = 0; i < totalLines; i++) { 382264fa531Smrg free(items[i*SEGS+0].chars); 383264fa531Smrg free(items[i*SEGS+1].chars); 384264fa531Smrg free(items[i*SEGS+2].chars); 385264fa531Smrg } 386264fa531Smrg free(items); 387264fa531Smrg } else { 388c9e4df9bSmrg for (int i = 0; i < totalLines; i++) { 389264fa531Smrg free(charBuf[i]); 390264fa531Smrg } 391264fa531Smrg free(charBuf); 392264fa531Smrg } 393264fa531Smrg XFreeFont(xp->d, font); 394264fa531Smrg if(bfont != NULL) { 395264fa531Smrg XFreeFont(xp->d, bfont); 396264fa531Smrg } 397264fa531Smrg} 398264fa531Smrg 399264fa531Smrg#ifdef XFT 400264fa531Smrg#include <X11/extensions/Xrender.h> 401264fa531Smrg#include <X11/Xft/Xft.h> 402264fa531Smrg 403264fa531Smrgstatic XftFont *aafont; 404264fa531Smrgstatic XftDraw *aadraw; 405264fa531Smrgstatic XftColor aacolor; 406264fa531Smrg 407dfac8f13Smrgint 408533545b5SmrgInitAAText(XParms xp, Parms p, int64_t reps) 409264fa531Smrg{ 410264fa531Smrg char ch; 411264fa531Smrg XRenderColor color; 412dfac8f13Smrg FcValue value; 413dfac8f13Smrg int v_len; 414dfac8f13Smrg FcPattern *pat; 415dfac8f13Smrg FcPattern *match; 416dfac8f13Smrg FcResult result; 417dfac8f13Smrg 418dfac8f13Smrg pat = FcNameParse((FcChar8 *) p->font); 419dfac8f13Smrg match = XftFontMatch(xp->d, DefaultScreen(xp->d), pat, &result); 420dfac8f13Smrg FcPatternDestroy(pat); 421dfac8f13Smrg if (p->bfont) { 422dfac8f13Smrg FcPatternDel(match, XFT_RENDER); 423dfac8f13Smrg FcPatternAddBool(match, XFT_RENDER, False); 424dfac8f13Smrg } 425264fa531Smrg 426dfac8f13Smrg aafont = XftFontOpenPattern (xp->d, match); 427dfac8f13Smrg 428dfac8f13Smrg if (aafont == NULL) 429264fa531Smrg { 430dfac8f13Smrg printf("Could not load font '%s', benchmark omitted\n", 431264fa531Smrg p->font); 432264fa531Smrg return 0; 433264fa531Smrg } 434dfac8f13Smrg if (FcPatternGet(aafont->pattern, FC_FAMILY, 0, &value) != FcResultMatch || 435dfac8f13Smrg value.type != FcTypeString) 436dfac8f13Smrg { 437dfac8f13Smrg printf("Could not load font '%s', benchmark omitted\n", 438dfac8f13Smrg p->font); 439dfac8f13Smrg XftFontClose (xp->d, aafont); 440dfac8f13Smrg return 0; 441dfac8f13Smrg } 442dfac8f13Smrg v_len = strlen((char *) value.u.s); 443dfac8f13Smrg if (strncmp((char *) value.u.s, p->font, v_len) != 0 || p->font[v_len] != ':') { 444dfac8f13Smrg printf("Could not load font '%s' (found %s), benchmark omitted\n", 445dfac8f13Smrg p->font, 446dfac8f13Smrg (char *) value.u.s); 447dfac8f13Smrg XftFontClose (xp->d, aafont); 448dfac8f13Smrg return 0; 449dfac8f13Smrg } 450264fa531Smrg 451dfac8f13Smrg aadraw = XftDrawCreate (xp->d, xp->w, 452dfac8f13Smrg xp->vinfo.visual, 453264fa531Smrg xp->cmap); 454264fa531Smrg 455dfac8f13Smrg if (!aadraw) 456264fa531Smrg { 457264fa531Smrg printf ("Cannot create XftDraw object\n"); 458264fa531Smrg XftFontClose (xp->d, aafont); 459264fa531Smrg return 0; 460264fa531Smrg } 461264fa531Smrg color.red = 0; 462264fa531Smrg color.green = 0; 463264fa531Smrg color.blue = 0; 464264fa531Smrg color.alpha = 0xffff; 465264fa531Smrg if (!XftColorAllocValue (xp->d, 466dfac8f13Smrg xp->vinfo.visual, 467264fa531Smrg xp->cmap, 468264fa531Smrg &color, &aacolor)) 469264fa531Smrg { 470264fa531Smrg printf ("Cannot allocate black\n"); 471264fa531Smrg XftFontClose (xp->d, aafont); 472264fa531Smrg XftDrawDestroy (aadraw); 473c37a63b8Smrg aafont = NULL; 474c37a63b8Smrg aadraw = NULL; 475264fa531Smrg return 0; 476264fa531Smrg } 477dfac8f13Smrg 478264fa531Smrg ypos = XPOS; 479264fa531Smrg height = aafont->height; 480dfac8f13Smrg 481264fa531Smrg charsPerLine = p->objects; 482264fa531Smrg charsPerLine = (charsPerLine + 3) & ~3; 483264fa531Smrg p->objects = charsPerLine; 484264fa531Smrg 485264fa531Smrg totalLines = '\177' - ' ' + 1; 486264fa531Smrg if (totalLines > reps) totalLines = reps; 487264fa531Smrg 488c9e4df9bSmrg charBuf = malloc(totalLines * sizeof (char *)); 489264fa531Smrg 490c9e4df9bSmrg for (int i = 0; i != totalLines; i++) { 491c9e4df9bSmrg charBuf[i] = malloc (sizeof (char) * charsPerLine); 492264fa531Smrg ch = i + ' '; 493c9e4df9bSmrg for (int j = 0; j != charsPerLine; j++) { 494264fa531Smrg charBuf[i][j] = ch; 495264fa531Smrg if (ch == '\177') ch = ' '; else ch++; 496264fa531Smrg } 497264fa531Smrg } 498264fa531Smrg return reps; 499264fa531Smrg} 500264fa531Smrg 501dfac8f13Smrgvoid 502533545b5SmrgDoAAText(XParms xp, Parms p, int64_t reps) 503264fa531Smrg{ 504c9e4df9bSmrg int line, startLine; 505264fa531Smrg 506264fa531Smrg startLine = 0; 507264fa531Smrg line = 0; 508c9e4df9bSmrg for (int i = 0; i != reps; i++) { 509dfac8f13Smrg XftDrawString8 (aadraw, &aacolor, aafont, 510264fa531Smrg XPOS, ypos, (unsigned char *) charBuf[line], charsPerLine); 511264fa531Smrg ypos += height; 512264fa531Smrg if (ypos > HEIGHT - height) { 513264fa531Smrg /* Wraparound to top of window */ 514264fa531Smrg ypos = XPOS; 515264fa531Smrg line = startLine; 516264fa531Smrg startLine = (startLine + 1) % totalLines; 517264fa531Smrg } 518264fa531Smrg line = (line + 1) % totalLines; 519264fa531Smrg CheckAbort (); 520264fa531Smrg } 521264fa531Smrg} 522264fa531Smrg 523dfac8f13Smrgvoid 524264fa531SmrgEndAAText(XParms xp, Parms p) 525264fa531Smrg{ 526264fa531Smrg if(!aadraw)return; 527c9e4df9bSmrg for (int i = 0; i != totalLines; i++) 528264fa531Smrg free(charBuf[i]); 529264fa531Smrg free(charBuf); 530264fa531Smrg XftDrawDestroy (aadraw); 531264fa531Smrg XftFontClose (xp->d, aafont); 532264fa531Smrg XftColorFree (xp->d, 533dfac8f13Smrg xp->vinfo.visual, 534264fa531Smrg xp->cmap, 535264fa531Smrg &aacolor); 536264fa531Smrg} 537264fa531Smrg 538264fa531Smrg#endif 539