1 /********************************************************************
2 *
3 * @(#)put.c 1.2 (CWI) 87/07/10
4 *
5 * code to put a character
6 *
7 *******************************************************************/
8
9 #include "the.h"
10
11 extern struct dev dev;
12 extern struct Font *fontbase[];
13 extern int output;
14 extern short *pstab;
15 extern int nfonts, smnt, nchtab;
16 extern char *chname, *fitab[];
17 extern char *widthtab[], *codetab[];
18 extern short *chtab, *fonttab[];
19 extern struct fontname fontname[];
20 extern int size, font, hpos, vpos, lastw, maxv;
21 extern int virtRES;
22 extern char buffer[];
23 extern int vorigin, pagelen;
24 extern int debug, dbg;
25
26
27
28
29 /*
30 * s is the name of a special character
31 */
32
put1s(s)33 put1s(s)
34 char *s;
35 {
36 int i;
37
38 if (!output)
39 return;
40
41 DBGPRINT(2, ("%s ", s));
42
43 for (i = 0; i < nchtab; i++)
44 if (strcmp(&chname[chtab[i]], s) == 0)
45 break;
46
47 if (i < nchtab)
48 put1(i + 128);
49 }
50
51
52 /*
53 * output char c
54 */
55
put1(c)56 put1(c)
57 int c;
58 {
59 char *pw;
60 register char *p;
61 register int i, k;
62 int ofont, code;
63 short f;
64
65 if (!output)
66 return;
67
68 c -= 32;
69 if (c <= 0) {
70 DBGPRINT(0, ("non-exist 0%o\n", c+32));
71 lastw = (widthtab[font][0] * pstab[size] + dev.unitwidth/2)/dev.unitwidth;
72 return;
73 }
74 k = ofont = font;
75
76 /* try to find it on this font
77 */
78 i = fitab[font][c] & BMASK;
79 if (i != 0) {
80 p = codetab[font];
81 pw = widthtab[font];
82 }
83 /* well, check special font
84 */
85 else if ((smnt > 0) && ((i = fitab[smnt][c] & BMASK) != 0)) {
86 k = smnt;
87 p = codetab[k];
88 pw = widthtab[k];
89 setfont(k);
90 }
91 /* now just see if we can find something on another font.
92 */
93 else {
94 for (k=1; k <= nfonts; k++) {
95 if ( k == smnt ) continue;
96 if ((i = fitab[k][c] & BMASK) != 0) {
97 p = codetab[k];
98 pw = widthtab[k];
99 setfont(k);
100 break;
101 }
102 }
103 }
104 if (i == 0 || (code = p[i] & BMASK) == 0 || k > nfonts) {
105 #ifdef DEBUGABLE
106 if (dbg) {
107 if (isprint(c+32) && isascii(c+32))
108 fprintf(stderr,"not found %c\n", c+32);
109 else
110 fprintf(stderr,"not found \\(%s\n", &chname[chtab[c -128+32]]);
111 }
112 #endif DEBUGABLE
113 lastw = (widthtab[font][0] * pstab[size] + dev.unitwidth/2)/dev.unitwidth;
114 return;
115 }
116 if (fontbase[k]->fonttab == 1){
117 f = fonttab[k][i];
118 }
119 else {
120 f = fontname[k].number;
121 }
122 #ifdef DEBUGABLE
123 if (dbg) {
124 if (isprint(c+32) && isascii(c+32)) { /* My God! */
125 fprintf(stderr,"%c %d %d\n", c+32, code, f);
126 }
127 else
128 fprintf(stderr,"\\(%s %d %d\n", &chname[chtab[c -128+32]], code, f);
129 }
130 #endif DEBUGABLE
131 /*
132 if(code == 0 || code > 0200) {
133 error(FATAL,"Illegal code 0%o found for char %03o\n", code, c+32);
134 }
135 */
136 putcode(code, f); /* character is < 254 */
137 if (font != ofont) /* char on special font, reset */
138 setfont(ofont);
139 lastw = pw[i] & NMASK;
140
141 lastw = (lastw * pstab[size] + dev.unitwidth/2) / dev.unitwidth;
142 }
143
144
145
146
147
148 /*
149 * Plot a dot at (x, y).
150 *
151 * x and y are *VIRTUAL* coordinates (a change from prev. versions).
152 *
153 * The physical mapping of the point should be in the range 0 <= x < RASTER_LENGTH,
154 * vorigin <= y < vorigin + NLINES. If the point will not fit on the buffer,
155 * it is left out. Things outside the x boundary are wrapped around the end.
156 */
157
point(x,y)158 point(x, y)
159 register int x;
160 register int y;
161 {
162 register char *ptr;
163
164 x = PHYS(x);
165 y = PHYS(y);
166
167 ptr = buf0p + (y - vorigin) * BYTES_PER_LINE + (x >> 3);
168
169 if (ptr > BUFBOTTOM || ptr < BUFTOP) /* ignore if it's off buffer */
170 return;
171
172 *ptr |= 1 << (7 - (x & 07));
173 if (y > maxv) maxv = y;
174 }
175