1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#endif |
4 |
/* |
5 |
* Impress plotting functions |
6 |
* |
7 |
* 1/2/86 |
8 |
*/ |
9 |
|
10 |
|
11 |
#include "meta.h" |
12 |
|
13 |
#include "plot.h" |
14 |
|
15 |
#include "imPfuncs.h" |
16 |
|
17 |
#include "imPcodes.h" |
18 |
|
19 |
#include <ctype.h> |
20 |
|
21 |
|
22 |
#define mapx(x) CONV(x,dxsize) |
23 |
#define mapy(y) CONV(y,dysize) |
24 |
|
25 |
#define DPI 296 /* dots per inch for imagen */ |
26 |
|
27 |
#define TexFamily 90 /* family for texture glyphs */ |
28 |
|
29 |
/* operation codes for graphics */ |
30 |
#define whiteOp 0 |
31 |
#define shadeOp 3 |
32 |
#define orOp 7 |
33 |
#define blackOp 15 |
34 |
|
35 |
/* imagen resident fonts */ |
36 |
static struct { |
37 |
char *name; /* font name */ |
38 |
int iwspace; /* interword spacing */ |
39 |
short loaded; /* boolean true if font loaded */ |
40 |
} font[] = { |
41 |
{"cour07", 21, FALSE}, |
42 |
{"cour08", 24, FALSE}, |
43 |
{"cour10", 30, FALSE}, |
44 |
{"cour12", 36, FALSE}, |
45 |
{"cour14", 42, FALSE}, |
46 |
{"zurm20", 60, FALSE} |
47 |
}; |
48 |
|
49 |
/* map from our matrix string types */ |
50 |
static int fontmap[16] = {3,4,4,5,2,4,4,5,1,2,2,3,0,2,2,3}; |
51 |
|
52 |
int dxsize, dysize; /* page size */ |
53 |
|
54 |
|
55 |
|
56 |
imInit() /* initialize imagen */ |
57 |
{ |
58 |
|
59 |
imout = stdout; |
60 |
|
61 |
fputs("@document(language imPress)", imout); |
62 |
fputs("@document(pagereversal off)", imout); |
63 |
|
64 |
imSetPum(0); /* new path deletes old one */ |
65 |
dxsize = dysize = 8 * DPI; /* square on 8.5 X 11 in. paper */ |
66 |
imSetAbsH(DPI/4); /* .25 in. on left and right */ |
67 |
imSetAbsV(dysize); |
68 |
imSetHVSystem(3, 3, 4); /* conventional orientation */ |
69 |
|
70 |
} |
71 |
|
72 |
|
73 |
|
74 |
printstr(p) /* output a string */ |
75 |
|
76 |
register PRIMITIVE *p; |
77 |
|
78 |
{ |
79 |
static int curfont = -1; |
80 |
int fn; |
81 |
register char *cp; |
82 |
|
83 |
fn = fontmap[(p->arg0 >> 2) & 017]; /* get font number */ |
84 |
/* set font */ |
85 |
if (fn != curfont) { |
86 |
imSetFamily(fn); |
87 |
if (!font[fn].loaded) { |
88 |
imCreateFamilyTable(fn, 1, 0, font[fn].name); |
89 |
font[fn].loaded = TRUE; |
90 |
} |
91 |
imSetSp(font[fn].iwspace); |
92 |
curfont = fn; |
93 |
} |
94 |
|
95 |
imSetAbsH(mapx(p->xy[XMN])); /* set page position */ |
96 |
imSetAbsV(mapy(p->xy[YMN])); |
97 |
|
98 |
for (cp = p->args; *cp; cp++) /* write out the string */ |
99 |
if (isspace(*cp)) |
100 |
imSp(); |
101 |
else |
102 |
im_putbyte(*cp); |
103 |
|
104 |
} |
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
plotlseg(p) /* plot a line segment */ |
111 |
|
112 |
register PRIMITIVE *p; |
113 |
|
114 |
{ |
115 |
int x1, x2, y1, y2; |
116 |
short pp; |
117 |
|
118 |
pp = (p->arg0 >> 4) & 03; |
119 |
if (p->arg0 & 0100 && pp != 0) |
120 |
pp += 03; |
121 |
settex(pp); |
122 |
|
123 |
setpen((p->arg0 >> 2) & 03); |
124 |
|
125 |
x1 = mapx(p->xy[XMN]); |
126 |
x2 = mapx(p->xy[XMX]); |
127 |
|
128 |
if (p->arg0 & 0100) { |
129 |
y1 = mapy(p->xy[YMX]); |
130 |
y2 = mapy(p->xy[YMN]); |
131 |
} else { |
132 |
y1 = mapy(p->xy[YMN]); |
133 |
y2 = mapy(p->xy[YMX]); |
134 |
} |
135 |
|
136 |
imCreatePath(2, x1, y1, x2, y2); |
137 |
imDrawPath(orOp); |
138 |
|
139 |
} |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
setfill(a0) /* set filling mode */ |
145 |
|
146 |
register int a0; |
147 |
|
148 |
{ |
149 |
|
150 |
settex(pati[(a0 >> 2) & 03]); |
151 |
|
152 |
} |
153 |
|
154 |
|
155 |
|
156 |
setpen(ps) /* set pen size to ps */ |
157 |
|
158 |
register int ps; |
159 |
|
160 |
{ |
161 |
static int curpsiz = -1; /* current pen size */ |
162 |
|
163 |
if (ps == curpsiz) |
164 |
return; |
165 |
|
166 |
curpsiz = ps; |
167 |
ps = WIDTH(ps); |
168 |
ps = CONV(ps, dxsize); |
169 |
if (ps < 2) |
170 |
ps = 2; |
171 |
else if (ps > 20) |
172 |
ps = 20; |
173 |
imSetPen(ps); |
174 |
|
175 |
} |
176 |
|
177 |
|
178 |
|
179 |
settex(pp) /* set texture pattern to pp */ |
180 |
|
181 |
int pp; |
182 |
|
183 |
{ |
184 |
static int curtex = -1; /* current texture */ |
185 |
static short ploaded[NPATS]; /* booleans for loaded patterns */ |
186 |
char span[4]; |
187 |
int i, k; |
188 |
register int j; |
189 |
|
190 |
if (pp == curtex) /* already set */ |
191 |
return; |
192 |
|
193 |
if (pp == 0) { /* all black */ |
194 |
imSetTexture(0, 0); /* special case */ |
195 |
curtex = 0; |
196 |
return; |
197 |
} |
198 |
|
199 |
if (pp >= NPATS || !ploaded[pp]) { /* download texture glyph */ |
200 |
im_77(imP_BGLY, TexFamily, pp); /* family and member */ |
201 |
im_putword(32); /* advance-width */ |
202 |
im_putword(32); /* width */ |
203 |
im_putword(0); /* left-offset */ |
204 |
im_putword(32); /* height */ |
205 |
im_putword(0); /* top-offset */ |
206 |
for (i = PATSIZE-1; i >= 0; i--) { |
207 |
for (j = 0; j < 4; j++) |
208 |
span[j] = 0; |
209 |
for (j = 0; j < 32; j++) |
210 |
span[j>>3] |= ((pattern[pp][i>>3][j/(32/PATSIZE)] |
211 |
>> (i&07)) & 01) << (7-(j&07)); |
212 |
for (k = 0; k < 32/PATSIZE; k++) |
213 |
for (j = 0; j < 4; j++) |
214 |
im_putbyte(span[j]); |
215 |
} |
216 |
if (pp < NPATS) |
217 |
ploaded[pp]++; |
218 |
} |
219 |
imSetTexture(TexFamily, pp); |
220 |
curtex = pp; |
221 |
|
222 |
} |
223 |
|
224 |
|
225 |
|
226 |
fillrect(p) /* fill a rectangle */ |
227 |
|
228 |
register PRIMITIVE *p; |
229 |
|
230 |
{ |
231 |
int left, right, top, bottom; |
232 |
|
233 |
left = mapx(p->xy[XMN]); |
234 |
right = mapx(p->xy[XMX]); |
235 |
top = mapy(p->xy[YMX]); |
236 |
bottom = mapy(p->xy[YMN]); |
237 |
|
238 |
setfill(p->arg0); |
239 |
imCreatePath(4, left, bottom, right, bottom, right, top, left, top); |
240 |
imFillPath(orOp); |
241 |
|
242 |
} |
243 |
|
244 |
|
245 |
|
246 |
filltri(p) /* fill a triangle */ |
247 |
|
248 |
register PRIMITIVE *p; |
249 |
|
250 |
{ |
251 |
int left, right, top, bottom; |
252 |
|
253 |
left = mapx(p->xy[XMN]); |
254 |
right = mapx(p->xy[XMX]); |
255 |
top = mapy(p->xy[YMX]); |
256 |
bottom = mapy(p->xy[YMN]); |
257 |
|
258 |
setfill(p->arg0); |
259 |
|
260 |
switch (p->arg0 & 060) { |
261 |
case 0: /* right (& down) */ |
262 |
imCreatePath(3, left, bottom, right, bottom, right, top); |
263 |
break; |
264 |
case 020: /* up */ |
265 |
imCreatePath(3, right, bottom, right, top, left, top); |
266 |
break; |
267 |
case 040: /* left */ |
268 |
imCreatePath(3, right, top, left, top, left, bottom); |
269 |
break; |
270 |
case 060: /* down */ |
271 |
imCreatePath(3, left, top, left, bottom, right, bottom); |
272 |
break; |
273 |
} |
274 |
|
275 |
imFillPath(orOp); |
276 |
|
277 |
} |
278 |
|
279 |
|
280 |
|
281 |
|
282 |
xform(xp, yp, p) /* transform a point according to p */ |
283 |
|
284 |
register int *xp, *yp; |
285 |
register PRIMITIVE *p; |
286 |
|
287 |
{ |
288 |
int x, y; |
289 |
|
290 |
switch (p->arg0 & 060) { |
291 |
case 0: /* right */ |
292 |
x = *xp; |
293 |
y = *yp; |
294 |
break; |
295 |
case 020: /* up */ |
296 |
x = (XYSIZE-1) - *yp; |
297 |
y = *xp; |
298 |
break; |
299 |
case 040: /* left */ |
300 |
x = (XYSIZE-1) - *xp; |
301 |
y = (XYSIZE-1) - *yp; |
302 |
break; |
303 |
case 060: /* down */ |
304 |
x = *yp; |
305 |
y = (XYSIZE-1) - *xp; |
306 |
break; |
307 |
} |
308 |
|
309 |
*xp = CONV(x, p->xy[XMX] - p->xy[XMN]) + p->xy[XMN]; |
310 |
*yp = CONV(y, p->xy[YMX] - p->xy[YMN]) + p->xy[YMN]; |
311 |
|
312 |
} |
313 |
|
314 |
|
315 |
|
316 |
fillpoly(p) /* fill a polygon */ |
317 |
|
318 |
register PRIMITIVE *p; |
319 |
|
320 |
{ |
321 |
int points[128]; |
322 |
register int *pp; |
323 |
char *nextscan(); |
324 |
register char *s; |
325 |
|
326 |
pp = points; |
327 |
|
328 |
if ((s = nextscan(nextscan(p->args, "%d", pp), "%d", pp+1)) == NULL) |
329 |
error(USER, "illegal polygon spec in fillpoly"); |
330 |
|
331 |
xform(pp, pp+1, p); |
332 |
pp[0] = mapx(pp[0]); pp[1] = mapy(pp[1]); |
333 |
pp += 2; |
334 |
|
335 |
while ((s = nextscan(nextscan(s, "%d", pp), "%d", pp+1)) != NULL) { |
336 |
xform(pp, pp+1, p); |
337 |
pp[0] = mapx(pp[0]); pp[1] = mapy(pp[1]); |
338 |
pp += 2; |
339 |
} |
340 |
pp[0] = points[0]; pp[1] = points[1]; |
341 |
pp += 2; |
342 |
|
343 |
settex(p->arg0 & 077); |
344 |
imCreatePathV((pp-points)/2, points); |
345 |
imFillPath(orOp); |
346 |
|
347 |
if (p->arg0 & 0100) { /* draw border */ |
348 |
settex(0); |
349 |
setpen(0); |
350 |
imDrawPath(orOp); |
351 |
} |
352 |
|
353 |
} |