home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / x11p-13.zip / RCS / do_text.c,v < prev    next >
Text File  |  1989-12-07  |  12KB  |  573 lines

  1. head     2.4;
  2. access   ;
  3. symbols  pre-merge:2.0;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 2.4
  9. date     89.12.07.16.36.20;  author joel;  state Exp;
  10. branches ;
  11. next     2.3;
  12.  
  13. 2.3
  14. date     89.05.11.16.44.52;  author joel;  state Exp;
  15. branches ;
  16. next     2.2;
  17.  
  18. 2.2
  19. date     89.05.08.18.38.53;  author joel;  state Exp;
  20. branches ;
  21. next     2.1;
  22.  
  23. 2.1
  24. date     89.05.03.14.18.04;  author joel;  state Exp;
  25. branches ;
  26. next     2.0;
  27.  
  28. 2.0
  29. date     89.01.31.17.06.59;  author erik;  state Exp;
  30. branches ;
  31. next     1.3;
  32.  
  33. 1.3
  34. date     89.01.31.17.06.59;  author joel;  state Exp;
  35. branches ;
  36. next     1.2;
  37.  
  38. 1.2
  39. date     88.12.15.13.40.31;  author joel;  state Exp;
  40. branches ;
  41. next     1.1;
  42.  
  43. 1.1
  44. date     88.06.17.12.41.13;  author joel;  state Exp;
  45. branches ;
  46. next     ;
  47.  
  48.  
  49. desc
  50. @@
  51.  
  52.  
  53. 2.4
  54. log
  55. @Changed interface to p->reps.
  56. @
  57. text
  58. @/*****************************************************************************
  59. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  60.  
  61.                         All Rights Reserved
  62.  
  63. Permission to use, copy, modify, and distribute this software and its 
  64. documentation for any purpose and without fee is hereby granted, 
  65. provided that the above copyright notice appear in all copies and that
  66. both that copyright notice and this permission notice appear in 
  67. supporting documentation, and that the name of Digital not be
  68. used in advertising or publicity pertaining to distribution of the
  69. software without specific, written prior permission.  
  70.  
  71. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  72. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  73. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  74. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  75. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  76. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  77. SOFTWARE.
  78.  
  79. ******************************************************************************/
  80.  
  81. #include "x11perf.h"
  82.  
  83. static char **charBuf;
  84. static XFontStruct *font, *bfont;
  85. static int height, ypos;
  86. static XTextItem *items;
  87. static int charsPerLine, totalLines;
  88.  
  89. #define XPOS 20
  90. #define SEGS 3
  91.  
  92.  
  93. int InitText(xp, p, reps)
  94.     XParms  xp;
  95.     Parms   p;
  96.     int     reps;
  97. {
  98.     int        i, j;
  99.     char    ch;
  100.     XGCValues   gcv;
  101.  
  102.     font = XLoadQueryFont(xp->d, p->font);
  103.     if (font == NULL) {
  104.     printf("Could not load font '%s', benchmark omitted\n", p->font);
  105.     return 0;
  106.     }
  107.  
  108.     bfont = NULL;
  109.     if (p->bfont != NULL) {
  110.     bfont = XLoadQueryFont(xp->d, p->bfont);
  111.     if (bfont == NULL) {
  112.         printf("Could not load font '%s', benchmark omitted\n", p->bfont);
  113.         return 0;
  114.     }
  115.     }
  116.  
  117.     ypos = XPOS;
  118.     height = (font->max_bounds.ascent + font->max_bounds.descent) + 1;
  119.     if (bfont != NULL) {
  120.     int     h = (bfont->max_bounds.ascent + bfont->max_bounds.descent) + 1;
  121.     if (h > height)
  122.         height = h;
  123.     }
  124.     gcv.font = font->fid;
  125.     XChangeGC(xp->d, xp->fggc, GCFont, &gcv);
  126.     XChangeGC(xp->d, xp->bggc, GCFont, &gcv);
  127.  
  128.     charsPerLine = p->objects;
  129.     charsPerLine = (charsPerLine + 3) & ~3;
  130.     p->objects = charsPerLine;
  131.  
  132.     totalLines = '\177' - ' ' + 1;
  133.     if (totalLines > reps) totalLines = reps;
  134.  
  135.     charBuf = (char **) malloc(totalLines*sizeof (char *));
  136.     if (p->special)
  137.     items = (XTextItem *) malloc(totalLines*SEGS*sizeof (XTextItem));
  138.  
  139.     for (i = 0; i != totalLines; i++) {
  140.     charBuf[i] = (char *) malloc (sizeof (char)*charsPerLine);
  141.     ch = i + ' ';
  142.     for (j = 0; j != charsPerLine; j++) {
  143.         charBuf[i][j] = ch;
  144.         if (ch == '\177') ch = ' '; else ch++;
  145.     }
  146.     if (p->special) {
  147.         items[i*SEGS+0].chars = &(charBuf[i][0]);
  148.         items[i*SEGS+0].nchars = charsPerLine/4;
  149.         items[i*SEGS+0].delta = 0;
  150.         items[i*SEGS+0].font = font->fid;
  151.         items[i*SEGS+1].chars = &(charBuf[i][charsPerLine/4]);
  152.         items[i*SEGS+1].nchars = charsPerLine/2;
  153.         items[i*SEGS+1].delta = 3;
  154.         items[i*SEGS+1].font = bfont->fid;
  155.         items[i*SEGS+2].chars = &(charBuf[i][3*charsPerLine/4]);
  156.         items[i*SEGS+2].nchars = charsPerLine/4;
  157.         items[i*SEGS+2].delta = 3;
  158.         items[i*SEGS+2].font = font->fid;
  159.     }
  160.     }
  161.     return reps;
  162. }
  163.  
  164. void DoText(xp, p, reps)
  165.     XParms  xp;
  166.     Parms   p;
  167.     int     reps;
  168. {
  169.     int     i, line, startLine;
  170.  
  171.     startLine = 0;
  172.     line = 0;
  173.     for (i = 0; i != reps; i++) {
  174.     XDrawString(
  175.         xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine);
  176.     ypos += height;
  177.     if (ypos > HEIGHT - height) {
  178.         /* Wraparound to top of window */
  179.         ypos = XPOS;
  180.         line = startLine;
  181.         startLine = (startLine + 1) % totalLines;
  182.     }
  183.     line = (line + 1) % totalLines;
  184.     }
  185. }
  186.  
  187. void DoPolyText(xp, p, reps)
  188.     XParms  xp;
  189.     Parms   p;
  190.     int     reps;
  191. {
  192.     int     i, line, startLine;
  193.  
  194.     startLine = 0;
  195.     line = 0;
  196.     for (i = 0; i != reps; i++) {
  197.     XDrawText(
  198.         xp->d, xp->w, xp->fggc, XPOS, ypos, &items[line*SEGS], SEGS);
  199.     ypos += height;
  200.     if (ypos > HEIGHT - height) {
  201.         /* Wraparound to top of window */
  202.         ypos = XPOS;
  203.         line = startLine;
  204.         startLine = (startLine + 1) % totalLines;
  205.     }
  206.     line = (line + 1) % totalLines;
  207.     }
  208. }
  209.  
  210. void DoImageText(xp, p, reps)
  211.     XParms  xp;
  212.     Parms   p;
  213.     int     reps;
  214. {
  215.     int     i, line, startLine;
  216.  
  217.     startLine = 0;
  218.     line = 0;
  219.     for (i = 0; i != reps; i++) {
  220.     XDrawImageString(
  221.         xp->d, xp->w, xp->fggc, XPOS, ypos, charBuf[line], charsPerLine);
  222.     ypos += height;
  223.     if (ypos > HEIGHT - height) {
  224.         /* Wraparound to top of window */
  225.         ypos = XPOS;
  226.         startLine = (startLine + 17) % totalLines;
  227.         line = startLine;
  228.     }
  229.     line = (line + 1) % totalLines;
  230.     }
  231. }
  232.  
  233. void ClearTextWin(xp, p)
  234.     XParms  xp;
  235.     Parms   p;
  236. {
  237.     XClearWindow(xp->d, xp->w);
  238. }
  239.  
  240. void EndText(xp, p)
  241.     XParms  xp;
  242.     Parms   p;
  243. {
  244.     int i;
  245.  
  246.     for (i = 0; i != totalLines; i++)
  247.     free(charBuf[i]);
  248.     free(charBuf);
  249.     if (p->special)
  250.     free(items);
  251.     XFreeFont(xp->d, font);
  252.     if (bfont != NULL)
  253.     XFreeFont(xp->d, bfont);
  254. }
  255.  
  256. @
  257.  
  258.  
  259. 2.3
  260. log
  261. @Parameters to all routines now (xp, p)
  262. MAXROWS used in all routines
  263. Junked most global communication variables
  264. @
  265. text
  266. @d36 1
  267. a36 1
  268. Bool InitText(xp, p)
  269. d39 1
  270. d48 1
  271. a48 1
  272.     return False;
  273. d56 1
  274. a56 1
  275.         return False;
  276. d76 1
  277. a76 1
  278.     if (totalLines > p->reps) totalLines = p->reps;
  279. d104 1
  280. a104 1
  281.     return True;
  282. d107 1
  283. a107 1
  284. void DoText(xp, p)
  285. d110 1
  286. d116 1
  287. a116 1
  288.     for (i = 0; i != p->reps; i++) {
  289. d130 1
  290. a130 1
  291. void DoPolyText(xp, p)
  292. d133 1
  293. d139 1
  294. a139 1
  295.     for (i = 0; i != p->reps; i++) {
  296. d153 1
  297. a153 1
  298. void DoImageText(xp, p)
  299. d156 1
  300. d162 1
  301. a162 1
  302.     for (i = 0; i != p->reps; i++) {
  303. @
  304.  
  305.  
  306. 2.2
  307. log
  308. @No random numbers, made to fit 600x600 window, no clipped text at top of
  309. screen.
  310. @
  311. text
  312. @d1 23
  313. a25 1
  314. static Window w;
  315. a26 1
  316. static GC fggc, bggc;
  317. d33 1
  318. a33 1
  319. #define SEGMENTS 3
  320. d36 3
  321. a38 3
  322. Bool InitText(d, p)
  323.     Display *d;
  324.     Parms p;
  325. d40 3
  326. a42 3
  327.     int     i, j;
  328.     char    ch;
  329.     XGCValues gcv;
  330. d44 1
  331. a44 1
  332.     font = XLoadQueryFont (d, p->font);
  333. d50 1
  334. d52 1
  335. a52 1
  336.     bfont = XLoadQueryFont (d, p->bfont);
  337. a56 2
  338.     } else {
  339.     bfont = NULL;
  340. d58 1
  341. a65 1
  342.     CreatePerfStuff (d, 1, WIDTH, HEIGHT, &w, &bggc, &fggc);
  343. d67 2
  344. a68 2
  345.     XChangeGC (d, fggc, GCFont, &gcv);
  346.     XChangeGC (d, bggc, GCFont, &gcv);
  347. d79 1
  348. a79 1
  349.     items = (XTextItem *) malloc(totalLines*SEGMENTS*sizeof (XTextItem));
  350. d81 1
  351. a81 1
  352.     for (i = 0; i < totalLines; i++) {
  353. d84 1
  354. a84 1
  355.     for (j = 0; j < charsPerLine; j++) {
  356. d89 12
  357. a100 12
  358.         items[i*SEGMENTS+0].chars = &(charBuf[i][0]);
  359.         items[i*SEGMENTS+0].nchars = charsPerLine/4;
  360.         items[i*SEGMENTS+0].delta = 0;
  361.         items[i*SEGMENTS+0].font = font->fid;
  362.         items[i*SEGMENTS+1].chars = &(charBuf[i][charsPerLine/4]);
  363.         items[i*SEGMENTS+1].nchars = charsPerLine/2;
  364.         items[i*SEGMENTS+1].delta = 3;
  365.         items[i*SEGMENTS+1].font = bfont->fid;
  366.         items[i*SEGMENTS+2].chars = &(charBuf[i][3*charsPerLine/4]);
  367.         items[i*SEGMENTS+2].nchars = charsPerLine/4;
  368.         items[i*SEGMENTS+2].delta = 3;
  369.         items[i*SEGMENTS+2].font = font->fid;
  370. d106 3
  371. a108 3
  372. void DoText(d, p)
  373.     Display *d;
  374.     Parms p;
  375. d114 3
  376. a116 2
  377.     for (i = 0; i < p->reps; i++) {
  378.     XDrawString(d, w, fggc, XPOS, ypos, charBuf[line], charsPerLine);
  379. d128 3
  380. a130 3
  381. void DoPolyText(d, p)
  382.     Display *d;
  383.     Parms p;
  384. d136 3
  385. a138 2
  386.     for (i = 0; i < p->reps; i++) {
  387.     XDrawText(d, w, fggc, XPOS, ypos, &items[line*SEGMENTS], SEGMENTS);
  388. d150 3
  389. a152 3
  390. void DoImageText(d, p)
  391.     Display *d;
  392.     Parms p;
  393. d158 1
  394. a158 1
  395.     for (i = 0; i < p->reps; i++) {
  396. d160 1
  397. a160 1
  398.         d, w, fggc, XPOS, ypos, charBuf[line], charsPerLine);
  399. d172 3
  400. a174 1
  401. void ClearTextWin(d, numLines)
  402. d176 1
  403. a176 1
  404.     XClearWindow(d, w);
  405. d179 3
  406. a181 3
  407. void EndText(d, p)
  408.     Display *d;
  409.     Parms p;
  410. d185 1
  411. a185 4
  412.     XDestroyWindow(d, w);
  413.     XFreeGC(d, fggc);
  414.     XFreeGC(d, bggc);
  415.     for (i = 0; i < totalLines; i++)
  416. d190 1
  417. a190 1
  418.     XFreeFont(d, font);
  419. d192 1
  420. a192 1
  421.     XFreeFont(d, bfont);
  422. @
  423.  
  424.  
  425. 2.1
  426. log
  427. @Massive changes, I'm not going to go into details.
  428. @
  429. text
  430. @d4 1
  431. a4 1
  432. static char **charBuf = NULL;
  433. d9 1
  434. a12 2
  435. #define STARTBOLD 20
  436. #define NUMBOLD 20
  437. d14 1
  438. d20 1
  439. d45 1
  440. a45 1
  441.     CreatePerfStuff (d, 1, 800, HEIGHT, &w, &bggc, &fggc);
  442. d50 17
  443. a66 25
  444.     if (charBuf == NULL) {
  445.     charBuf = (char **) malloc(p->reps*sizeof (char *));
  446.     if (p->special)
  447.         items = (XTextItem *) malloc(p->reps*SEGMENTS*sizeof (XTextItem));
  448.     else
  449.         items = NULL;
  450.     for (i = 0; i < p->reps; i++) {
  451.         charBuf[i] = (char *) malloc (sizeof (char)*CHARS);
  452.         for (j = 0; j < CHARS; j++) {
  453.         charBuf[i][j] = ' ' + (rand () % ('\177' - ' '));
  454.         if (p->special) {
  455.             items[i*SEGMENTS+0].chars = &(charBuf[i][0]);
  456.             items[i*SEGMENTS+0].nchars = STARTBOLD;
  457.             items[i*SEGMENTS+0].delta = 0;
  458.             items[i*SEGMENTS+0].font = font->fid;
  459.             items[i*SEGMENTS+1].chars = &(charBuf[i][STARTBOLD]);
  460.             items[i*SEGMENTS+1].nchars = NUMBOLD;
  461.             items[i*SEGMENTS+1].delta = 3;
  462.             items[i*SEGMENTS+1].font = bfont->fid;
  463.             items[i*SEGMENTS+2].chars = &(charBuf[i][STARTBOLD + NUMBOLD]);
  464.             items[i*SEGMENTS+2].nchars = CHARS - (STARTBOLD + NUMBOLD);
  465.             items[i*SEGMENTS+2].delta = 3;
  466.             items[i*SEGMENTS+2].font = font->fid;
  467.         }
  468.         }
  469. d68 14
  470. d90 1
  471. a90 1
  472.     int     i;
  473. d92 2
  474. d95 9
  475. a103 2
  476.     XDrawString(d, w, fggc, XPOS, ypos, charBuf[i], CHARS);
  477.     ypos = (ypos + height) % (HEIGHT - height);
  478. d111 1
  479. a111 1
  480.     int     i;
  481. d113 2
  482. d116 9
  483. a124 2
  484.     XDrawText(d, w, fggc, XPOS, ypos, &items[i*SEGMENTS], SEGMENTS);
  485.     ypos = (ypos + height) % (HEIGHT - height);
  486. d132 1
  487. a132 1
  488.     int     i;
  489. d134 2
  490. d138 9
  491. a146 2
  492.         d, w, (i & 1) ? fggc : bggc, XPOS, ypos, charBuf[i], CHARS);
  493.     ypos = (ypos + height) % (HEIGHT - height);
  494. d164 1
  495. a164 1
  496.     for (i = 0; i < p->reps; i++)
  497. d167 1
  498. a167 1
  499.     if (items != NULL)
  500. a168 1
  501.     charBuf = NULL;
  502. @
  503.  
  504.  
  505. 2.0
  506. log
  507. @version from /usr/src/pmax
  508. @
  509. text
  510. @d15 1
  511. a15 1
  512. void InitText(d, p)
  513. d23 6
  514. a28 1
  515.     if (p->bfont != NULL)
  516. d30 5
  517. a34 1
  518.     else
  519. d36 1
  520. d76 1
  521. @
  522.  
  523.  
  524. 1.3
  525. log
  526. @Added -fg -bg capabilities
  527. @
  528. text
  529. @@
  530.  
  531.  
  532. 1.2
  533. log
  534. @Made charBuf static so as not to interfere with other modules,
  535. like do_plane.c
  536. @
  537. text
  538. @d5 1
  539. a5 1
  540. static GC blackgc, whitegc;
  541. d34 1
  542. a34 1
  543.     CreatePerfStuff (d, 1, 800, HEIGHT, &w, &whitegc, &blackgc);
  544. d36 2
  545. a37 2
  546.     XChangeGC (d, blackgc, GCFont, &gcv);
  547.     XChangeGC (d, whitegc, GCFont, &gcv);
  548. d75 1
  549. a75 1
  550.     XDrawString(d, w, blackgc, XPOS, ypos, charBuf[i], CHARS);
  551. d87 1
  552. a87 1
  553.     XDrawText(d, w, blackgc, XPOS, ypos, &items[i*SEGMENTS], SEGMENTS);
  554. d100 1
  555. a100 1
  556.         d, w, (i & 1) ? blackgc : whitegc, XPOS, ypos, charBuf[i], CHARS);
  557. d117 2
  558. a118 2
  559.     XFreeGC(d, blackgc);
  560.     XFreeGC(d, whitegc);
  561. @
  562.  
  563.  
  564. 1.1
  565. log
  566. @Initial revision
  567. @
  568. text
  569. @d4 1
  570. a4 1
  571. char **charBuf = NULL;
  572. @
  573.