home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / fp / ifp_unix.lzh / ifp / interp / G_confont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-23  |  11.0 KB  |  309 lines

  1.  
  2. /* Written 12:01 pm  Jan  8, 1985 by gwyn@brl-tgr in uiucdcsb:net.unix */
  3. /*
  4.     symbol -- software character generator subroutine
  5.  
  6.     last edit:    26-Nov-1984    D A Gwyn
  7.             18-Mar-1985     A D Robison - hacked for GSI card
  8.                               rehacked for console
  9.  
  10. Function:
  11.  
  12.     This routine plots an ASCII character string as vector strokes.
  13.  
  14.  
  15. Calling sequence:
  16.  
  17.     void ConSymbol (
  18.              char *string,       // -> NUL-terminated string
  19.              int transform [2][3]; // text transformation //
  20.            );
  21.  
  22. The characters are on a 6 high by 4 wide grid.  The transform is scaled
  23. by 1024 and transforms from the character grid onto console device coordinates.
  24. E.g. the unit transform is {{1024,0,0},{0,1024,0}}.
  25.  
  26. */
  27.  
  28. /*
  29.                 STROKE TABLES
  30.  
  31.     The stroke[] table contains encodings for all vector strokes
  32.     needed to draw each character at a standard size.  Actual plot
  33.     output is of course properly positioned, scaled, and rotated.
  34.     To keep code size small, variable-length entries are used; each
  35.     character stroke sequence is terminated by a 0 datum.  Pointers
  36.     to the appropriate data for every character is stored into
  37.     sstroke[] during a one-time initialization.
  38.  
  39.     The prototypes are constrained to a 4 x 6 unit area, except for
  40.     occasional descenders up to 2 units below the baseline.  All
  41.     visible strokes should be "basic" vectors (in directions that
  42.     are integral multiples of 45 degrees) for best overall results
  43.     on most devices, especially with small character height.  The
  44.     first 16 "control" characters are plotted as non-standard extra
  45.     symbols, the next 16 produce Calcomp "centered plotting symbols"
  46.     (not centered here!), and the final 96 characters are plotted as
  47.     corresponding ASCII graphics (DEL plots as a grid).
  48.  
  49.     A prototype stroke is encoded as 8 bits SVXXXYYY:
  50.         S    = 0 if YYY is correct as is
  51.               1 if YYY needs to have 2 subtracted
  52.         V    = 0 if stroke is invisible (move)
  53.               1 if stroke is visible (draw)
  54.         XXX    = final X coord of stroke (0..4)
  55.         YYY    = final Y coord of stroke (0..6)
  56. */
  57.  
  58. /* bit masks for fields in stroke vector */
  59.  
  60. #define    S    0200
  61. #define    V    0100
  62. #define    XXX    0070
  63. #define    YYY    0007
  64.  
  65. #define    XJUST    3            /* bits to the right of XXX */
  66.  
  67. /* stroke vectors for all characters */
  68.  
  69. static char    stroke[] =
  70.     {
  71. /*NUL*/    0003, 0105, 0123, 0143, 0141, 0121, 0125, 0,
  72. /*SOH*/    0006, 0115, 0112, 0142, 0022, 0121, 0141, 0140, 0120, 0013,
  73.     0133, 0034, 0114, 0015, 0126, 0,
  74. /*STX*/    0021, 0125, 0105, 0103, 0123, 0141, 0143, 0,
  75. /*ETX*/    0012, 0114, 0034, 0104, 0106, 0126, 0124, 0033, 0113, 0021,
  76.     0141, 0042, 0122, 0120, 0,
  77. /*EOT*/    0005, 0125, 0134, 0145, 0143, 0023, 0125, 0015, 0113, 0,
  78. /*ENQ*/    0011, 0131, 0142, 0144, 0135, 0115, 0104, 0102, 0111, 0012,
  79.     0114, 0134, 0133, 0113, 0023, 0132, 0,
  80. /*ACK*/    0011, 0131, 0142, 0144, 0135, 0115, 0104, 0102, 0111, 0034,
  81.     0114, 0112, 0132, 0,
  82. /*BEL*/    0021, 0122, 0142, 0133, 0134, 0124, 0125, 0024, 0114, 0113,
  83.     0102, 0122, 0,
  84. /*BS */    0012, 0103, 0114, 0003, 0143, 0,
  85. /*HT */    0003, 0143, 0034, 0143, 0132, 0,
  86. /*LF */    0012, 0121, 0132, 0021, 0125, 0,
  87. /*VT */    0021, 0125, 0014, 0125, 0134, 0,
  88. /*FF */    0012, 0121, 0132, 0021, 0125, 0014, 0125, 0134, 0,
  89. /*CR */    0012, 0103, 0114, 0003, 0143, 0034, 0143, 0132, 0,
  90. /*SO */    0004, 0124, 0126, 0106, 0104, 0014, 0112, 0142, 0034, 0130, 0,
  91. /*SI */    0021, 0123, 0013, 0115, 0025, 0105, 0003, 0123, 0141, 0143, 0,
  92. /*DLE*/    0023, 0125, 0145, 0141, 0101, 0105, 0125, 0,
  93. /*DC1*/    0023, 0125, 0135, 0144, 0142, 0131, 0111, 0102, 0104, 0115,
  94.     0125, 0,
  95. /*DC2*/    0023, 0124, 0142, 0102, 0124, 0,
  96. /*DC3*/    0021, 0125, 0003, 0143, 0,
  97. /*DC4*/    0001, 0145, 0005, 0141, 0,
  98. /*NAK*/    0023, 0125, 0143, 0121, 0103, 0125, 0,
  99. /*SYN*/    0021, 0125, 0143, 0103, 0125, 0,
  100. /*ETB*/    0001, 0145, 0105, 0141, 0,
  101. /*CAN*/    0005, 0145, 0101, 0141, 0,
  102. /*EM */    0023, 0121, 0005, 0123, 0145, 0,
  103. /*SUB*/    0023, 0145, 0034, 0132, 0141, 0032, 0112, 0101, 0012, 0114,
  104.     0105, 0014, 0134, 0,
  105. /*ESC*/    0001, 0145, 0025, 0121, 0041, 0105, 0003, 0143, 0,
  106. /*FS */    0001, 0141, 0105, 0145, 0101, 0,
  107. /*GS */    0021, 0125, 0,
  108. /*RS */    0023, 0125, 0024, 0142, 0102, 0124, 0021, 0122, 0144, 0104,
  109.     0122, 0,
  110. /*US */    0023, 0143, 0,
  111. /*SP */    0,
  112. /* ! */    0020, 0121, 0022, 0126, 0,
  113. /* " */    0014, 0116, 0036, 0134, 0,
  114. /* # */    0010, 0116, 0036, 0130, 0042, 0102, 0004, 0144, 0,
  115. /* $ */    0002, 0111, 0131, 0142, 0133, 0113, 0104, 0115, 0135, 0144,
  116.     0026, 0120, 0,
  117. /* % */    0001, 0145, 0025, 0114, 0105, 0116, 0125, 0032, 0141, 0130,
  118.     0121, 0132, 0,
  119. /* & */    0040, 0104, 0105, 0116, 0125, 0124, 0102, 0101, 0110, 0120,
  120.     0142, 0,
  121. /* ' */    0014, 0136, 0,
  122. /* ( */    0030, 0112, 0114, 0136, 0,
  123. /* ) */    0010, 0132, 0134, 0116, 0,
  124. /* * */    0001, 0145, 0025, 0121, 0041, 0105, 0,
  125. /* + */    0021, 0125, 0003, 0143, 0,
  126. /* , */    0211, 0120, 0121, 0,
  127. /* - */    0003, 0143, 0,
  128. /* . */    0020, 0121, 0,
  129. /* / */    0001, 0145, 0,
  130. /* 0 */    0001, 0145, 0136, 0116, 0105, 0101, 0110, 0130, 0141, 0145, 0,
  131. /* 1 */    0010, 0130, 0020, 0126, 0115, 0,
  132. /* 2 */    0005, 0116, 0136, 0145, 0144, 0100, 0140, 0,
  133. /* 3 */    0001, 0110, 0130, 0141, 0142, 0133, 0144, 0145, 0136, 0116,
  134.     0105, 0023, 0133, 0,
  135. /* 4 */    0030, 0136, 0024, 0102, 0142, 0,
  136. /* 5 */    0001, 0110, 0130, 0141, 0143, 0134, 0114, 0103, 0106, 0146, 0,
  137. /* 6 */    0002, 0113, 0133, 0142, 0141, 0130, 0110, 0101, 0105, 0116,
  138.     0136, 0145, 0,
  139. /* 7 */    0006, 0146, 0145, 0112, 0110, 0,
  140. /* 8 */    0013, 0102, 0101, 0110, 0130, 0141, 0142, 0133, 0113, 0104,
  141.     0105, 0116, 0136, 0145, 0144, 0133, 0,
  142. /* 9 */    0001, 0110, 0130, 0141, 0145, 0136, 0116, 0105, 0104, 0113,
  143.     0133, 0144, 0,
  144. /* : */    0020, 0121, 0023, 0124, 0,
  145. /* ; */    0211, 0120, 0121, 0023, 0124, 0,
  146. /* < */    0030, 0103, 0136, 0,
  147. /* = */    0002, 0142, 0044, 0104, 0,
  148. /* > */    0010, 0143, 0116, 0,
  149. /* ? */    0005, 0116, 0136, 0145, 0144, 0122, 0021, 0120, 0,
  150. /* @ */    0031, 0133, 0124, 0113, 0112, 0121, 0131, 0142, 0144, 0135,
  151.     0115, 0104, 0101, 0110, 0130, 0,
  152. /* A */    0104, 0126, 0144, 0140, 0042, 0102, 0,
  153. /* B */    0130, 0141, 0142, 0133, 0144, 0145, 0136, 0106, 0100, 0003,
  154.     0133, 0,
  155. /* C */    0045, 0136, 0116, 0105, 0101, 0110, 0130, 0141, 0,
  156. /* D */    0130, 0141, 0145, 0136, 0106, 0100, 0,
  157. /* E */    0003, 0133, 0046, 0106, 0100, 0140, 0,
  158. /* F */    0106, 0146, 0033, 0103, 0,
  159. /* G */    0022, 0142, 0141, 0130, 0110, 0101, 0105, 0116, 0136, 0145, 0,
  160. /* H */    0106, 0046, 0140, 0043, 0103, 0,
  161. /* I */    0010, 0130, 0020, 0126, 0016, 0136, 0,
  162. /* J */    0001, 0110, 0130, 0141, 0146, 0,
  163. /* K */    0106, 0046, 0102, 0013, 0140, 0,
  164. /* L */    0006, 0100, 0140, 0,
  165. /* M */    0106, 0124, 0146, 0140, 0,
  166. /* N */    0106, 0005, 0141, 0040, 0146, 0,
  167. /* O */    0010, 0130, 0141, 0145, 0136, 0116, 0105, 0101, 0110, 0,
  168. /* P */    0106, 0136, 0145, 0144, 0133, 0103, 0,
  169. /* Q */    0010, 0130, 0141, 0145, 0136, 0116, 0105, 0101, 0110, 0022,
  170.     0140, 0,
  171. /* R */    0106, 0136, 0145, 0144, 0133, 0103, 0013, 0140, 0,
  172. /* S */    0001, 0110, 0130, 0141, 0142, 0133, 0113, 0104, 0105, 0116,
  173.     0136, 0145, 0,
  174. /* T */    0020, 0126, 0006, 0146, 0,
  175. /* U */    0006, 0101, 0110, 0130, 0141, 0146, 0,
  176. /* V */    0006, 0102, 0120, 0142, 0146, 0,
  177. /* W */    0006, 0100, 0122, 0140, 0146, 0,
  178. /* X */    0101, 0145, 0146, 0006, 0105, 0141, 0140, 0,
  179. /* Y */    0020, 0123, 0105, 0106, 0046, 0145, 0123, 0,
  180. /* Z */    0040, 0100, 0101, 0145, 0146, 0106, 0013, 0133, 0,
  181. /* [ */    0030, 0110, 0116, 0136, 0,
  182. /* \ */    0005, 0141, 0,
  183. /* ] */    0010, 0130, 0136, 0116, 0,
  184. /* ^ */    0004, 0126, 0144, 0,
  185. /* _ */    0201, 0341, 0,
  186. /* ` */    0016, 0134, 0,
  187. /* a */    0003, 0114, 0134, 0143, 0140, 0042, 0112, 0101, 0110, 0130,
  188.     0141, 0,
  189. /* b */    0106, 0001, 0110, 0130, 0141, 0143, 0134, 0114, 0103, 0,
  190. /* c */    0043, 0134, 0114, 0103, 0101, 0110, 0130, 0141, 0,
  191. /* d */    0043, 0134, 0114, 0103, 0101, 0110, 0130, 0141, 0040, 0146, 0,
  192. /* e */    0002, 0142, 0143, 0134, 0114, 0103, 0101, 0110, 0130, 0141, 0,
  193. /* f */    0010, 0115, 0126, 0136, 0145, 0034, 0104, 0,
  194. /* g */    0201, 0310, 0330, 0341, 0144, 0041, 0130, 0110, 0101, 0103,
  195.     0114, 0134, 0143, 0,
  196. /* h */    0106, 0003, 0114, 0134, 0143, 0140, 0,
  197. /* i */    0020, 0124, 0114, 0025, 0126, 0,
  198. /* j */    0201, 0310, 0330, 0341, 0144, 0045, 0146, 0,
  199. /* k */    0106, 0044, 0100, 0022, 0140, 0,
  200. /* l */    0020, 0126, 0116, 0,
  201. /* m */    0104, 0003, 0114, 0123, 0120, 0040, 0143, 0134, 0123, 0,
  202. /* n */    0104, 0003, 0114, 0134, 0143, 0140, 0,
  203. /* o */    0010, 0130, 0141, 0143, 0134, 0114, 0103, 0101, 0110, 0,
  204. /* p */    0001, 0110, 0130, 0141, 0143, 0134, 0114, 0103, 0004, 0300, 0,
  205. /* q */    0041, 0130, 0110, 0101, 0103, 0114, 0134, 0143, 0044, 0340, 0,
  206. /* r */    0104, 0003, 0114, 0134, 0143, 0,
  207. /* s */    0001, 0110, 0130, 0141, 0132, 0112, 0103, 0114, 0134, 0143, 0,
  208. /* t */    0004, 0134, 0015, 0111, 0120, 0130, 0141, 0,
  209. /* u */    0004, 0101, 0110, 0130, 0141, 0040, 0144, 0,
  210. /* v */    0004, 0102, 0120, 0142, 0144, 0,
  211. /* w */    0004, 0101, 0110, 0121, 0022, 0121, 0130, 0141, 0144, 0,
  212. /* x */    0144, 0004, 0140, 0,
  213. /* y */    0201, 0310, 0330, 0341, 0144, 0004, 0101, 0110, 0130, 0141, 0,
  214. /* z */    0004, 0144, 0100, 0140, 0,
  215. /* { */    0030, 0121, 0122, 0113, 0124, 0125, 0136, 0,
  216. /* | */    0020, 0126, 0,
  217. /* } */    0010, 0121, 0122, 0133, 0124, 0125, 0116, 0,
  218. /* ~ */    0005, 0116, 0134, 0145, 0,
  219. /*DEL*/    0140, 0146, 0106, 0100, 0010, 0116, 0026, 0120, 0030, 0136, 0
  220.     };
  221.  
  222. /* pointers to start of stroke data for each character */
  223.  
  224. static char    *sstroke[128] = {(char *) 0};
  225.  
  226.             /* CONSTANTS */
  227. #define    CHSPAC    6            /* prototype text spacing */
  228. #define    ASCMASK    0177            /* 7-bit ASCII mask */
  229. #define void int
  230.  
  231.             /* GLOBAL DATA */
  232.  
  233. static int (*T)[3];            /* text transformation */
  234.  
  235.             /* ENTRY POINT */
  236.  
  237. void ConSymbol (string,transform)
  238.    char *string;        /* -> NUL-terminated string */
  239.    int    transform[2][3];    /* text transformation */
  240.    {
  241.       register char *sp;    /* -> stroke data */
  242.       register int cornx;    /* proto X of cell corner */
  243.       register int c;            /* char from ASCII string    */
  244.                 /* also used for stroke data */
  245.  
  246.       /* initialize starting stroke pointers upon first entry only */
  247.  
  248.       if (!sstroke[0]) {
  249.      sp = stroke;
  250.      for (c = 0; c < 128; ++c) {
  251.         sstroke [c] = sp;              /* starts here */
  252.         while (*sp++) continue;          /* 0 terminates the data */
  253.      }
  254.       }
  255.  
  256.       T = transform;
  257.  
  258.       /* look up strokes for each character and plot them */
  259.  
  260.       for (cornx = 0; c = *string++; cornx += CHSPAC) {
  261.  
  262.      sp = sstroke [c & ASCMASK]; /* -> stroke data */
  263.  
  264.      plot (cornx,0,0,0);     /* get to character cell LLC */
  265.  
  266.      /* draw the strokes starting at LLC */
  267.  
  268.      while (c = *sp++ )    /* get stroke */
  269.         plot (cornx + ((c & XXX) >> XJUST),
  270.           (c & YYY) - ((c & S) ? 2 : 0),
  271.           (c & V),
  272.           (*sp & V));    /* move or draw */
  273.       }
  274.    }
  275.  
  276. /* transform prototype coordinates to actual plot coordinates */
  277. #define map(x,y,n) ((T[n][0] * x + T[n][1]*y + T[n][2]) + 512 >> 10);
  278.  
  279. static void plot (dx,dy,vis,NextVis)    /* plot adjusted stroke */
  280.    int dx,dy;                /* unrot pos rel to text LLC */
  281.    int vis;                    /* nonzero => visible */
  282.    int NextVis;                /* Is the next stroke visible? */
  283.    {
  284.       static int oldposx=0,oldposy=0;
  285.       static int olddx,olddy;
  286.       static int oldValid;
  287.       int posx,posy;
  288.  
  289.       if (vis && !oldValid) {
  290.      oldposx = map (olddx,olddy,0);
  291.      oldposy = map (olddx,olddy,1);
  292.      VI_AMove (oldposx,oldposy);
  293.       }
  294.       posx = map (dx,dy,0);
  295.       posy = map (dx,dy,1);
  296.  
  297.       /* no arithmetic overflow checking is done */
  298.  
  299.       if (vis) VI_RLine (posx-oldposx,posy-oldposy);
  300.  
  301.       oldValid = vis;
  302.       olddx = dx;
  303.       olddy = dy;
  304.       oldposx = posx;
  305.       oldposy = posy;
  306.    }
  307.  
  308. /* End of text from uiucdcsb:net.unix */
  309.