Annotation of OpenXM_contrib/gnuplot/term/ai.trm, Revision 1.1.1.2
1.1 maekawa 1: /*
1.1.1.2 ! maekawa 2: * $Id: ai.trm,v 1.9 1999/01/13 21:49:44 lhecking Exp $
1.1 maekawa 3: *
4: */
5:
6: /* GNUPLOT - ai.trm */
7:
8: /*[
9: * Copyright 1991, 1992, 1993, 1998
10: *
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.
16: *
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,
21: * provided you
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
29: * software.
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.
33: *
34: * This software is provided "as is" without express or implied warranty
35: * to the extent permitted by applicable law.
36: ]*/
37:
38: /*
39: * This file is included by ../term.c.
40: *
41: * This terminal driver supports:
42: * aifm
43: *
44: * AUTHORS
45: * Ray Ghanbari
46: *
47: * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
48: *
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'.
54: */
55:
56: /* AIFM driver by Ray Ghanbari, ray@mtl.mit.edu,
57: * based on PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
58:
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 */
63:
64: #include "driver.h"
65:
66: #ifdef TERM_REGISTER
67: register_term(aifm)
68: #endif
69:
70: #ifdef TERM_PROTO
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, 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(());
83: TERM_PUBLIC void AI_resume __PROTO(());
84: TERM_PUBLIC int AI_set_font __PROTO((char *font));
85:
86: #define AI_XOFF 50 /* page offset in pts */
87: #define AI_YOFF 50
88:
89: #define AI_XMAX 5000
90: #define AI_YMAX 3500
91:
92: #define AI_XLAST (AI_XMAX - 1)
93: #define AI_YLAST (AI_YMAX - 1)
94:
95: #define AI_VTIC (AI_YMAX/80)
96: #define AI_HTIC (AI_YMAX/80)
97:
98: #define AI_SC (10.0) /* scale is 1pt = 10 units */
99: #define AI_LW (0.5*AI_SC) /* linewidth = 0.5 pts */
100:
101: #define AI_VCHAR (14*AI_SC) /* default is 14 point characters */
102: #define AI_HCHAR (14*AI_SC*6/10)
103:
104: #endif
105:
106:
107:
108: #ifndef TERM_PROTO_ONLY
109: #ifdef TERM_BODY
110:
111: /* From version.c */
112: extern char version[];
113: extern char patchlevel[];
114:
115: char ai_font[MAX_ID_LEN + 1] = "Times-Roman"; /* name of font */
116: int ai_fontsize = 14; /* size of font in pts */
117: char ai_oldfont[MAX_ID_LEN + 1] = "Times-Roman"; /* name of font */
118: int ai_oldfontsize = 14; /* size of font in pts */
119: TBOOLEAN ai_color = FALSE;
120: TBOOLEAN ai_stroke = FALSE;
121: int ai_page = 0; /* page count */
122: int ai_path_count = 0; /* count of lines in path */
123: int ai_ang = 0; /* text angle */
124: int ai_subgroup_level = 0; /* depth of sub-groups */
125: int ai_multiplot_group = 0; /* group for multiplot */
126: enum JUSTIFY ai_justify = LEFT; /* text is flush left */
127:
128:
129: TERM_PUBLIC void AI_options()
130: {
131: if (!END_OF_COMMAND) {
132: if (almost_equals(c_token, "d$efault")) {
133: ai_color = FALSE;
134: strcpy(ai_font, "Times-Roman");
135: ai_fontsize = 14;
136: strcpy(ai_oldfont, "Times-Roman");
137: ai_oldfontsize = 14;
138: c_token++;
139: }
140: }
141: if (!END_OF_COMMAND) {
142: if (almost_equals(c_token, "m$onochrome")) {
143: ai_color = FALSE;
144: c_token++;
145: } else if (almost_equals(c_token, "c$olor")
146: || almost_equals(c_token, "c$olour")) {
147: ai_color = TRUE;
148: c_token++;
149: }
150: }
151: if (!END_OF_COMMAND && isstring(c_token)) {
152: quote_str(ai_font, c_token, MAX_ID_LEN);
153: strcpy(ai_oldfont, ai_font);
154: c_token++;
155: }
156: if (!END_OF_COMMAND) {
157: /* We have font size specified */
158: struct value a;
159: ai_fontsize = (int) real(const_express(&a));
160: ai_oldfontsize = ai_fontsize;
161: c_token++;
162: term->v_char = (unsigned int) (ai_fontsize * AI_SC);
163: term->h_char = (unsigned int) (ai_fontsize * AI_SC * 6 / 10);
164: }
165: sprintf(term_options, "%s \"%s\" %d",
166: ai_color ? "color" : "monochrome", ai_font, ai_fontsize);
167: }
168:
169:
170: TERM_PUBLIC void AI_init()
171: {
172: ai_page = 0;
173:
174: fprintf(gpoutfile, "%%!PS-Adobe-2.0 EPSF-1.2\n\
175: %%%%Creator: Adobe Illustrator(TM) 3.2\n\
176: %%%%TrueCreator: gnuplot %s patchlevel %s ai terminal\n\
177: %%%%BoundingBox: %d %d %d %d\n\
178: %%%%Template:\n\
179: %%%%EndComments\n\
180: %%%%EndProlog\n",
181: version, patchlevel,
182: AI_XOFF, AI_YOFF,
183: (int) ((AI_XMAX) / AI_SC + 0.5 + AI_XOFF),
184: (int) ((AI_YMAX) / AI_SC + 0.5 + AI_YOFF));
185: }
186:
187:
188: TERM_PUBLIC void AI_graphics()
189: {
190: ai_page++;
191: /* fprintf(gpoutfile,"%%%%Page: %d %d\n",ai_page,ai_page);*/
192: fputs("\
193: 0 G\n\
194: 1 j\n\
195: 1 J\n\
196: u\n", gpoutfile);
197: ai_path_count = 0;
198: ai_stroke = FALSE;
199: }
200:
201:
202: TERM_PUBLIC void AI_text()
203: {
204: if (ai_stroke) {
205: fputs("S\n", gpoutfile);
206: ai_stroke = FALSE;
207: }
208: while (ai_subgroup_level) {
209: fputs("U\n", gpoutfile);
210: ai_subgroup_level--;
211: }
212: fputs("U\n", gpoutfile);
213: ai_path_count = 0;
214: ai_multiplot_group = 0;
215: }
216:
217:
218: TERM_PUBLIC void AI_reset()
219: {
220: fputs("%%%%Trailer\n", gpoutfile);
221: /* fprintf(gpoutfile,"%%%%Pages: %d\n",ai_page);*/
222: }
223:
224:
225: TERM_PUBLIC void AI_linetype(linetype)
226: int linetype;
227: {
228: if (ai_stroke) {
229: fputs("S\n", gpoutfile);
230: ai_stroke = FALSE;
231: }
232: if (ai_subgroup_level) {
233: fputs("U\n", gpoutfile);
234: ai_subgroup_level--;
235: }
236: if (linetype == -2 && multiplot) {
237: /* for each new plot, line_type gets called twice with a value of -2.
238: It gets called once for the border and again for the tics.
239: This code will need to be changed if gnuplot's behavior changes.
240: */
241: switch (ai_multiplot_group) {
242: case 0:
243: fputs("u\n", gpoutfile);
244: ai_subgroup_level++;
245: ai_multiplot_group = 1;
246: break;
247: case 1:
248: ai_multiplot_group = 2;
249: break;
250: case 2:
251: ai_multiplot_group = 1;
252: fputs("U\nu\n", gpoutfile);
253: break;
254: }
255: }
256: if (linetype == -2 && !multiplot) {
257: if (ai_multiplot_group) {
258: fputs("U\n", gpoutfile);
259: ai_subgroup_level--;
260: ai_multiplot_group = 0;
261: }
262: }
263: fputs("u\n", gpoutfile);
264: ai_subgroup_level++;
265:
266: switch (linetype) {
267: case -2:
268: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC * 2.0);
269: if (ai_color) {
270: fputs("0 0 0 1 K\n", gpoutfile);
271: } else {
272: fputs("[] 0 d\n", gpoutfile);
273: }
274: break;
275:
276: case -1:
277: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC / 2.0);
278: if (ai_color) {
279: fputs("0 0 0 1 K\n", gpoutfile);
280: } else {
281: fputs("[1 2] 0 d\n", gpoutfile);
282: }
283: break;
284:
285: case 0:
286: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
287: if (ai_color) {
288: fputs("1 0 1 0 K\n", gpoutfile);
289: } else {
290: fputs("[] 0 d\n", gpoutfile);
291: }
292: break;
293:
294: case 1:
295: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
296: if (ai_color) {
297: fputs("1 1 0 0 K\n", gpoutfile);
298: } else {
299: fputs("[4 2] 0 d\n", gpoutfile);
300: }
301: break;
302:
303: case 2:
304: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
305: if (ai_color) {
306: fputs("0 1 1 0 K\n", gpoutfile);
307: } else {
308: fputs("[2 3] 0 d\n", gpoutfile);
309: }
310: break;
311:
312: case 3:
313: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
314: if (ai_color) {
315: fputs("0 1 0 0 K\n", gpoutfile);
316: } else {
317: fputs("[1 1.5] 0 d\n", gpoutfile);
318: }
319: break;
320:
321: case 4:
322: fprintf(gpoutfile, "%f w\n", AI_LW / AI_SC);
323: if (ai_color) {
324: fputs("1 0 0 0 K\n", gpoutfile);
325: } else {
326: fputs("[5 2 1 2] 0 d\n", gpoutfile);
327: }
328: break;
329:
330: case 5:
331: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
332: if (ai_color) {
333: fputs("0 0 1 0 K\n", gpoutfile);
334: } else {
335: fputs("[4 3 1 3] 0 d\n", gpoutfile);
336: }
337: break;
338:
339: case 6:
340: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
341: if (ai_color) {
342: fputs("0 0 0 1 K\n", gpoutfile);
343: } else {
344: fputs("[2 2 2 4] 0 d\n", gpoutfile);
345: }
346: break;
347:
348: case 7:
349: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
350: if (ai_color) {
351: fputs("0 0.7 1 0 K\n", gpoutfile);
352: } else {
353: fputs("[2 2 2 2 2 4] 0 d\n", gpoutfile);
354: }
355: break;
356:
357: case 8:
358: fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
359: if (ai_color) {
360: fputs("0.5 0.5 0.5 0 K\n", gpoutfile);
361: } else {
362: fputs("[2 2 2 2 2 2 2 4] 0 d\n", gpoutfile);
363: }
364: break;
365: }
366:
367: ai_path_count = 0;
368: }
369:
370:
371: TERM_PUBLIC void AI_move(x, y)
372: unsigned int x, y;
373: {
374: if (ai_stroke)
375: fputs("S\n", gpoutfile);
376: fprintf(gpoutfile, "%.2f %.2f m\n", x / AI_SC, y / AI_SC);
377: ai_path_count += 1;
378: ai_stroke = TRUE;
379: }
380:
381:
382: TERM_PUBLIC void AI_vector(x, y)
383: unsigned int x, y;
384: {
385: fprintf(gpoutfile, "%.2f %.2f l\n", x / AI_SC, y / AI_SC);
386: ai_path_count += 1;
387: ai_stroke = TRUE;
388: if (ai_path_count >= 400) {
389: fprintf(gpoutfile, "S\n%.2f %.2f m\n", x / AI_SC, y / AI_SC);
390: ai_path_count = 0;
391: }
392: }
393:
394:
395: TERM_PUBLIC void AI_put_text(x, y, str)
396: unsigned int x, y;
397: char *str;
398: {
399: char ch;
400: if (ai_stroke) {
401: fputs("S\n", gpoutfile);
402: ai_stroke = FALSE;
403: }
404: switch (ai_justify) {
405: case LEFT:
406: fprintf(gpoutfile, "/_%s %d 0 0 0 z\n", ai_font, ai_fontsize);
407: break;
408: case CENTRE:
409: fprintf(gpoutfile, "/_%s %d 0 0 1 z\n", ai_font, ai_fontsize);
410: break;
411: case RIGHT:
412: fprintf(gpoutfile, "/_%s %d 0 0 2 z\n", ai_font, ai_fontsize);
413: break;
414: }
415: if (ai_ang == 0) {
416: fprintf(gpoutfile, "[ 1 0 0 1 %.2f %.2f] e\n",
417: x / AI_SC, y / AI_SC - ai_fontsize / 3.0);
418: } else {
419: fprintf(gpoutfile, "[ 0 1 -1 0 %.2f %.2f] e\n",
420: x / AI_SC - ai_fontsize / 3.0, y / AI_SC);
421: }
422:
423: putc('(', gpoutfile);
424: ch = *str++;
425: while (ch != '\0') {
426: if ((ch == '(') || (ch == ')') || (ch == '\\'))
427: putc('\\', gpoutfile);
428: putc(ch, gpoutfile);
429: ch = *str++;
430: }
431: fputs(") t\nT\n", gpoutfile);
432: ai_path_count = 0;
433: }
434:
435: TERM_PUBLIC int AI_text_angle(ang)
436: int ang;
437: {
438: ai_ang = ang;
439: return TRUE;
440: }
441:
442: TERM_PUBLIC int AI_justify_text(mode)
443: enum JUSTIFY mode;
444: {
445: ai_justify = mode;
446: return TRUE;
447: }
448:
449: TERM_PUBLIC int AI_set_font(font) /* Entry font added by DJL */
450: char *font;
451: {
452: char name[32];
453: int size, sep;
454:
455: if (font && *font) {
456: sep = strcspn(font, ",");
457: strncpy(name, font, sep);
458: name[sep] = '\0';
459: size = ai_fontsize;
460: sscanf(&(font[sep + 1]), "%d", &size);
461: if (*name)
462: strcpy(ai_font, name);
463: if (size)
464: ai_fontsize = size;
465: } else {
466: ai_fontsize = ai_oldfontsize;
467: strcpy(ai_font, ai_oldfont);
468: }
469: return TRUE;
470: }
471:
472:
473: TERM_PUBLIC void AI_suspend()
474: {
475: }
476:
477: TERM_PUBLIC void AI_resume()
478: {
479: }
480:
481:
482: #endif
483:
484:
485: #ifdef TERM_TABLE
486:
487: TERM_TABLE_START(aifm_driver)
488: "aifm", "Adobe Illustrator 3.0 Format",
489: AI_XMAX, AI_YMAX, AI_VCHAR, AI_HCHAR,
490: AI_VTIC, AI_HTIC, AI_options, AI_init, AI_reset,
491: AI_text, null_scale, AI_graphics, AI_move, AI_vector,
492: AI_linetype, AI_put_text, AI_text_angle,
493: AI_justify_text, do_point, do_arrow, AI_set_font,
494: NULL, 0, AI_suspend, AI_resume
495: TERM_TABLE_END(aifm_driver)
496:
497: #undef LAST_TERM
498: #define LAST_TERM aifm_driver
499:
500: #endif /* TERM_TABLE */
501: #endif /* TERM_PROTO_ONLY */
502:
503: #ifdef TERM_HELP
504: START_HELP(aifm)
505: "1 aifm",
506: "?commands set terminal aifm",
507: "?set terminal aifm",
508: "?set term aifm",
509: "?terminal aifm",
510: "?term aifm",
511: "?aifm",
512: " Several options may be set in `aifm`---the Adobe Illustrator 3.0+ driver.",
513: "",
514: " Syntax:",
515: " set terminal aifm {<color>} {\"<fontname>\"} {<fontsize>}",
516: "",
517: " <color> is either `color` or `monochrome`; \"<fontname>\" is the name of a",
518: " valid PostScript font; <fontsize> is the size of the font in PostScript",
519: " points, before scaling by the `set size` command. Selecting `default` sets",
520: " all options to their default values: `monochrome`, \"Helvetica\", and 14pt.",
521: "",
522: " Since AI does not really support multiple pages, multiple graphs will be",
523: " drawn directly on top of one another. However, each graph will be grouped",
524: " individually, making it easy to separate them inside AI (just pick them up",
525: " and move them).",
526: "",
527: " Examples:",
528: " set term aifm",
529: " set term aifm 22",
530: " set size 0.7,1.4; set term aifm color \"Times-Roman\" 14"
531: END_HELP(ai)
532: #endif /* TERM_HELP */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>