Annotation of OpenXM_contrib/gnuplot/term/texdraw.trm, Revision 1.1.1.2
1.1 maekawa 1: /*
1.1.1.2 ! maekawa 2: * $Id: texdraw.trm,v 1.9 1998/12/14 18:41:27 lhecking Exp $
1.1 maekawa 3: */
4:
5: /* GNUPLOT - texdraw.trm */
6:
7: /*[
8: * Copyright 1990 - 1993, 1998
9: *
10: * Permission to use, copy, and distribute this software and its
11: * documentation for any purpose with or without fee is hereby granted,
12: * provided that the above copyright notice appear in all copies and
13: * that both that copyright notice and this permission notice appear
14: * in supporting documentation.
15: *
16: * Permission to modify the software is granted, but not the right to
17: * distribute the complete modified source code. Modifications are to
18: * be distributed as patches to the released version. Permission to
19: * distribute binaries produced by compiling modified sources is granted,
20: * provided you
21: * 1. distribute the corresponding source modifications from the
22: * released version in the form of a patch file along with the binaries,
23: * 2. add special version identification to distinguish your version
24: * in addition to the base release version number,
25: * 3. provide your name and address as the primary contact for the
26: * support of your modified version, and
27: * 4. retain our contact information in regard to use of the base
28: * software.
29: * Permission to distribute the released version of the source code along
30: * with corresponding source modifications in the form of a patch file is
31: * granted with same provisions 2 through 4 for binary distributions.
32: *
33: * This software is provided "as is" without express or implied warranty
34: * to the extent permitted by applicable law.
35: ]*/
36:
37: /*
38: * This file is included by ../term.c.
39: *
40: * This terminal driver supports:
41: * The TEXDRAW macros for LaTeX.
42: *
43: * AUTHORS
44: * Khun Yee Fung. Modified from eepic.trm.
45: * clipper@csd.uwo.ca
46: * January 20, 1992
47: *
48: * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
49: *
50: */
51:
52: /*
53: * This file contains the texdraw terminal driver, intended for use with the
54: * texdraw macro package for LaTeX. This is an alternative to the
55: * latex driver. You need texdraw.sty, and texdraw.tex in the texdraw package.
56: *
57: */
58: #include "driver.h"
59:
60: #ifdef TERM_REGISTER
61: register_term(texdraw)
62: #endif
63:
64: #ifdef TERM_PROTO
65: TERM_PUBLIC void TEXDRAW_init __PROTO((void));
66: TERM_PUBLIC void TEXDRAW_graphics __PROTO((void));
67: TERM_PUBLIC void TEXDRAW_text __PROTO((void));
68: TERM_PUBLIC void TEXDRAW_linetype __PROTO((int linetype));
69: TERM_PUBLIC void TEXDRAW_move __PROTO((unsigned int x, unsigned int y));
70: TERM_PUBLIC void TEXDRAW_point __PROTO((unsigned int x, unsigned int y,
71: int number));
72: TERM_PUBLIC void TEXDRAW_vector __PROTO((unsigned int ux, unsigned int uy));
73: TERM_PUBLIC void TEXDRAW_arrow __PROTO((unsigned int sx, unsigned int sy,
74: unsigned int ex, unsigned int ey,
75: TBOOLEAN head));
76: TERM_PUBLIC void TEXDRAW_put_text __PROTO((unsigned int x, unsigned int y,
77: char str[]));
78: TERM_PUBLIC int TEXDRAW_justify_text __PROTO((enum JUSTIFY mode));
79: TERM_PUBLIC int TEXDRAW_text_angle __PROTO((int ang));
80: TERM_PUBLIC void TEXDRAW_reset __PROTO((void));
81:
82: #define TEXDRAW_PTS_PER_INCH (72.27)
83: /* resolution of printer we expect to use */
84: #define DOTS_PER_INCH (300)
85: /* dot size in pt */
86: #define TEXDRAW_UNIT (TEXDRAW_PTS_PER_INCH/DOTS_PER_INCH)
87:
88: /* 5 inches wide by 3 inches high (default) */
89: #define TEXDRAW_XMAX (5*DOTS_PER_INCH)
90: #define TEXDRAW_YMAX (3*DOTS_PER_INCH)
91:
92: #define TEXDRAW_HTIC (5*DOTS_PER_INCH/72) /* (5./TEXDRAW_UNIT) */
93: #define TEXDRAW_VTIC (5*DOTS_PER_INCH/72) /* (5./TEXDRAW_UNIT) */
94: #define TEXDRAW_HCHAR (DOTS_PER_INCH*53/10/72) /* (5.3/TEXDRAW_UNIT) */
95: #define TEXDRAW_VCHAR (DOTS_PER_INCH*11/72) /* (11./TEXDRAW_UNIT) */
96:
97: #define GOT_TEXDRAW_PROTO
98: #endif
99:
100: #ifndef TERM_PROTO_ONLY
101: #ifdef TERM_BODY
102: static void TEXDRAW_endline __PROTO((void));
103: static unsigned int TEXDRAW_posx;
104: static unsigned int TEXDRAW_posy;
105: enum JUSTIFY TEXDRAW_justify = LEFT;
106: enum JUSTIFY TEXDRAW_last_justify = LEFT;
107: static int TEXDRAW_angle = 0;
108: static float TEXDRAW_scalefactor = 0.2409;
109: static double TEXDRAW_xscale = 1.0, TEXDRAW_yscale = 1.0;
110:
111: /* for DOTS point style */
112: #define TEXDRAW_TINY_DOT "\\htext{$\\cdot$}"
113:
114: /* POINTS */
115: #define TEXDRAW_POINT_TYPES 12 /* we supply more point types */
116: static char GPFAR *GPFAR TEXDRAW_points[] =
117: {
118: "\\rmove(0 4)\\htext{$\\Diamond$}",
119: "\\htext{$+$}",
120: "\\rmove(0 4)\\htext{$\\Box$}",
121: "\\htext{$\\times$}",
122: "\\htext{$\\triangle$}",
123: "\\htext{$\\star$}",
124: "\\lcir r:9",
125: "\\lcir r:12",
126: "\\lcir r:16",
127: "\\fcir f:0.9 r:9",
128: "\\fcir f:0.9 r:12",
129: "\\fcir f:0.9 r:16"
130: };
131:
132: /* LINES */
133: #define TEXDRAW_NUMLINES 5 /* number of linetypes below */
134: static int TEXDRAW_lines[] =
135: {
136: 4, /* -2 border */
137: 3, /* -1 axes */
138: 3, /* 0 solid thin */
139: 4, /* 1 solid thick */
140: 6, /* 2 solid Thick */
141: };
142:
143: /* The line type selected most recently */
144: static int TEXDRAW_last_type = 0;
145: /* current line type */
146: static int TEXDRAW_type;
147: /* are we in the middle of a line */
148: static TBOOLEAN TEXDRAW_inline = FALSE;
149: /* terminate any line in progress */
150: static void TEXDRAW_endline __PROTO((void));
151: /* number of points in line so far */
152: static int TEXDRAW_linecount = 0;
153: /* max value for linecount */
154: #define TEXDRAW_LINEMAX 5
155:
156: TERM_PUBLIC void TEXDRAW_init()
157: {
158: TEXDRAW_posx = TEXDRAW_posy = 0;
159: TEXDRAW_linetype(-1);
160: fputs("%% GNUPLOT: LaTeX using TEXDRAW macros\n", gpoutfile);
161: }
162:
163: TERM_PUBLIC void TEXDRAW_graphics()
164: {
165: static char GPFAR tdg1[] = "\
166: \\begin{texdraw}\n\
167: \\normalsize\n\
168: \\ifx\\pathDEFINED\\relax\\else\\let\\pathDEFINED\\relax\n\
169: \\def\\QtGfr{\\ifx (\\TGre \\let\\YhetT\\cpath\\else\\let\\YhetT\\relax\\fi\\YhetT}\n\
170: \\def\\path (#1 #2){\\move (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
171: \\def\\cpath (#1 #2){\\lvec (#1 #2)\\futurelet\\TGre\\QtGfr}\n\
172: \\fi\n\
173: \\drawdim pt\n\
174: \\setunitscale %2.2f\n\
175: \\linewd %d\n\
176: \\textref h:L v:C\n";
177: fprintf(gpoutfile, tdg1,
178: TEXDRAW_scalefactor,
179: TEXDRAW_lines[2]);
180: TEXDRAW_last_type = 0;
181: TEXDRAW_type = 0;
182: }
183:
184: TERM_PUBLIC void TEXDRAW_text()
185: {
186: TEXDRAW_endline();
187: fputs("\\end{texdraw}\n", gpoutfile);
188: }
189:
190: TERM_PUBLIC void TEXDRAW_linetype(linetype)
191: int linetype;
192: {
193: TEXDRAW_endline();
194:
195: if (linetype >= TEXDRAW_NUMLINES - 2)
196: linetype %= (TEXDRAW_NUMLINES - 2);
197:
198: TEXDRAW_type = linetype;
199: }
200:
201: TERM_PUBLIC void TEXDRAW_move(x, y)
202: unsigned int x, y;
203: {
204: TEXDRAW_endline();
205:
206: TEXDRAW_posx = x;
207: TEXDRAW_posy = y;
208: }
209:
210: TERM_PUBLIC void TEXDRAW_point(x, y, number)
211: unsigned int x, y;
212: int number;
213: {
214: TEXDRAW_move(x, y);
215:
216: /* Print the character defined by 'number'; number < 0 means
217: * to use a dot, otherwise one of the defined points. */
218: fprintf(gpoutfile, "\\move (%d %d)\n",
219: (int) ((double) x * TEXDRAW_xscale),
220: (int) ((double) y * TEXDRAW_yscale));
221: if (TEXDRAW_last_justify != CENTRE) {
222: fprintf(gpoutfile, "\\textref h:C v:C ");
223: TEXDRAW_last_justify = CENTRE;
224: }
225: fprintf(gpoutfile, "%s\n",
226: (number < 0 ?
227: TEXDRAW_TINY_DOT :
228: TEXDRAW_points[number % TEXDRAW_POINT_TYPES]));
229: }
230:
231: TERM_PUBLIC void TEXDRAW_vector(ux, uy)
232: unsigned int ux, uy;
233: {
234: if (!TEXDRAW_inline) {
235: TEXDRAW_inline = TRUE;
236:
237: /* Start a new line. This depends on line type */
238: if (TEXDRAW_type != TEXDRAW_last_type) {
239: if (TEXDRAW_lines[TEXDRAW_type + 2] != TEXDRAW_lines[TEXDRAW_last_type + 2])
240: fprintf(gpoutfile, "\\linewd %d\n", TEXDRAW_lines[TEXDRAW_type + 2]);
241: TEXDRAW_last_type = TEXDRAW_type;
242: }
243: fprintf(gpoutfile, "\\path (%d %d)",
244: (int) ((double) TEXDRAW_posx * TEXDRAW_xscale),
245: (int) ((double) TEXDRAW_posy * TEXDRAW_yscale));
246: TEXDRAW_linecount = 1;
247: } else {
248: /* Even though we are in middle of a path,
249: * we may want to start a new path command.
250: * If they are too long then latex will choke.
251: */
252: if (TEXDRAW_linecount++ >= TEXDRAW_LINEMAX) {
253: fputs("\n\\cpath ", gpoutfile);
254: TEXDRAW_linecount = 1;
255: }
256: }
257: fprintf(gpoutfile, "(%d %d)",
258: (int) ((double) ux * TEXDRAW_xscale),
259: (int) ((double) uy * TEXDRAW_yscale));
260: TEXDRAW_posx = ux;
261: TEXDRAW_posy = uy;
262: }
263:
264: static void TEXDRAW_endline()
265: {
266: if (TEXDRAW_inline) {
267: putc('\n', gpoutfile);
268: TEXDRAW_inline = FALSE;
269: }
270: }
271:
272: TERM_PUBLIC void TEXDRAW_arrow(sx, sy, ex, ey, head)
273: unsigned int sx, sy, ex, ey;
274: TBOOLEAN head;
275: {
276: char text;
277:
278: if (head)
279: text = 'a';
280: else
281: text = 'l';
282: fprintf(gpoutfile, "\\move (%d %d)\\%cvec (%d %d)",
283: (int) ((double) sx * TEXDRAW_xscale),
284: (int) ((double) sy * TEXDRAW_yscale),
285: text,
286: (int) ((double) ex * TEXDRAW_xscale),
287: (int) ((double) ey * TEXDRAW_yscale));
288: TEXDRAW_posx = ex;
289: TEXDRAW_posy = ey;
290: }
291:
292: TERM_PUBLIC void TEXDRAW_put_text(x, y, str)
293: unsigned int x, y; /* reference point of string */
294: char str[]; /* the text */
295: {
296: char text;
297:
298: TEXDRAW_endline();
299:
300: fprintf(gpoutfile, "\\move (%d %d)",
301: (int) ((double) x * TEXDRAW_xscale),
302: (int) ((double) y * TEXDRAW_yscale));
303:
304: if (!TEXDRAW_angle)
305: text = 'h';
306: else
307: text = 'v';
308:
309: if (TEXDRAW_last_justify != TEXDRAW_justify) {
310: TEXDRAW_last_justify = TEXDRAW_justify;
311: if (TEXDRAW_justify == LEFT)
312: fputs("\\textref h:L v:C ", gpoutfile);
313: else if (TEXDRAW_justify == CENTRE)
314: fputs("\\textref h:C v:C ", gpoutfile);
315: else if (TEXDRAW_justify == RIGHT)
316: fputs("\\textref h:R v:C ", gpoutfile);
317: }
318: fprintf(gpoutfile, "\\%ctext{%s}\n", text, str);
319: }
320:
321:
322: TERM_PUBLIC int TEXDRAW_justify_text(mode)
323: enum JUSTIFY mode;
324: {
325: TEXDRAW_justify = mode;
326: return (TRUE);
327: }
328:
329: TERM_PUBLIC int TEXDRAW_text_angle(ang)
330: int ang;
331: {
332: TEXDRAW_angle = ang;
333: return (TRUE);
334: }
335:
336: TERM_PUBLIC void TEXDRAW_reset()
337: {
338: TEXDRAW_endline();
339: TEXDRAW_posx = TEXDRAW_posy = 0;
340: }
341:
342: #endif /* TERM_BODY */
343:
344: #ifdef TERM_TABLE
345:
346: TERM_TABLE_START(texdraw_driver)
347: "texdraw",
348: "LaTeX texdraw environment",
349: TEXDRAW_XMAX, TEXDRAW_YMAX, TEXDRAW_VCHAR, TEXDRAW_HCHAR,
350: TEXDRAW_VTIC, TEXDRAW_HTIC, options_null, TEXDRAW_init, TEXDRAW_reset,
351: TEXDRAW_text, null_scale, TEXDRAW_graphics, TEXDRAW_move, TEXDRAW_vector,
352: TEXDRAW_linetype, TEXDRAW_put_text, TEXDRAW_text_angle,
353: TEXDRAW_justify_text, TEXDRAW_point, TEXDRAW_arrow, set_font_null
354: TERM_TABLE_END(texdraw_driver)
355:
356: #undef LAST_TERM
357: #define LAST_TERM texdraw_driver
358:
359: #endif /* TERM_TABLE */
360:
361: #endif /* TERM_PROTO_ONLY */
362:
363: #ifdef TERM_HELP
364: START_HELP(texdraw)
365: "1 texdraw",
366: "?commands set terminal texdraw",
367: "?set terminal texdraw",
368: "?set term texdraw",
369: "?terminal texdraw",
370: "?term texdraw",
371: "?texdraw",
372: " The `texdraw` terminal driver supports the LaTeX texdraw environment. It is",
373: " intended for use with \"texdraw.sty\" and \"texdraw.tex\" in the texdraw package.",
374: "",
375: " It has no options."
376: END_HELP(texdraw)
377: #endif /* TERM_HELP */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>