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