1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: gpic.trm,v 1.18 2006/07/21 02:35:46 sfeam Exp $
5 /* GNUPLOT - gpic.trm */
8 * Copyright 1993, 1998, 2004
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.
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,
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
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.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
38 * This file is included by ../term.c.
42 * This terminal driver supports:
43 * The GPIC graphics language for groff
48 * send your comments or suggestions to (siglun@volterra.teorekol.lu.se).
53 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
63 TERM_PUBLIC void GPIC_options __PROTO((void));
64 TERM_PUBLIC void GPIC_init __PROTO((void));
65 TERM_PUBLIC void GPIC_graphics __PROTO((void));
66 TERM_PUBLIC void GPIC_text __PROTO((void));
67 TERM_PUBLIC void GPIC_linetype __PROTO((int linetype));
68 TERM_PUBLIC void GPIC_move __PROTO((unsigned int x, unsigned int y));
69 TERM_PUBLIC void GPIC_vector __PROTO((unsigned int ux, unsigned int uy));
70 TERM_PUBLIC void GPIC_arrow __PROTO((unsigned int sx, unsigned int sy,
71 unsigned int ex, unsigned int ey,
73 TERM_PUBLIC void GPIC_put_text __PROTO((unsigned int x, unsigned int y,
75 TERM_PUBLIC int GPIC_justify_text __PROTO((enum JUSTIFY mode));
76 TERM_PUBLIC int GPIC_text_angle __PROTO((int ang));
77 TERM_PUBLIC void GPIC_reset __PROTO((void));
78 #define GPIC_DOTS_PER_INCH (300)
80 /* 5 inches wide by 3 inches high (default) */
81 #define GPIC_XMAX (5*GPIC_DOTS_PER_INCH)
82 #define GPIC_YMAX (3*GPIC_DOTS_PER_INCH)
84 #define GPIC_HTIC (5*GPIC_DOTS_PER_INCH/72)
85 #define GPIC_VTIC (5*GPIC_DOTS_PER_INCH/72)
86 #define GPIC_HCHAR (GPIC_DOTS_PER_INCH*53/10/72)
87 #define GPIC_VCHAR (GPIC_DOTS_PER_INCH*11/72)
88 #endif /* TERM_PROTO */
90 #ifndef TERM_PROTO_ONLY
93 #define GPIC_PTS_PER_INCH (72.27)
95 #define GPIC_UNIT (GPIC_PTS_PER_INCH/GPIC_DOTS_PER_INCH)
96 #define GPIC_coord(x) ((float)x)/((float)GPIC_DOTS_PER_INCH)
98 static void GPIC_close_line __PROTO((void));
99 static float GPIC_x, GPIC_y;
100 static unsigned int GPIC_ltype;
101 static enum JUSTIFY GPIC_justify = LEFT;
103 /* for DOTS point style */
105 static const char *GPIC_lines[] =
107 "thickness 1.0", /* -2 border */
109 "", /* 0 solid thin */
111 "dashed 0.05", /* 1 solid thick */
112 "dashed 0.075", /* 2 solid Thick */
115 /* number of linetypes above */
116 #define GPIC_NUMLINES (sizeof(GPIC_lines)/sizeof(char *))
119 static int GPIC_linecount = 0; /* number of points in line so far */
131 if (!END_OF_COMMAND) {
132 x = real(const_express(&a));
133 if (!END_OF_COMMAND) {
134 y = real(const_express(&a));
139 sprintf(term_options, "Origin is at (%f,%f)", GPIC_x, GPIC_y);
147 fputs(".\\\"GNUPLOT: GROFF picture using the gpic preprocessor\n", gpoutfile);
155 register struct termentry *t = term;
157 fprintf(gpoutfile, ".PS %f %f\n", GPIC_coord(t->xmax),
158 GPIC_coord(t->ymax));
159 fprintf(gpoutfile, "x=%f; y=%f\n", GPIC_x, GPIC_y);
167 fputs(".PE\n", gpoutfile);
171 GPIC_linetype(int linetype)
175 if (linetype >= GPIC_NUMLINES - 2)
176 linetype %= (GPIC_NUMLINES - 2);
177 GPIC_ltype = linetype;
183 if (GPIC_linecount > 0) {
184 fputs("; reset linewid\n", gpoutfile);
190 GPIC_move(unsigned int x, unsigned int y)
193 fprintf(gpoutfile, "move to (x+%f,y+%f)\n", GPIC_coord(x), GPIC_coord(y));
199 GPIC_vector(unsigned int ux, unsigned int uy)
201 if (GPIC_linecount == 1) {
202 fprintf(gpoutfile, "line %s to (x+%f,y+%f)",
203 GPIC_lines[GPIC_ltype + 2],
204 GPIC_coord(ux), GPIC_coord(uy));
206 fprintf(gpoutfile, "\
208 then to (x+%f,y+%f)",
209 GPIC_coord(ux), GPIC_coord(uy));
217 unsigned int sx, unsigned int sy,
218 unsigned int ex, unsigned int ey,
223 fprintf(gpoutfile, "arrowhead=7; arrow from x+%f,y+%f to x+%f,y+%f\n",
224 GPIC_coord(sx), GPIC_coord(sy), GPIC_coord(ex), GPIC_coord(ey));
226 fprintf(gpoutfile, "line from x+%f,y+%f to x+%f,y+%f\n",
227 GPIC_coord(sx), GPIC_coord(sy), GPIC_coord(ex), GPIC_coord(ey));
233 GPIC_put_text(unsigned int x, unsigned int y, const char str[])
236 fprintf(gpoutfile, "\"%s\" ", str);
237 switch (GPIC_justify) {
239 fputs("ljust ", gpoutfile);
243 fputs(" ", gpoutfile);
247 fputs("rjust ", gpoutfile);
251 fprintf(gpoutfile, "at x+%f,y+%f\n", GPIC_coord(x), GPIC_coord(y));
257 GPIC_justify_text(enum JUSTIFY mode)
264 GPIC_text_angle(int ang)
277 #endif /* TERM_BODY */
281 TERM_TABLE_START(gpic_driver)
282 "gpic", "GPIC -- Produce graphs in groff using the gpic preprocessor",
283 GPIC_XMAX, GPIC_YMAX, GPIC_VCHAR, GPIC_HCHAR,
284 GPIC_VTIC, GPIC_HTIC, GPIC_options, GPIC_init, GPIC_reset,
285 GPIC_text, null_scale, GPIC_graphics, GPIC_move, GPIC_vector,
286 GPIC_linetype, GPIC_put_text, GPIC_text_angle,
287 GPIC_justify_text, line_and_point, GPIC_arrow, set_font_null
288 TERM_TABLE_END(gpic_driver)
290 #define LAST_TERM gpic_driver
292 #endif /* TERM_TABLE */
293 #endif /* TERM_PROTO_ONLY */
298 "?commands set terminal gpic",
299 "?set terminal gpic",
304 " The `gpic` terminal driver generates GPIC graphs in the Free Software",
305 " Foundations's \"groff\" package. The default size is 5 x 3 inches. The only",
306 " option is the origin, which defaults to (0,0).",
309 " set terminal gpic {<x> <y>}",
311 " where `x` and `y` are in inches.",
313 " A simple graph can be formatted using",
315 " groff -p -mpic -Tps file.pic > file.ps.",
317 " The output from pic can be pipe-lined into eqn, so it is possible to put",
318 " complex functions in a graph with the `set label` and `set {x/y}label`",
319 " commands. For instance,",
321 " set ylab '@space 0 int from 0 to x alpha ( t ) roman d t@'",
323 " will label the y axis with a nice integral if formatted with the command:",
325 " gpic filename.pic | geqn -d@@ -Tps | groff -m[macro-package] -Tps",
328 " Figures made this way can be scaled to fit into a document. The pic language",
329 " is easy to understand, so the graphs can be edited by hand if need be. All",
330 " co-ordinates in the pic-file produced by `gnuplot` are given as x+gnuplotx",
331 " and y+gnuploty. By default x and y are given the value 0. If this line is",
332 " removed with an editor in a number of files, one can put several graphs in",
333 " one figure like this (default size is 5.0x3.0 inches):",
337 " copy \"figa.pic\"",
339 " copy \"figb.pic\"",
341 " copy \"figc.pic\"",
343 " copy \"figd.pic\"",
346 " This will produce an 8-inch-wide figure with four graphs in two rows on top",
349 " One can also achieve the same thing by the command",
351 " set terminal gpic x y",
353 " for example, using",
356 " copy \"trig.pic\"",
359 #endif /* TERM_HELP */