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