1 | /*
|
---|
2 | * $Source: /tmp_mnt/n/fs/grad1/jsp/src/jgraph/RCS/printline.c,v $
|
---|
3 | * $Revision: 8.3 $
|
---|
4 | * $Date: 92/11/30 11:42:31 $
|
---|
5 | * $Author: jsp $
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "jgraph.h"
|
---|
9 | #include <stdio.h>
|
---|
10 |
|
---|
11 | #define LINEWIDTHFACTOR 0.700
|
---|
12 | #define MAX(a, b) ((a > b) ? (a) : (b))
|
---|
13 |
|
---|
14 | typedef struct fontlist {
|
---|
15 | struct fontlist *flink;
|
---|
16 | struct fontlist *blink;
|
---|
17 | int level;
|
---|
18 | float s;
|
---|
19 | char *f;
|
---|
20 | } *Fontlist;
|
---|
21 |
|
---|
22 | static Fontlist Jgraph_fonts;
|
---|
23 | static int Jgraph_gsave_level = -100;
|
---|
24 | static int Jgraph_comment;
|
---|
25 |
|
---|
26 | gsave()
|
---|
27 | {
|
---|
28 | if (Jgraph_gsave_level == -100) {
|
---|
29 | Jgraph_gsave_level = 0;
|
---|
30 | Jgraph_fonts = (Fontlist) make_list(sizeof(struct fontlist));
|
---|
31 | }
|
---|
32 | Jgraph_gsave_level++;
|
---|
33 | printf(" gsave ");
|
---|
34 | }
|
---|
35 |
|
---|
36 | grestore()
|
---|
37 | {
|
---|
38 | Fontlist l;
|
---|
39 |
|
---|
40 | if (last(Jgraph_fonts) != nil(Jgraph_fonts)) {
|
---|
41 | l = last(Jgraph_fonts);
|
---|
42 | if (l->level == Jgraph_gsave_level) {
|
---|
43 | delete_item(l);
|
---|
44 | free_node(l, Jgraph_fonts);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | Jgraph_gsave_level--;
|
---|
48 | printf(" grestore ");
|
---|
49 | }
|
---|
50 |
|
---|
51 | setfont(f, s)
|
---|
52 | char *f;
|
---|
53 | float s;
|
---|
54 | {
|
---|
55 | Fontlist l;
|
---|
56 | int ins;
|
---|
57 |
|
---|
58 | if (last(Jgraph_fonts) != nil(Jgraph_fonts)) {
|
---|
59 | l = last(Jgraph_fonts);
|
---|
60 | ins = (strcmp(l->f, f) != 0 || s != l->s);
|
---|
61 | if (ins) {
|
---|
62 | delete_item(l);
|
---|
63 | free_node(l, Jgraph_fonts);
|
---|
64 | }
|
---|
65 | } else {
|
---|
66 | ins = 1;
|
---|
67 | }
|
---|
68 | if (ins) {
|
---|
69 | l = (Fontlist) get_node(Jgraph_fonts);
|
---|
70 | l->level = Jgraph_gsave_level;
|
---|
71 | l->s = s;
|
---|
72 | l->f = f;
|
---|
73 | insert(l, Jgraph_fonts);
|
---|
74 | printf("/%s findfont %f scalefont setfont\n", f, s);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | setfill( x, y, t, f, p, a)
|
---|
79 | char t, p ;
|
---|
80 | float x, y;
|
---|
81 | float f[], a ;
|
---|
82 | {
|
---|
83 | /* fprintf(stderr, "Hello? %c %f %c %f\n", t, f[0], p, a); */
|
---|
84 | if (t == 'g' && f[0] < 0.0) return;
|
---|
85 | printf("gsave ");
|
---|
86 |
|
---|
87 | if ( t == 'g' ) {
|
---|
88 | if( f[0] >= 0.0 ) printf("%f setgray ", f[0] );
|
---|
89 | } else if ( t == 'c' ) {
|
---|
90 | printf("%f %f %f setrgbcolor ", f[0], f[1], f[2] );
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (p == 's') {
|
---|
94 | printf(" fill");
|
---|
95 | } else if (p == '/') {
|
---|
96 | printf(" 6.1 10 %f %f %f 1 JSTR", a, x, y);
|
---|
97 | } else if (p == 'e') {
|
---|
98 | printf(" 6.1 10 %f %f %f 0 JSTR", a, x, y);
|
---|
99 | }
|
---|
100 | printf(" grestore\n");
|
---|
101 | }
|
---|
102 |
|
---|
103 | setgray( t, f)
|
---|
104 | char t ;
|
---|
105 | float f[] ;
|
---|
106 | {
|
---|
107 | if ( t == 'g' ) {
|
---|
108 | if( f[0] >= 0.0 ) printf("%f setgray\n", f[0] );
|
---|
109 | } else if ( t == 'c' ) {
|
---|
110 | printf("%f %f %f setrgbcolor\n", f[0], f[1], f[2] );
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | printline(x1, y1,x2, y2, orientation)
|
---|
115 | float x1, y1, x2, y2;
|
---|
116 | char orientation;
|
---|
117 | {
|
---|
118 | if (orientation == 'x')
|
---|
119 | printf("newpath %f %f moveto %f %f lineto stroke\n", x1, y1, x2, y2);
|
---|
120 | else
|
---|
121 | printf("newpath %f %f moveto %f %f lineto stroke\n", y1, x1, y2, x2);
|
---|
122 | fflush(stdout);
|
---|
123 | }
|
---|
124 |
|
---|
125 | print_ebar(x1, y1, x2, ms, orientation)
|
---|
126 | float x1, y1, x2, ms;
|
---|
127 | char orientation;
|
---|
128 | {
|
---|
129 | printline(x1, y1, x2, y1, orientation);
|
---|
130 | printline(x2, y1-ms, x2, y1+ms, orientation);
|
---|
131 | }
|
---|
132 |
|
---|
133 | start_line(x1, y1, c)
|
---|
134 | float x1, y1;
|
---|
135 | Curve c;
|
---|
136 | {
|
---|
137 | setlinewidth(c->linethick);
|
---|
138 | setlinestyle(c->linetype, c->gen_linetype);
|
---|
139 | printf("%f %f moveto ", x1, y1);
|
---|
140 | }
|
---|
141 |
|
---|
142 | cont_line(x1, y1)
|
---|
143 | float x1, y1;
|
---|
144 | {
|
---|
145 | printf(" %f %f lineto\n", x1, y1);
|
---|
146 | }
|
---|
147 |
|
---|
148 | end_line()
|
---|
149 | {
|
---|
150 | printf("stroke\n");
|
---|
151 | setlinewidth(1.0);
|
---|
152 | setlinestyle('s', (Flist) 0);
|
---|
153 | fflush(stdout);
|
---|
154 |
|
---|
155 | }
|
---|
156 |
|
---|
157 | bezier_control(x1, y1)
|
---|
158 | float x1, y1;
|
---|
159 | {
|
---|
160 | printf(" %f %f ", x1, y1);
|
---|
161 | }
|
---|
162 |
|
---|
163 | bezier_end(x1, y1)
|
---|
164 | float x1, y1;
|
---|
165 | {
|
---|
166 | printf(" %f %f curveto\n", x1, y1);
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | start_poly(x1, y1)
|
---|
171 | float x1, y1;
|
---|
172 | {
|
---|
173 | printf(" newpath %f %f moveto", x1, y1);
|
---|
174 | }
|
---|
175 |
|
---|
176 | cont_poly(x1, y1)
|
---|
177 | float x1, y1;
|
---|
178 | {
|
---|
179 | printf(" %f %f lineto\n", x1, y1);
|
---|
180 | }
|
---|
181 |
|
---|
182 | end_poly(x, y, ftype, fill, pattern, parg)
|
---|
183 | float x, y;
|
---|
184 | char ftype, pattern ;
|
---|
185 | float fill[], parg;
|
---|
186 | {
|
---|
187 | printf("closepath ");
|
---|
188 | setfill( x, y, ftype, fill, pattern, parg );
|
---|
189 | printf("stroke\n");
|
---|
190 | fflush(stdout);
|
---|
191 | }
|
---|
192 |
|
---|
193 | /* Ellipse at 0, 0 -- assumes that you've already translated to x, y */
|
---|
194 |
|
---|
195 | printellipse(x, y, radius1, radius2, ftype, fill, pattern, parg)
|
---|
196 | char ftype, pattern;
|
---|
197 | float x, y, radius1, radius2, fill[], parg;
|
---|
198 | {
|
---|
199 | printf("newpath %f %f JDE\n", radius1, radius2);
|
---|
200 | setfill( x, y, ftype, fill, pattern, parg );
|
---|
201 | printf("stroke\n");
|
---|
202 | fflush(stdout);
|
---|
203 | }
|
---|
204 |
|
---|
205 | set_comment(c)
|
---|
206 | int c;
|
---|
207 | {
|
---|
208 | Jgraph_comment = c;
|
---|
209 | }
|
---|
210 |
|
---|
211 | comment(s)
|
---|
212 | char *s;
|
---|
213 | {
|
---|
214 | if (Jgraph_comment) printf("%% %s\n", s);
|
---|
215 | }
|
---|
216 |
|
---|
217 | printline_c(x1, y1, x2, y2, g)
|
---|
218 | float x1, y1, x2, y2;
|
---|
219 | Graph g;
|
---|
220 | {
|
---|
221 | printline(ctop(x1, g->x_axis), ctop(y1, g->y_axis),
|
---|
222 | ctop(x2, g->x_axis), ctop(y2, g->y_axis), 'x');
|
---|
223 | }
|
---|
224 |
|
---|
225 | print_label(l)
|
---|
226 | Label l;
|
---|
227 | {
|
---|
228 | int f, i, nlines;
|
---|
229 | float fnl;
|
---|
230 | char *s;
|
---|
231 |
|
---|
232 | if (l->label == CNULL) return;
|
---|
233 |
|
---|
234 | nlines = 0;
|
---|
235 | for (i = 0; l->label[i] != '\0'; i++) {
|
---|
236 | if (l->label[i] == '\n') {
|
---|
237 | l->label[i] = '\0';
|
---|
238 | nlines++;
|
---|
239 | }
|
---|
240 | }
|
---|
241 | fnl = (float) nlines;
|
---|
242 |
|
---|
243 | setfont(l->font, l->fontsize);
|
---|
244 | printf("gsave %f %f translate %f rotate\n", l->x, l->y, l->rotate);
|
---|
245 | if (l->graytype == 'g') {
|
---|
246 | printf(" %f setgray\n", l->gray[0]);
|
---|
247 | } else if (l->graytype == 'c') {
|
---|
248 | printf(" %f %f %f setrgbcolor\n", l->gray[0], l->gray[1],
|
---|
249 | l->gray[2]);
|
---|
250 | }
|
---|
251 |
|
---|
252 | if (l->vj == 'b') {
|
---|
253 | printf("0 %f translate ", fnl * (l->fontsize + l->linesep) * FCPI / FPPI);
|
---|
254 | } else if (l->vj == 'c') {
|
---|
255 | if (nlines % 2 == 0) {
|
---|
256 | printf("0 %f translate ",
|
---|
257 | (fnl/2.0*(l->fontsize + l->linesep) - l->fontsize/2.0)
|
---|
258 | * FCPI / FPPI);
|
---|
259 | } else {
|
---|
260 | printf("0 %f translate ",
|
---|
261 | ((fnl-1.0)/2.0*(l->fontsize + l->linesep) + l->linesep/2.0)
|
---|
262 | * FCPI / FPPI);
|
---|
263 | }
|
---|
264 | } else {
|
---|
265 | printf("0 %f translate ", -l->fontsize * FCPI / FPPI);
|
---|
266 | }
|
---|
267 |
|
---|
268 | s = l->label;
|
---|
269 | for (i = 0; i <= nlines; i++) {
|
---|
270 | printf("(%s) dup stringwidth pop ", s);
|
---|
271 | if (l->hj == 'c') {
|
---|
272 | printf("2 div neg 0 moveto\n");
|
---|
273 | } else if (l->hj == 'r') {
|
---|
274 | printf("neg 0 moveto\n");
|
---|
275 | } else {
|
---|
276 | printf("pop 0 0 moveto\n");
|
---|
277 | }
|
---|
278 | /* I would put string blanking in here if I had the time... */
|
---|
279 |
|
---|
280 | if (i != nlines) {
|
---|
281 | f = strlen(s);
|
---|
282 | s[f] = '\n';
|
---|
283 | s = &(s[f+1]);
|
---|
284 | printf("show 0 %f translate\n",
|
---|
285 | - (l->fontsize + l->linesep) * FCPI / FPPI);
|
---|
286 | } else {
|
---|
287 | printf("show\n");
|
---|
288 | }
|
---|
289 | }
|
---|
290 | printf("grestore\n");
|
---|
291 | }
|
---|
292 |
|
---|
293 | setlinewidth(size)
|
---|
294 | float size;
|
---|
295 | {
|
---|
296 | printf("%f setlinewidth ", size * LINEWIDTHFACTOR);
|
---|
297 | }
|
---|
298 |
|
---|
299 | setlinestyle(style, glist)
|
---|
300 | char style;
|
---|
301 | Flist glist;
|
---|
302 | {
|
---|
303 | Flist fl;
|
---|
304 |
|
---|
305 | switch(style) {
|
---|
306 | case '0': printf(" [0 2] setdash\n"); break;
|
---|
307 | case 's': printf(" [] 0 setdash\n"); break;
|
---|
308 | case '.': printf(" [1 3.200000] 0 setdash\n"); break;
|
---|
309 | case '-': printf(" [4.00000] 0 setdash\n"); break;
|
---|
310 | case 'l': printf(" [7 2] 0 setdash\n"); break;
|
---|
311 | case 'd': printf(" [5 3 1 3] 0 setdash\n"); break;
|
---|
312 | case 'D': printf(" [5 3 1 2 1 3] 0 setdash\n"); break;
|
---|
313 | case '2': printf(" [5 3 5 3 1 2 1 3] 0 setdash\n"); break;
|
---|
314 | case 'g':
|
---|
315 | printf(" [");
|
---|
316 | for (fl = first(glist); fl != nil(glist); fl = next(fl))
|
---|
317 | printf("%f ", fl->f);
|
---|
318 | printf("] 0 setdash\n");
|
---|
319 | break;
|
---|
320 | default: fprintf(stderr, "Error: Unknown line type: %c\n", style);
|
---|
321 | exit(1);
|
---|
322 | break;
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|