dtinfo: remove register keyword
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / cgm / cgmtext.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: cgmtext.c /main/5 1996/06/11 16:09:46 cde-hal $ */
24 /* this is a set of Hershey font routines. No attempt is made to copyright
25    this code, we use only one font: simplex Roman */
26 /* optimised for calling XLib commands */
27 #include <X11/Xlib.h>     /* XLib stuff */
28 #include "cgm.h"                /* our defs */
29 /* how many characters */
30 #define MAX_HCHARS 128
31 /* pointers into main array */
32 static int h_array[MAX_HCHARS] = {
33 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
34 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
35 0,4,24,38,64,120,186,258,266,290,314,334,348,368,376,390,
36 398,436,448,480,514,530,568,618,632,694,744,770,802,812,826,836,
37 - -1,880,900,950,990,1024,1050,1070,1118,1138,1146,1170,1190,1204,1230,1250,
38 1296,1326,1378,1414,1458,1472,1496,1510,1536,1550,1566,-1,1586,-1,1594,-1,
39 1608,1624,1662,1700,1732,1770,1808,1828,1876,1900,1920,1946,1966,1974,2014,2038,
40 2076,2114,2152,2172,2210,2230,2254,2268,2294,2308,2330,-1,2350,-1,-1,-1};
41
42 /* main data array */
43 #define MAX_OFFSET 2358
44 static unsigned char hf_array[MAX_OFFSET] = {
45 120,136,0,0,123,133,128,116,128,130,0,128,128,135,127,136,128,137,129,136,
46 128,135,0,0,120,136,124,116,124,123,0,128,132,116,132,123,0,0,118,139,
47 129,112,122,144,0,128,135,112,128,144,0,128,122,125,136,125,0,128,121,131,
48 135,131,0,0,118,138,126,112,126,141,0,128,130,112,130,141,0,128,135,119,
49 133,117,130,116,126,116,123,117,121,119,121,121,122,123,123,124,125,125,131,127,
50 133,128,134,129,135,131,135,134,133,136,130,137,126,137,123,136,121,134,0,0,
51 116,140,137,116,119,137,0,128,124,116,126,118,126,120,125,122,123,123,121,123,
52 119,121,119,119,120,117,122,116,124,116,126,117,129,118,132,118,135,117,137,116,
53 0,128,133,130,131,131,130,133,130,135,132,137,134,137,136,136,137,134,137,132,
54 135,130,133,130,0,0,115,141,138,125,138,124,137,123,136,123,135,124,134,126,
55 132,131,130,134,128,136,126,137,122,137,120,136,119,135,118,133,118,131,119,129,
56 120,128,127,124,128,123,129,121,129,119,128,117,126,116,124,117,123,119,123,121,
57 124,124,126,127,131,134,133,136,135,137,137,137,138,136,138,135,0,0,124,132,
58 128,116,128,123,0,0,121,135,132,112,130,114,128,117,126,121,125,126,125,130,
59 126,135,128,139,130,142,132,144,0,0,121,135,124,112,126,114,128,117,130,121,
60 131,126,131,130,130,135,128,139,126,142,124,144,0,0,120,136,128,122,128,134,
61 0,128,123,125,133,131,0,128,133,125,123,131,0,0,115,141,128,119,128,137,
62 0,128,119,128,137,128,0,0,123,133,129,136,128,137,127,136,128,135,129,136,
63 129,138,128,140,127,141,0,0,115,141,119,128,137,128,0,0,123,133,128,135,
64 127,136,128,137,129,136,128,135,0,0,117,139,137,112,119,144,0,0,118,138,
65 127,116,124,117,122,120,121,125,121,128,122,133,124,136,127,137,129,137,132,136,
66 134,133,135,128,135,125,134,120,132,117,129,116,127,116,0,0,118,138,124,120,
67 126,119,129,116,129,137,0,0,118,138,122,121,122,120,123,118,124,117,126,116,
68 130,116,132,117,133,118,134,120,134,122,133,124,131,127,121,137,135,137,0,0,
69 118,138,123,116,134,116,128,124,131,124,133,125,134,126,135,129,135,131,134,134,
70 132,136,129,137,126,137,123,136,122,135,121,133,0,0,118,138,131,116,121,130,
71 136,130,0,128,131,116,131,137,0,0,118,138,133,116,123,116,122,125,123,124,
72 126,123,129,123,132,124,134,126,135,129,135,131,134,134,132,136,129,137,126,137,
73 123,136,122,135,121,133,0,0,118,138,134,119,133,117,130,116,128,116,125,117,
74 123,120,122,125,122,130,123,134,125,136,128,137,129,137,132,136,134,134,135,131,
75 135,130,134,127,132,125,129,124,128,124,125,125,123,127,122,130,0,0,118,138,
76 135,116,125,137,0,128,121,116,135,116,0,0,118,138,126,116,123,117,122,119,
77 122,121,123,123,125,124,129,125,132,126,134,128,135,130,135,133,134,135,133,136,
78 130,137,126,137,123,136,122,135,121,133,121,130,122,128,124,126,127,125,131,124,
79 133,123,134,121,134,119,133,117,130,116,126,116,0,0,118,138,134,123,133,126,
80 131,128,128,129,127,129,124,128,122,126,121,123,121,122,122,119,124,117,127,116,
81 128,116,131,117,133,119,134,123,134,128,133,133,131,136,128,137,126,137,123,136,
82 122,134,0,0,123,133,128,123,127,124,128,125,129,124,128,123,0,128,128,135,
83 127,136,128,137,129,136,128,135,0,0,123,133,128,123,127,124,128,125,129,124,
84 128,123,0,128,129,136,128,137,127,136,128,135,129,136,129,138,128,140,127,141,
85 0,0,116,140,136,119,120,128,136,137,0,0,115,141,119,125,137,125,0,128,
86 119,131,137,131,0,0,116,140,120,119,136,128,120,137,0,0,119,137,122,121,
87 122,120,123,118,124,117,126,116,130,116,132,117,133,118,134,120,134,122,133,124,
88 132,125,128,127,128,130,0,128,128,135,127,136,128,137,129,136,128,135,0,0,
89 119,137,128,116,120,137,0,128,128,116,136,137,0,128,123,130,133,130,0,0,
90 117,138,121,116,121,137,0,128,121,116,130,116,133,117,134,118,135,120,135,122,
91 134,124,133,125,130,126,0,128,121,126,130,126,133,127,134,128,135,130,135,133,
92 134,135,133,136,130,137,121,137,0,0,118,139,136,121,135,119,133,117,131,116,
93 127,116,125,117,123,119,122,121,121,124,121,129,122,132,123,134,125,136,127,137,
94 131,137,133,136,135,134,136,132,0,0,117,138,121,116,121,137,0,128,121,116,
95 128,116,131,117,133,119,134,121,135,124,135,129,134,132,133,134,131,136,128,137,
96 121,137,0,0,118,137,122,116,122,137,0,128,122,116,135,116,0,128,122,126,
97 130,126,0,128,122,137,135,137,0,0,118,136,122,116,122,137,0,128,122,116,
98 135,116,0,128,122,126,130,126,0,0,118,139,136,121,135,119,133,117,131,116,
99 127,116,125,117,123,119,122,121,121,124,121,129,122,132,123,134,125,136,127,137,
100 131,137,133,136,135,134,136,132,136,129,0,128,131,129,136,129,0,0,117,139,
101 121,116,121,137,0,128,135,116,135,137,0,128,121,126,135,126,0,0,124,132,
102 128,116,128,137,0,0,120,136,132,116,132,132,131,135,130,136,128,137,126,137,
103 124,136,123,135,122,132,122,130,0,0,117,138,121,116,121,137,0,128,135,116,
104 121,130,0,128,126,125,135,137,0,0,118,135,122,116,122,137,0,128,122,137,
105 134,137,0,0,116,140,120,116,120,137,0,128,120,116,128,137,0,128,136,116,
106 128,137,0,128,136,116,136,137,0,0,117,139,121,116,121,137,0,128,121,116,
107 135,137,0,128,135,116,135,137,0,0,117,139,126,116,124,117,122,119,121,121,
108 120,124,120,129,121,132,122,134,124,136,126,137,130,137,132,136,134,134,135,132,
109 136,129,136,124,135,121,134,119,132,117,130,116,126,116,0,0,117,138,121,116,
110 121,137,0,128,121,116,130,116,133,117,134,118,135,120,135,123,134,125,133,126,
111 130,127,121,127,0,0,117,139,126,116,124,117,122,119,121,121,120,124,120,129,
112 121,132,122,134,124,136,126,137,130,137,132,136,134,134,135,132,136,129,136,124,
113 135,121,134,119,132,117,130,116,126,116,0,128,129,133,135,139,0,0,117,138,
114 121,116,121,137,0,128,121,116,130,116,133,117,134,118,135,120,135,122,134,124,
115 133,125,130,126,121,126,0,128,128,126,135,137,0,0,118,138,135,119,133,117,
116 130,116,126,116,123,117,121,119,121,121,122,123,123,124,125,125,131,127,133,128,
117 134,129,135,131,135,134,133,136,130,137,126,137,123,136,121,134,0,0,120,136,
118 128,116,128,137,0,128,121,116,135,116,0,0,117,139,121,116,121,131,122,134,
119 124,136,127,137,129,137,132,136,134,134,135,131,135,116,0,0,119,137,120,116,
120 128,137,0,128,136,116,128,137,0,0,116,140,118,116,123,137,0,128,128,116,
121 123,137,0,128,128,116,133,137,0,128,138,116,133,137,0,0,118,138,121,116,
122 135,137,0,128,135,116,121,137,0,0,119,137,120,116,128,126,128,137,0,128,
123 136,116,128,126,0,0,118,138,135,116,121,137,0,128,121,116,135,116,0,128,
124 121,137,135,137,0,0,121,135,121,116,135,140,0,0,120,136,128,114,120,128,
125 0,128,128,114,136,128,0,0,122,134,126,116,131,122,0,128,126,116,125,117,
126 131,122,0,0,119,138,134,123,134,137,0,128,134,126,132,124,130,123,127,123,
127 125,124,123,126,122,129,122,131,123,134,125,136,127,137,130,137,132,136,134,134,
128 0,0,118,137,122,116,122,137,0,128,122,126,124,124,126,123,129,123,131,124,
129 133,126,134,129,134,131,133,134,131,136,129,137,126,137,124,136,122,134,0,0,
130 119,137,134,126,132,124,130,123,127,123,125,124,123,126,122,129,122,131,123,134,
131 125,136,127,137,130,137,132,136,134,134,0,0,119,138,134,116,134,137,0,128,
132 134,126,132,124,130,123,127,123,125,124,123,126,122,129,122,131,123,134,125,136,
133 127,137,130,137,132,136,134,134,0,0,119,137,122,129,134,129,134,127,133,125,
134 132,124,130,123,127,123,125,124,123,126,122,129,122,131,123,134,125,136,127,137,
135 130,137,132,136,134,134,0,0,123,135,133,116,131,116,129,117,128,120,128,137,
136 0,128,125,123,132,123,0,0,119,138,134,123,134,139,133,142,132,143,130,144,
137 127,144,125,143,0,128,134,126,132,124,130,123,127,123,125,124,123,126,122,129,
138 122,131,123,134,125,136,127,137,130,137,132,136,134,134,0,0,119,138,123,116,
139 123,137,0,128,123,127,126,124,128,123,131,123,133,124,134,127,134,137,0,0,
140 124,132,127,116,128,117,129,116,128,115,127,116,0,128,128,123,128,137,0,0,
141 123,133,128,116,129,117,130,116,129,115,128,116,0,128,129,123,129,140,128,143,
142 126,144,124,144,0,0,119,136,123,116,123,137,0,128,133,123,123,133,0,128,
143 127,129,134,137,0,0,124,132,128,116,128,137,0,0,113,143,117,123,117,137,
144 0,128,117,127,120,124,122,123,125,123,127,124,128,127,128,137,0,128,128,127,
145 131,124,133,123,136,123,138,124,139,127,139,137,0,0,119,138,123,123,123,137,
146 0,128,123,127,126,124,128,123,131,123,133,124,134,127,134,137,0,0,119,138,
147 127,123,125,124,123,126,122,129,122,131,123,134,125,136,127,137,130,137,132,136,
148 134,134,135,131,135,129,134,126,132,124,130,123,127,123,0,0,118,137,122,123,
149 122,144,0,128,122,126,124,124,126,123,129,123,131,124,133,126,134,129,134,131,
150 133,134,131,136,129,137,126,137,124,136,122,134,0,0,119,138,134,123,134,144,
151 0,128,134,126,132,124,130,123,127,123,125,124,123,126,122,129,122,131,123,134,
152 125,136,127,137,130,137,132,136,134,134,0,0,121,134,125,123,125,137,0,128,
153 125,129,126,126,128,124,130,123,133,123,0,0,120,137,134,126,133,124,130,123,
154 127,123,124,124,123,126,124,128,126,129,131,130,133,131,134,133,134,134,133,136,
155 130,137,127,137,124,136,123,134,0,0,123,135,128,116,128,133,129,136,131,137,
156 133,137,0,128,125,123,132,123,0,0,119,138,123,123,123,133,124,136,126,137,
157 129,137,131,136,134,133,0,128,134,123,134,137,0,0,120,136,122,123,128,137,
158 0,128,134,123,128,137,0,0,117,139,120,123,124,137,0,128,128,123,124,137,
159 0,128,128,123,132,137,0,128,136,123,132,137,0,0,120,137,123,123,134,137,
160 0,128,134,123,123,137,0,0,120,136,122,123,128,137,0,128,134,123,128,137,
161 126,141,124,143,122,144,121,144,0,0,120,137,134,123,123,137,0,128,123,123,
162 134,123,0,128,123,137,134,137,0,0,124,132,128,112,128,144,0,0};
163
164 /* external entry point */
165 /* NB this is X-specific, Y points down */
166 void draw_cgm_text(Display *inDis,  Drawable inDraw, GC inGC, 
167                    cgm_s_type *cgm_s, int inX, int inY, int inW, int inH,
168                    partialText *inText)
169 {
170   XPoint myPts[128]; /* should be plenty */
171   int offset, noPts, w1, w2, x, y, w = 0;
172   unsigned char *hPtr;
173   char *inS;
174   float charSize, cMod = 1;
175   partialText *myText;
176   int doDraw;
177   x = inX;
178   y = inY;
179   for (doDraw = 0; doDraw < 2; ++doDraw) { /* always go through twice */
180     myText = inText;
181     if (doDraw) { /* done a measurement, now about to draw */
182       if (inW && inH) { /* restricted text */
183       w = (x > inX) ? x - inX : inX - x;
184       if (w && (w > inW)) cMod = ((float) inW) / w;
185       }
186       switch (cgm_s->talign[0].i) { /* horizontal alignment */
187       default: /* don't worry about continuous horizontal for now */
188       case 0: /* normal */
189       case 1: /* left */
190         x = inX;
191         break;
192       case 2: /* centre */
193         x = inX - (int) (0.5 * (x - inX));
194           break;
195       case 3: /* right */
196         x = inX - (x - inX);
197         break;
198       } 
199     }
200     while (myText) {
201       switch (cgm_s->talign[1].i) { /* vertical alignment */
202       default: /* don't worry about continuous vertical for now */
203       case 0: /* normal */
204       case 5: /* bottom */
205         y = inY;
206         break;
207       case 1: /* top */
208         y = inY + (int) (cMod * myText->cheight);
209         break;
210       case 2: /* cap */
211         y = inY + (int) (0.9 * cMod * myText->cheight);
212           break;
213       case 3: /* half */
214         y = inY + (int) (0.5 * cMod * myText->cheight);
215         break;
216       case 4: /* base */
217         y = inY + (int) (0.1 * cMod * myText->cheight);
218         break;
219       } 
220       if (doDraw) XSetForeground(inDis, inGC, myText->tcolr);
221       inS = myText->text;
222       charSize = cMod * myText->cheight / 24.0; /* chars are in a 24 pt box */
223       while (*inS) { /* step thru the string */
224         if ((*inS < 0) || ((offset = h_array[(int)*inS]) < 0))
225           { /* illegal character */
226             ++inS; /* step over */        
227             continue; 
228           }
229         hPtr = hf_array + offset;
230         /* pick up the character widths */
231         w1 = (int) ((charSize * (128 - (int) *hPtr++)) * myText->cexpfac);
232         w2 = (int) ((charSize * ((int) *hPtr++ - 128)) * myText->cexpfac);
233         /* need to step before beginning character */
234         switch (cgm_s->tpath) {
235         default: /* shouldn't happen */
236         case 0: /* right */
237           x += w1;
238           break;
239         case 1: /* left */
240           x -= w2;
241           break;
242         case 2: /* up */
243           x = inX + w1;
244           break;
245         case 3: /* down */
246           x = inX + w1;
247           y += myText->cheight;
248           break;
249         }
250         /* now draw the character, polyline by polyline */
251         noPts = 0;
252         if (doDraw) do {
253           /* what sort of point are we at ? */
254           if (!hPtr[2 * noPts] &&
255               (!hPtr[2 * noPts + 1] || (hPtr[2 * noPts + 1] == 128))) {
256             /* either pen up or end of char description */
257             /* need to take care of points so far */
258             if (noPts) XDrawLines(inDis, inDraw, inGC, myPts, noPts,
259                                   CoordModeOrigin);
260             /* is there another segment ? */
261             if (hPtr[2 * noPts + 1]) {
262               hPtr += 2 * noPts + 2;
263               noPts = 0;
264             } else break; /* finished this char */
265           } else { /* normal point */
266             myPts[noPts].x = x +
267               (int) ((charSize * ((int) hPtr[2 * noPts] - 128))
268                 * myText->cexpfac);
269             myPts[noPts].y = y -
270               (int) (charSize * (140 - (int) hPtr[2 * noPts + 1]));
271             ++noPts;
272           }
273         } while ((hPtr + noPts * 2) <= (hf_array + MAX_OFFSET)); /* legal */
274         /* need to step for next character */
275         switch (cgm_s->tpath) {
276         default: /* shouldn't happen */
277         case 0: /* right */
278           x += w2 + myText->cspace;
279           break;
280         case 1: /* left */
281           x -= w1 + myText->cspace;
282           break;
283         case 2: /* up */
284           y -= myText->cheight;
285           break;
286         case 3: /* down */
287           break;
288         }
289         ++inS; /* next character */
290       } /* end of string */
291       myText = myText->next; 
292     } /* end of partial text */
293   } /* end of dodraw loop */
294 }