1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: ai.trm,v 1.21 2006/07/29 22:35:43 tlecomte Exp $
9 * Copyright 1991, 1992, 1993, 1998, 2004
11 * Permission to use, copy, and distribute this software and its
12 * documentation for any purpose with or without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and
14 * that both that copyright notice and this permission notice appear
15 * in supporting documentation.
17 * Permission to modify the software is granted, but not the right to
18 * distribute the complete modified source code. Modifications are to
19 * be distributed as patches to the released version. Permission to
20 * distribute binaries produced by compiling modified sources is granted,
22 * 1. distribute the corresponding source modifications from the
23 * released version in the form of a patch file along with the binaries,
24 * 2. add special version identification to distinguish your version
25 * in addition to the base release version number,
26 * 3. provide your name and address as the primary contact for the
27 * support of your modified version, and
28 * 4. retain our contact information in regard to use of the base
30 * Permission to distribute the released version of the source code along
31 * with corresponding source modifications in the form of a patch file is
32 * granted with same provisions 2 through 4 for binary distributions.
34 * This software is provided "as is" without express or implied warranty
35 * to the extent permitted by applicable law.
39 * This file is included by ../term.c.
41 * This terminal driver supports:
47 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
49 * The 'aifm' driver produces files editable by Adobe Illustrator 3.0
50 * To change font to Courier and font size to 20pts use
51 * 'set term aifm "Courier" 20'.
52 * To switch to color output use
53 * 'set term aifm color'.
56 /* AIFM driver by Ray Ghanbari, ray@mtl.mit.edu,
57 * based on PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
59 /* Changed to 3.6 terminal format, David C. Schooley, 9/29/95 */
60 /* Improved multiple plot support, David C. Schooley, 6/5/95 */
61 /* Compatiblity with Illustrator 7.0, David C. Schooley, 6/5/95 */
62 /* Font and size support for labels, David C. Schooley, 6/5/95 */
71 TERM_PUBLIC void AI_init __PROTO((void));
72 TERM_PUBLIC void AI_graphics __PROTO((void));
73 TERM_PUBLIC void AI_text __PROTO((void));
74 TERM_PUBLIC void AI_linetype __PROTO((int linetype));
75 TERM_PUBLIC void AI_move __PROTO((unsigned int x, unsigned int y));
76 TERM_PUBLIC void AI_vector __PROTO((unsigned int x, unsigned int y));
77 TERM_PUBLIC void AI_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
78 TERM_PUBLIC int AI_text_angle __PROTO((int ang));
79 TERM_PUBLIC void AI_reset __PROTO((void));
80 TERM_PUBLIC void AI_options __PROTO((void));
81 TERM_PUBLIC int AI_justify_text __PROTO((enum JUSTIFY mode));
82 TERM_PUBLIC void AI_suspend __PROTO((void));
83 TERM_PUBLIC void AI_resume __PROTO((void));
84 TERM_PUBLIC int AI_set_font __PROTO((const char *font));
86 #define AI_XOFF 50 /* page offset in pts */
92 #define AI_XLAST (AI_XMAX - 1)
93 #define AI_YLAST (AI_YMAX - 1)
95 #define AI_VTIC (AI_YMAX/80)
96 #define AI_HTIC (AI_YMAX/80)
98 #define AI_SC (10.0) /* scale is 1pt = 10 units */
99 #define AI_LW (0.5*AI_SC) /* linewidth = 0.5 pts */
101 #define AI_VCHAR (14*AI_SC) /* default is 14 point characters */
102 #define AI_HCHAR (14*AI_SC*6/10)
104 #endif /* TERM_PROTO */
107 #ifndef TERM_PROTO_ONLY
110 enum AI_id { AI_DEFAULT, AI_MONOCHROME, AI_COLOUR, AI_OTHER };
112 static struct gen_table AI_opts[] =
114 { "d$efault", AI_DEFAULT },
115 { "m$onochrome", AI_MONOCHROME },
116 { "c$olor", AI_COLOUR },
117 { "c$olour", AI_COLOUR },
121 #define DEFAULT_FONT "Times-Roman"
124 static char ai_font[MAX_ID_LEN + 1] = DEFAULT_FONT;
126 /* size of font in pts */
127 static int ai_fontsize = 14;
130 static char ai_oldfont[MAX_ID_LEN + 1] = DEFAULT_FONT;
132 /* size of font in pts */
133 static int ai_oldfontsize = 14;
135 static TBOOLEAN ai_color = FALSE;
136 static TBOOLEAN ai_stroke = FALSE;
137 static int ai_page = 0; /* page count */
138 static int ai_path_count = 0; /* count of lines in path */
139 static int ai_ang = 0; /* text angle */
140 static int ai_subgroup_level = 0; /* depth of sub-groups */
141 static int ai_multiplot_group = 0; /* group for multiplot */
142 static enum JUSTIFY ai_justify = LEFT; /* text is flush left */
148 while (!END_OF_COMMAND) {
149 switch(lookup_table(&AI_opts[0],c_token)) {
153 strncpy(ai_font,DEFAULT_FONT,sizeof(ai_font));
155 strncpy(ai_oldfont,DEFAULT_FONT,sizeof(ai_oldfont));
168 if (isstring(c_token)) {
169 quote_str(ai_font, c_token, MAX_ID_LEN);
170 strcpy(ai_oldfont, ai_font);
172 } else { /* is a number */
173 /* We have font size specified */
175 ai_fontsize = (int) real(const_express(&a));
176 ai_oldfontsize = ai_fontsize;
177 term->v_char = (unsigned int) (ai_fontsize * AI_SC);
178 term->h_char = (unsigned int) (ai_fontsize * AI_SC * 6 / 10);
184 sprintf(term_options, "%s \"%s\" %d",
185 ai_color ? "color" : "monochrome", ai_font, ai_fontsize);
194 fprintf(gpoutfile, "%%!PS-Adobe-2.0 EPSF-1.2\n\
195 %%%%Creator: Adobe Illustrator(TM) 3.2\n\
196 %%%%TrueCreator: gnuplot %s patchlevel %s ai terminal\n\
197 %%%%BoundingBox: %d %d %d %d\n\
201 gnuplot_version, gnuplot_patchlevel,
203 (int) ((AI_XMAX) / AI_SC + 0.5 + AI_XOFF),
204 (int) ((AI_YMAX) / AI_SC + 0.5 + AI_YOFF));
212 /* fprintf(gpoutfile,"%%%%Page: %d %d\n",ai_page,ai_page);*/
227 fputs("S\n", gpoutfile);
230 while (ai_subgroup_level) {
231 fputs("U\n", gpoutfile);
234 fputs("U\n", gpoutfile);
236 ai_multiplot_group = 0;
243 fputs("%%Trailer\n", gpoutfile);
244 /* fprintf(gpoutfile,"%%%%Pages: %d\n",ai_page);*/
249 AI_linetype(int linetype)
252 fputs("S\n", gpoutfile);
255 if (ai_subgroup_level) {
256 fputs("U\n", gpoutfile);
259 if (linetype == LT_BLACK && multiplot) {
260 /* for each new plot, line_type gets called twice with a value of LT_BLACK.
261 It gets called once for the border and again for the tics.
262 This code will need to be changed if gnuplot's behavior changes.
264 switch (ai_multiplot_group) {
266 fputs("u\n", gpoutfile);
268 ai_multiplot_group = 1;
271 ai_multiplot_group = 2;
274 ai_multiplot_group = 1;
275 fputs("U\nu\n", gpoutfile);
279 if (linetype == LT_BLACK && !multiplot) {
280 if (ai_multiplot_group) {
281 fputs("U\n", gpoutfile);
283 ai_multiplot_group = 0;
286 fputs("u\n", gpoutfile);
291 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC * 2.0);
293 fputs("0 0 0 1 K\n", gpoutfile);
295 fputs("[] 0 d\n", gpoutfile);
300 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC / 2.0);
302 fputs("0 0 0 1 K\n", gpoutfile);
304 fputs("[1 2] 0 d\n", gpoutfile);
309 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
311 fputs("1 0 1 0 K\n", gpoutfile);
313 fputs("[] 0 d\n", gpoutfile);
318 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
320 fputs("1 1 0 0 K\n", gpoutfile);
322 fputs("[4 2] 0 d\n", gpoutfile);
327 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
329 fputs("0 1 1 0 K\n", gpoutfile);
331 fputs("[2 3] 0 d\n", gpoutfile);
336 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
338 fputs("0 1 0 0 K\n", gpoutfile);
340 fputs("[1 1.5] 0 d\n", gpoutfile);
345 fprintf(gpoutfile, "%f w\n", AI_LW / AI_SC);
347 fputs("1 0 0 0 K\n", gpoutfile);
349 fputs("[5 2 1 2] 0 d\n", gpoutfile);
354 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
356 fputs("0 0 1 0 K\n", gpoutfile);
358 fputs("[4 3 1 3] 0 d\n", gpoutfile);
363 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
365 fputs("0 0 0 1 K\n", gpoutfile);
367 fputs("[2 2 2 4] 0 d\n", gpoutfile);
372 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
374 fputs("0 0.7 1 0 K\n", gpoutfile);
376 fputs("[2 2 2 2 2 4] 0 d\n", gpoutfile);
381 fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
383 fputs("0.5 0.5 0.5 0 K\n", gpoutfile);
385 fputs("[2 2 2 2 2 2 2 4] 0 d\n", gpoutfile);
395 AI_move(unsigned int x, unsigned int y)
398 fputs("S\n", gpoutfile);
399 fprintf(gpoutfile, "%.2f %.2f m\n", x / AI_SC, y / AI_SC);
406 AI_vector(unsigned int x, unsigned int y)
408 fprintf(gpoutfile, "%.2f %.2f l\n", x / AI_SC, y / AI_SC);
411 if (ai_path_count >= 400) {
412 fprintf(gpoutfile, "S\n%.2f %.2f m\n", x / AI_SC, y / AI_SC);
419 AI_put_text(unsigned int x, unsigned int y, const char *str)
423 fputs("S\n", gpoutfile);
426 switch (ai_justify) {
428 fprintf(gpoutfile, "/_%s %d 0 0 0 z\n", ai_font, ai_fontsize);
431 fprintf(gpoutfile, "/_%s %d 0 0 1 z\n", ai_font, ai_fontsize);
434 fprintf(gpoutfile, "/_%s %d 0 0 2 z\n", ai_font, ai_fontsize);
438 fprintf(gpoutfile, "[ 1 0 0 1 %.2f %.2f] e\n",
439 x / AI_SC, y / AI_SC - ai_fontsize / 3.0);
441 fprintf(gpoutfile, "[ 0 1 -1 0 %.2f %.2f] e\n",
442 x / AI_SC - ai_fontsize / 3.0, y / AI_SC);
445 putc('(', gpoutfile);
448 if ((ch == '(') || (ch == ')') || (ch == '\\'))
449 putc('\\', gpoutfile);
453 fputs(") t\nT\n", gpoutfile);
458 AI_text_angle(int ang)
465 AI_justify_text(enum JUSTIFY mode)
472 AI_set_font(const char *font)
479 sep = strcspn(font, ",");
480 assert(sep < sizeof(name));
481 strncpy(name, font, sep);
484 sscanf(&(font[sep + 1]), "%d", &size);
486 strcpy(ai_font, name);
490 ai_fontsize = ai_oldfontsize;
491 strcpy(ai_font, ai_oldfont);
513 TERM_TABLE_START(aifm_driver)
514 "aifm", "Adobe Illustrator 3.0 Format",
515 AI_XMAX, AI_YMAX, AI_VCHAR, AI_HCHAR,
516 AI_VTIC, AI_HTIC, AI_options, AI_init, AI_reset,
517 AI_text, null_scale, AI_graphics, AI_move, AI_vector,
518 AI_linetype, AI_put_text, AI_text_angle,
519 AI_justify_text, do_point, do_arrow, AI_set_font,
520 NULL, 0, AI_suspend, AI_resume
521 TERM_TABLE_END(aifm_driver)
524 #define LAST_TERM aifm_driver
526 #endif /* TERM_TABLE */
527 #endif /* TERM_PROTO_ONLY */
532 "?commands set terminal aifm",
533 "?set terminal aifm",
539 " NOTE: this terminal driver is outdated. Since Adobe Illustrator understands",
540 " PostScript level 1 directly, you should use `set terminal post level1`",
543 " Several options may be set in `aifm`---the Adobe Illustrator 3.0+ driver.",
546 " set terminal aifm {<color>} {\"<fontname>\"} {<fontsize>}",
548 " <color> is either `color` or `monochrome`; \"<fontname>\" is the name of a",
549 " valid PostScript font; <fontsize> is the size of the font in PostScript",
550 " points, before scaling by the `set size` command. Selecting `default` sets",
551 " all options to their default values: `monochrome`, \"Times-Roman\", and 14pt.",
553 " Since AI does not really support multiple pages, multiple graphs will be",
554 " drawn directly on top of one another. However, each graph will be grouped",
555 " individually, making it easy to separate them inside AI (just pick them up",
561 " set size 0.7,1.4; set term aifm color \"Times-Roman\" 14"
563 #endif /* TERM_HELP */