1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: metacalls.c,v 1.1 2003/02/22 02:07:26 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* metacalls.c - functional interface to metafile. |
6 |
* |
7 |
* 2/24/86 |
8 |
*/ |
9 |
|
10 |
#include "meta.h" |
11 |
|
12 |
|
13 |
#define RIGHT 0 |
14 |
#define UP 1 |
15 |
#define LEFT 2 |
16 |
#define DOWN 3 |
17 |
|
18 |
#define pflush() if (inpoly) closepoly() |
19 |
|
20 |
#define putdec(v) if (v) decival(v); else *cap++ = '0'; |
21 |
|
22 |
|
23 |
static int curx = 0; |
24 |
static int cury = 0; |
25 |
static int cura0 = 0; |
26 |
static int inpoly = FALSE; |
27 |
static char curargs[MAXARGS] = ""; |
28 |
static char *cap; |
29 |
|
30 |
|
31 |
static int let_dir( register int c); |
32 |
static void closepoly(void); |
33 |
static void polyval( register int x, register int y); |
34 |
static void decival( register int v); |
35 |
|
36 |
|
37 |
void |
38 |
mendpage(void) /* end of page */ |
39 |
{ |
40 |
pflush(); |
41 |
pglob(PEOP, 0200, NULL); |
42 |
} |
43 |
|
44 |
void |
45 |
mdone(void) /* end of graphics metafile */ |
46 |
{ |
47 |
pflush(); |
48 |
pglob(PEOF, 0200, NULL); |
49 |
} |
50 |
|
51 |
void |
52 |
minclude( /* include a file */ |
53 |
char *fname |
54 |
) |
55 |
{ |
56 |
pflush(); |
57 |
pglob(PINCL, 1, fname); |
58 |
} |
59 |
|
60 |
void |
61 |
msetpat( /* set a pattern */ |
62 |
int pn, |
63 |
char *pat |
64 |
) |
65 |
{ |
66 |
pflush(); |
67 |
pglob(PSET, pn+4, pat); |
68 |
} |
69 |
|
70 |
|
71 |
void |
72 |
mopenseg( /* open a segment */ |
73 |
char *sname |
74 |
) |
75 |
{ |
76 |
pflush(); |
77 |
pglob(POPEN, 0, sname); |
78 |
} |
79 |
|
80 |
|
81 |
void |
82 |
mcloseseg(void) /* close current segment */ |
83 |
{ |
84 |
pflush(); |
85 |
pglob(PCLOSE, 0200, NULL); |
86 |
} |
87 |
|
88 |
|
89 |
void |
90 |
mline( /* start a line */ |
91 |
int x, int y, |
92 |
int type, int thick, int color |
93 |
) |
94 |
{ |
95 |
pflush(); |
96 |
cura0 = (type<<4 & 060) | (thick<<2 & 014) | (color & 03); |
97 |
curx = x; |
98 |
cury = y; |
99 |
} |
100 |
|
101 |
|
102 |
void |
103 |
mrectangle( /* fill a rectangle */ |
104 |
int xmin, int ymin, int xmax, int ymax, |
105 |
int pat, int color |
106 |
) |
107 |
{ |
108 |
pflush(); |
109 |
cura0 = (pat<<2 & 014) | (color & 03); |
110 |
pprim(PRFILL, cura0, xmin, ymin, xmax, ymax, NULL); |
111 |
} |
112 |
|
113 |
|
114 |
void |
115 |
mtriangle( /* fill a triangle */ |
116 |
int xmin, int ymin, int xmax, int ymax, |
117 |
int d, int pat, int color |
118 |
) |
119 |
{ |
120 |
pflush(); |
121 |
cura0 = (let_dir(d)<<4 & 060) | (pat<<2 & 014) | (color & 03); |
122 |
pprim(PTFILL, cura0, xmin, ymin, xmax, ymax, NULL); |
123 |
} |
124 |
|
125 |
|
126 |
void |
127 |
mpoly( /* start a polygon */ |
128 |
int x, int y, |
129 |
int border, int pat, int color |
130 |
) |
131 |
{ |
132 |
pflush(); |
133 |
cura0 = (border<<6 & 0100) | (pat<<2 & 014) | (color & 03); |
134 |
cap = curargs; |
135 |
inpoly = TRUE; |
136 |
putdec(x); |
137 |
*cap++ = ' '; |
138 |
putdec(y); |
139 |
} |
140 |
|
141 |
|
142 |
void |
143 |
mtext( /* matrix string */ |
144 |
int x, int y, |
145 |
char *s, |
146 |
int cpi, |
147 |
int color |
148 |
) |
149 |
{ |
150 |
pflush(); |
151 |
cura0 = (color & 03); |
152 |
if (cpi < 10) { |
153 |
cura0 += 04; |
154 |
cpi *= 2; |
155 |
} |
156 |
if (cpi > 11) |
157 |
cura0 += 020; |
158 |
if (cpi > 14) |
159 |
cura0 += 020; |
160 |
if (cpi > 18) |
161 |
cura0 += 020; |
162 |
pprim(PMSTR, cura0, x, y, x, y, s); |
163 |
} |
164 |
|
165 |
|
166 |
void |
167 |
mvstr( /* vector string */ |
168 |
int xmin, int ymin, int xmax, int ymax, |
169 |
char *s, |
170 |
int d, int thick, int color |
171 |
) |
172 |
{ |
173 |
pflush(); |
174 |
cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03); |
175 |
pprim(PVSTR, cura0, xmin, ymin, xmax, ymax, s); |
176 |
} |
177 |
|
178 |
|
179 |
void |
180 |
msegment( /* segment */ |
181 |
int xmin, int ymin, int xmax, int ymax, |
182 |
char *sname, |
183 |
int d, int thick, int color |
184 |
) |
185 |
{ |
186 |
pflush(); |
187 |
cura0 = (let_dir(d)<<4 & 060) | (thick<<2 & 014) | (color & 03); |
188 |
pprim(PSEG, cura0, xmin, ymin, xmax, ymax, sname); |
189 |
} |
190 |
|
191 |
|
192 |
void |
193 |
mdraw( /* draw to next point */ |
194 |
int x, int y |
195 |
) |
196 |
{ |
197 |
if (inpoly) { |
198 |
polyval(x, y); |
199 |
} else if (x != curx || y != cury) { |
200 |
plseg(cura0, curx, cury, x, y); |
201 |
curx = x; |
202 |
cury = y; |
203 |
} |
204 |
} |
205 |
|
206 |
|
207 |
static void |
208 |
decival( /* add value to polygon */ |
209 |
register int v |
210 |
) |
211 |
{ |
212 |
if (!v) |
213 |
return; |
214 |
decival(v/10); |
215 |
*cap++ = v%10 + '0'; |
216 |
} |
217 |
|
218 |
|
219 |
static void |
220 |
polyval( /* add vertex to a polygon */ |
221 |
register int x, |
222 |
register int y |
223 |
) |
224 |
{ |
225 |
*cap++ = ' '; |
226 |
putdec(x); |
227 |
*cap++ = ' '; |
228 |
putdec(y); |
229 |
} |
230 |
|
231 |
|
232 |
static void |
233 |
closepoly(void) /* close current polygon */ |
234 |
{ |
235 |
*cap = '\0'; |
236 |
pprim(PPFILL, cura0, 0, 0, XYSIZE-1, XYSIZE-1, curargs); |
237 |
inpoly = FALSE; |
238 |
} |
239 |
|
240 |
|
241 |
static int |
242 |
let_dir( /* convert letter to corresponding direction */ |
243 |
register int c |
244 |
) |
245 |
{ |
246 |
switch (c) { |
247 |
case 'R': |
248 |
case 'r': |
249 |
return(RIGHT); |
250 |
case 'U': |
251 |
case 'u': |
252 |
return(UP); |
253 |
case 'L': |
254 |
case 'l': |
255 |
return(LEFT); |
256 |
case 'D': |
257 |
case 'd': |
258 |
return(DOWN); |
259 |
} |
260 |
return(0); |
261 |
} |