Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / corel.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: corel.trm,v 1.17 2006/07/21 02:35:45 sfeam Exp $
3  */
4
5 /*
6    corel.trm
7
8    A modified ai.trm for CorelDraw import filters
9    by Chris Parks, parks@physics.purdue.edu
10    Import from CorelDraw with the CorelTrace filter
11
12    syntax: set terminal default
13            set terminal mode "fontname" fontsize,xsize,ysize,linewidth
14
15            mode= color or monochrome             (default=mono)
16            "fontname"= postscript font name      (default="SwitzerlandLight")
17            fontsize  = size of font in points    (default=22pt)
18            xsize     = width of page in inches   (default=8.2in)
19            ysize     = height of page in inches  (default=10in)
20            linewidth = width of lines in points  (default=1.2pt)
21
22 */
23
24 /*
25  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
26  */
27
28 #include "driver.h"
29
30 #ifdef TERM_REGISTER
31 register_term(corel)
32 #endif
33
34 #ifdef TERM_PROTO
35 TERM_PUBLIC void COREL_options __PROTO((void));
36 TERM_PUBLIC void COREL_init __PROTO((void));
37 TERM_PUBLIC void COREL_graphics __PROTO((void));
38 TERM_PUBLIC void COREL_text __PROTO((void));
39 TERM_PUBLIC void COREL_reset __PROTO((void));
40 TERM_PUBLIC void COREL_linetype __PROTO((int linetype));
41 TERM_PUBLIC void COREL_move __PROTO((unsigned int x, unsigned int y));
42 TERM_PUBLIC void COREL_vector __PROTO((unsigned int x, unsigned int y));
43 TERM_PUBLIC void COREL_put_text __PROTO((unsigned int x, unsigned int y,
44                                          const char *str));
45 TERM_PUBLIC int COREL_text_angle __PROTO((int ang));
46 TERM_PUBLIC int COREL_justify_text __PROTO((enum JUSTIFY mode));
47 #define CORELD_XMAX  5960       /* 8.2 inches wide */
48 #define CORELD_YMAX  7200       /* 10 inches high  */
49 #define CORELD_VTIC  (CORELD_YMAX/80)
50 #define CORELD_HTIC  (CORELD_YMAX/80)
51 #define CORELD_VCHAR (22*COREL_SC)      /* default is 22 point characters */
52 #define CORELD_HCHAR (22*COREL_SC*6/10)
53 #endif
54
55 #ifndef TERM_PROTO_ONLY
56 #ifdef TERM_BODY
57
58 #define DEFAULT_CORELFONT "SwitzerlandLight"
59
60 /* plots for publication should be sans-serif (don't use TimesRoman) */
61 static char corel_font[MAX_ID_LEN + 1] = DEFAULT_CORELFONT;     /* name of font */
62 static int corel_fontsize = 22; /* size of font in pts */
63 static TBOOLEAN corel_color = FALSE;
64 static TBOOLEAN corel_stroke = FALSE;
65 static int corel_path_count = 0;        /* count of lines in path */
66 static int corel_ang = 0;               /* text angle */
67 static enum JUSTIFY corel_justify = LEFT;       /* text is flush left */
68
69
70 /* default mode constants */
71 #define CORELD_XOFF  0          /* page offset in pts */
72 #define CORELD_YOFF  0
73 #define COREL_SC     (10.0)     /* scale is 1pt = 10 units */
74 #define CORELD_LW    (1.2*COREL_SC)     /* linewidth = 1.2 pts */
75
76 static unsigned int corel_xmax = CORELD_XMAX;
77 static unsigned int corel_ymax = CORELD_YMAX;
78 static float corel_lw = CORELD_LW;
79
80 enum COREL_id {COREL_DEFAULT, COREL_MONOCHROME, COREL_COLOR, COREL_OTHER };
81
82 static struct gen_table COREL_opts[] =
83 {
84     { "def$ault", COREL_DEFAULT},
85     { "mono$chrome", COREL_MONOCHROME },
86     { "color$", COREL_COLOR },
87     { "colour$", COREL_COLOR },
88     { NULL, COREL_OTHER }
89 };
90
91 TERM_PUBLIC void
92 COREL_options()
93 {
94     struct value a;
95
96     while (!END_OF_COMMAND) {
97         switch(lookup_table(&COREL_opts[0],c_token)) {
98         case COREL_DEFAULT:
99             corel_color = FALSE;
100             strcpy(corel_font, DEFAULT_CORELFONT);
101             corel_fontsize = 22;
102             corel_lw = CORELD_LW;
103             corel_xmax = CORELD_XMAX;
104             corel_ymax = CORELD_YMAX;
105             c_token++;
106             break;
107         case COREL_MONOCHROME:
108             corel_color = FALSE;
109             c_token++;
110             break;
111         case COREL_COLOR:
112             corel_color = TRUE;
113             c_token++;
114             break;
115         case COREL_OTHER:
116         default:
117             /* font name */
118             if (isstring(c_token)) {
119                 quote_str(corel_font, c_token, MAX_ID_LEN);
120                 c_token++;
121             } else {
122                 /* We have font size specified */
123                 corel_fontsize = (int) real(const_express(&a));
124                 c_token++;
125                 term->v_char = (unsigned int) (corel_fontsize * COREL_SC);
126                 term->h_char = (unsigned int) (corel_fontsize * COREL_SC * 6 / 10);
127             }
128             break;
129         }
130     }
131
132     /* FIXME - argh. Stupid syntax alert here */
133     if (!END_OF_COMMAND) {
134         corel_xmax = (unsigned int) (real(const_express(&a)) * 720);
135         c_token++;
136         if (!END_OF_COMMAND) {
137             corel_ymax = (unsigned int) (real(const_express(&a)) * 720);
138             c_token++;
139         }
140         term->xmax = corel_xmax;
141         term->ymax = corel_ymax;
142         term->v_tic = corel_ymax / 80;
143         term->h_tic = corel_ymax / 80;
144     }
145     if (!END_OF_COMMAND) {
146         corel_lw = real(const_express(&a)) * COREL_SC;
147         c_token++;
148     }
149     sprintf(term_options, "%s \"%s\" %d,%0.1f,%0.1f,%0.1f",
150             corel_color ? "color" : "monochrome", corel_font,
151             corel_fontsize, corel_xmax / 720.0, corel_ymax / 720.0,
152             corel_lw / COREL_SC);
153 }
154
155 TERM_PUBLIC void
156 COREL_init()
157 {
158     fprintf(gpoutfile, "\
159 %%!PS-Adobe-2.0 EPSF-1.2\n\
160 %%%%BoundingBox: %d %d %d %d\n\
161 %%%%TemplateBox: %d %d %d %d\n\
162 %%%%EndComments\n\
163 %%%%EndProlog\n\
164 %%%%BeginSetup\n%%%%EndSetup\n",
165             CORELD_XOFF, CORELD_YOFF,
166             (int) ((corel_xmax) / COREL_SC + 0.5 + CORELD_XOFF),
167             (int) ((corel_ymax) / COREL_SC + 0.5 + CORELD_YOFF),
168             CORELD_XOFF, CORELD_YOFF,
169             (int) ((corel_xmax) / COREL_SC + 0.5 + CORELD_XOFF),
170             (int) ((corel_ymax) / COREL_SC + 0.5 + CORELD_YOFF));
171 }
172
173
174 TERM_PUBLIC void
175 COREL_graphics()
176 {
177     corel_path_count = 0;
178     corel_stroke = FALSE;
179 }
180
181
182 TERM_PUBLIC void
183 COREL_text()
184 {
185     if (corel_stroke) {
186         fputs("S\n", gpoutfile);
187         corel_stroke = FALSE;
188     }
189     corel_path_count = 0;
190 }
191
192
193 TERM_PUBLIC void
194 COREL_reset()
195 {
196     fputs("%%Trailer\n", gpoutfile);
197 }
198
199
200 TERM_PUBLIC void
201 COREL_linetype(int linetype)
202 {
203     if (corel_stroke) {
204         fputs("S\n", gpoutfile);
205         corel_stroke = FALSE;
206     }
207     switch (linetype) {
208     case LT_BLACK:
209         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
210         if (corel_color) {
211             fputs("0 0 0 1 K\n", gpoutfile);
212         } else {
213             fputs("\
214 [] 0 d\n\
215 0 j\n0 G\n", gpoutfile);
216         }
217         break;
218
219     case LT_AXIS:
220         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
221         if (corel_color) {
222             fputs("0 0 0 1 K\n", gpoutfile);
223         } else {
224             fputs("\
225 [1 2] 0 d\n\
226 0 j\n0 G\n", gpoutfile);
227         }
228         break;
229
230     case 0:
231         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
232         if (corel_color) {
233             fputs("1 0 1 0 K\n", gpoutfile);
234         } else {
235             fputs("\
236 [] 0 d\n\
237 2 j\n0 G\n", gpoutfile);
238         }
239         break;
240
241     case 1:
242         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
243         if (corel_color) {
244             fputs("1 1 0 0 K\n", gpoutfile);
245         } else {
246             fputs("\
247 [4 2] 0 d\n\
248 2 j\n0 G\n", gpoutfile);
249         }
250         break;
251
252     case 2:
253         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
254         if (corel_color) {
255             fputs("0 1 1 0 K\n", gpoutfile);
256         } else {
257             fputs("\
258 [2 3] 0 d\n\
259 2 j\n0 G\n", gpoutfile);
260         }
261         break;
262
263     case 3:
264         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
265         if (corel_color) {
266             fputs("0 1 0 0 K\n", gpoutfile);
267         } else {
268             fputs("\
269 [1 1.5] 0 d\n\
270 2 j\n0 G\n", gpoutfile);
271         }
272         break;
273
274     case 4:
275         fprintf(gpoutfile, "%f w\n", corel_lw / COREL_SC);
276         if (corel_color) {
277             fputs("1 0 0 0 K\n", gpoutfile);
278         } else {
279             fputs("\
280 [5 2 1 2] 0 d\n\
281 2 j\n0 G\n", gpoutfile);
282         }
283         break;
284
285     case 5:
286         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
287         if (corel_color) {
288             fputs("0 0 1 0 K\n", gpoutfile);
289         } else {
290             fputs("\
291 [4 3 1 3] 0 d\n\
292 2 j\n0 G\n", gpoutfile);
293         }
294         break;
295
296     case 6:
297         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
298         if (corel_color) {
299             fputs("0 0 0 1 K\n", gpoutfile);
300         } else {
301             fputs("\
302 [2 2 2 4] 0 d\n\
303 2 j\n0 G\n", gpoutfile);
304         }
305         break;
306
307     case 7:
308         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
309         if (corel_color) {
310             fputs("0 0.7 1 0 K\n", gpoutfile);
311         } else {
312             fputs("\
313 [2 2 2 2 2 4] 0 d\n\
314 2 j\n0 G\n", gpoutfile);
315         }
316         break;
317
318     case 8:
319         fprintf(gpoutfile, "%.2f w\n", corel_lw / COREL_SC);
320         if (corel_color) {
321             fputs("0.5 0.5 0.5 0 K\n", gpoutfile);
322         } else {
323             fputs("\
324 [2 2 2 2 2 2 2 4] 0 d\n\
325 2 j\n0 G\n", gpoutfile);
326         }
327         break;
328     }
329     corel_path_count = 0;
330 }
331
332
333 TERM_PUBLIC void
334 COREL_move(unsigned int x, unsigned int y)
335 {
336     if (corel_stroke)
337         fputs("S\n", gpoutfile);
338     fprintf(gpoutfile, "%0.2f %0.2f m\n", x / COREL_SC, y / COREL_SC);
339     corel_path_count += 1;
340     corel_stroke = TRUE;
341 }
342
343
344 TERM_PUBLIC void
345 COREL_vector(unsigned int x, unsigned int y)
346 {
347     fprintf(gpoutfile, "%.2f %.2f l\n", x / COREL_SC, y / COREL_SC);
348     corel_path_count += 1;
349     corel_stroke = TRUE;
350     if (corel_path_count >= 400) {
351         fprintf(gpoutfile, "S\n%.2f %.2f m\n", x / COREL_SC, y / COREL_SC);
352         corel_path_count = 0;
353     }
354 }
355
356
357 TERM_PUBLIC void
358 COREL_put_text(unsigned int x, unsigned int y, const char *str)
359 {
360     char ch;
361     if (corel_stroke) {
362         fputs("S\n", gpoutfile);
363         corel_stroke = FALSE;
364     }
365     switch (corel_justify) {
366     case LEFT:
367         fprintf(gpoutfile, "/_%s %d %d 0 0 z\n",
368                 corel_font, corel_fontsize, corel_fontsize);
369         break;
370     case CENTRE:
371         fprintf(gpoutfile, "/_%s %d %d 0 1 z\n",
372                 corel_font, corel_fontsize, corel_fontsize);
373         break;
374     case RIGHT:
375         fprintf(gpoutfile, "/_%s %d %d 0 2 z\n",
376                 corel_font, corel_fontsize, corel_fontsize);
377         break;
378     }
379     if (corel_ang == 0) {
380         fprintf(gpoutfile, "[1 0 0 1 %.2f %.2f]e\n0 g\n",
381                 x / COREL_SC, y / COREL_SC - corel_fontsize / 3.0);
382     } else {
383         fprintf(gpoutfile, "[0 1 -1 0 %.2f %.2f]e\n0 g\n",
384                 x / COREL_SC - corel_fontsize / 3.0, y / COREL_SC);
385     }
386
387     putc('(', gpoutfile);
388     ch = *str++;
389     while (ch != NUL) {
390         if ((ch == '(') || (ch == ')') || (ch == '\\'))
391             putc('\\', gpoutfile);
392         putc(ch, gpoutfile);
393         ch = *str++;
394     }
395     fputs(")t\nT\n", gpoutfile);
396     corel_path_count = 0;
397 }
398
399 TERM_PUBLIC int
400 COREL_text_angle(int ang)
401 {
402     corel_ang = ang;
403     return TRUE;
404 }
405
406 TERM_PUBLIC int
407 COREL_justify_text(enum JUSTIFY mode)
408 {
409     corel_justify = mode;
410     return TRUE;
411 }
412
413 #endif /* TERM_BODY */
414
415 #ifdef TERM_TABLE
416
417 TERM_TABLE_START(corel_driver)
418     "corel", "EPS format for CorelDRAW",
419     CORELD_XMAX, CORELD_YMAX, CORELD_VCHAR, CORELD_HCHAR,
420     CORELD_VTIC, CORELD_HTIC, COREL_options, COREL_init, COREL_reset,
421     COREL_text, null_scale, COREL_graphics, COREL_move, COREL_vector,
422     COREL_linetype, COREL_put_text, COREL_text_angle,
423     COREL_justify_text, do_point, do_arrow, set_font_null
424 TERM_TABLE_END(corel_driver)
425
426 #undef LAST_TERM
427 #define LAST_TERM corel_driver
428
429 #endif /* TERM_TABLE */
430 #endif /* TERM_PROTO_ONLY */
431
432 #ifdef TERM_HELP
433 START_HELP(corel)
434 "1 corel",
435 "?commands set terminal corel",
436 "?set terminal corel",
437 "?set term corel",
438 "?terminal corel",
439 "?term corel",
440 "?corel",
441 " The `corel` terminal driver supports CorelDraw.",
442 "",
443 " Syntax:",
444 "       set terminal corel {  default",
445 "                           | {monochrome | color",
446 "                                {\"<font>\" {<fontsize> ",
447 "                                   {<xsize> <ysize> {<linewidth> }}}}}",
448 "",
449 " where the fontsize and linewidth are specified in points and the sizes in",
450 " inches.  The defaults are monochrome, \"SwitzerlandLight\", 22, 8.2, 10 and 1.2."
451 END_HELP(corel)
452 #endif /* TERM_HELP */