/usr/bin/gnuplot symlinks packageing problems were fixed gor gnuplot-x11
[gnuplot] / term / gpic.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: gpic.trm,v 1.18 2006/07/21 02:35:46 sfeam Exp $
3  */
4
5 /* GNUPLOT - gpic.trm */
6
7 /*[
8  * Copyright 1993, 1998, 2004
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
41 /*
42  * This terminal driver supports:
43  *   The GPIC graphics language for groff
44  *
45  * AUTHOR
46  *  Sigfrid Lundberg
47  *
48  * send your comments or suggestions to (siglun@volterra.teorekol.lu.se).
49  *
50  */
51
52 /*
53  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
54  */
55
56 #include "driver.h"
57
58 #ifdef TERM_REGISTER
59 register_term(gpic)
60 #endif
61
62 #ifdef TERM_PROTO
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,
72                                      int head));
73 TERM_PUBLIC void GPIC_put_text __PROTO((unsigned int x, unsigned int y,
74                                         const char str[]));
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)
79
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)
83
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 */
89
90 #ifndef TERM_PROTO_ONLY
91 #ifdef TERM_BODY
92
93 #define GPIC_PTS_PER_INCH (72.27)
94 /* dot size in pt */
95 #define GPIC_UNIT (GPIC_PTS_PER_INCH/GPIC_DOTS_PER_INCH)
96 #define GPIC_coord(x) ((float)x)/((float)GPIC_DOTS_PER_INCH)
97
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;
102
103 /* for DOTS point style */
104
105 static const char *GPIC_lines[] =
106 {
107     "thickness 1.0",            /* -2 border */
108     "",                         /* -1 axes */
109     "",                         /*  0 solid thin  */
110     "dotted",
111     "dashed 0.05",              /*  1 solid thick */
112     "dashed 0.075",             /*  2 solid Thick */
113 };
114
115 /* number of linetypes above */
116 #define GPIC_NUMLINES (sizeof(GPIC_lines)/sizeof(char *))
117
118
119 static int GPIC_linecount = 0;  /* number of points in line so far */
120
121
122 TERM_PUBLIC void
123 GPIC_options()
124 {
125     float x, y;
126     struct value a;
127
128     GPIC_x = 0;
129     GPIC_y = 0;
130
131     if (!END_OF_COMMAND) {
132         x = real(const_express(&a));
133         if (!END_OF_COMMAND) {
134             y = real(const_express(&a));
135             GPIC_x = x;
136             GPIC_y = y;
137         }
138     }
139     sprintf(term_options, "Origin is at (%f,%f)", GPIC_x, GPIC_y);
140
141 }
142
143 TERM_PUBLIC void
144 GPIC_init()
145 {
146     GPIC_linetype(-1);
147     fputs(".\\\"GNUPLOT: GROFF picture using the gpic preprocessor\n", gpoutfile);
148 }
149
150
151
152 TERM_PUBLIC void
153 GPIC_graphics()
154 {
155     register struct termentry *t = term;
156
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);
160 }
161
162
163 TERM_PUBLIC void
164 GPIC_text()
165 {
166     GPIC_close_line();
167     fputs(".PE\n", gpoutfile);
168 }
169
170 TERM_PUBLIC void
171 GPIC_linetype(int linetype)
172 {
173     if (linetype < -2)
174         linetype = LT_BLACK;
175     if (linetype >= GPIC_NUMLINES - 2)
176         linetype %= (GPIC_NUMLINES - 2);
177     GPIC_ltype = linetype;
178 }
179
180 static void
181 GPIC_close_line()
182 {
183     if (GPIC_linecount > 0) {
184         fputs("; reset linewid\n", gpoutfile);
185         GPIC_linecount = 0;
186     }
187 }
188
189 TERM_PUBLIC void
190 GPIC_move(unsigned int x, unsigned int y)
191 {
192     GPIC_close_line();
193     fprintf(gpoutfile, "move to (x+%f,y+%f)\n", GPIC_coord(x), GPIC_coord(y));
194     GPIC_linecount = 1;
195 }
196
197
198 TERM_PUBLIC void
199 GPIC_vector(unsigned int ux, unsigned int uy)
200 {
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));
205     } else {
206         fprintf(gpoutfile, "\
207  \\\n\
208    then to (x+%f,y+%f)",
209                 GPIC_coord(ux), GPIC_coord(uy));
210     }
211     GPIC_linecount++;
212 }
213
214
215 TERM_PUBLIC void
216 GPIC_arrow(
217     unsigned int sx, unsigned int sy,
218     unsigned int ex, unsigned int ey,
219     int head)
220 {
221     GPIC_close_line();
222     if (head) {
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));
225     } else {
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));
228     }
229 }
230
231
232 TERM_PUBLIC void
233 GPIC_put_text(unsigned int x, unsigned int y, const char str[])
234 {
235     GPIC_close_line();
236     fprintf(gpoutfile, "\"%s\" ", str);
237     switch (GPIC_justify) {
238     case LEFT:{
239             fputs("ljust ", gpoutfile);
240             break;
241         }
242     case CENTRE:{
243             fputs(" ", gpoutfile);
244             break;
245         }
246     case RIGHT:{
247             fputs("rjust ", gpoutfile);
248             break;
249         }
250     }
251     fprintf(gpoutfile, "at x+%f,y+%f\n", GPIC_coord(x), GPIC_coord(y));
252 }
253
254
255
256 TERM_PUBLIC int
257 GPIC_justify_text(enum JUSTIFY mode)
258 {
259     GPIC_justify = mode;
260     return (TRUE);
261 }
262
263 TERM_PUBLIC int
264 GPIC_text_angle(int ang)
265 {
266     (void) ang;
267     GPIC_close_line();
268     return (FALSE);
269 }
270
271 TERM_PUBLIC void
272 GPIC_reset()
273 {
274     fflush(gpoutfile);
275 }
276
277 #endif /* TERM_BODY */
278
279 #ifdef TERM_TABLE
280
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)
289 #undef LAST_TERM
290 #define LAST_TERM gpic_driver
291
292 #endif /* TERM_TABLE */
293 #endif /* TERM_PROTO_ONLY */
294
295 #ifdef TERM_HELP
296 START_HELP(gpic)
297 "1 gpic",
298 "?commands set terminal gpic",
299 "?set terminal gpic",
300 "?set term gpic",
301 "?terminal gpic",
302 "?term gpic",
303 "?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).",
307 "",
308 " Syntax:",
309 "       set terminal gpic {<x> <y>}",
310 "",
311 " where `x` and `y` are in inches.",
312 "",
313 " A simple graph can be formatted using",
314 "",
315 "       groff -p -mpic -Tps file.pic > file.ps.",
316 "",
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,",
320 "",
321 "       set ylab '@space 0 int from 0 to x alpha ( t ) roman d t@'",
322 "",
323 " will label the y axis with a nice integral if formatted with the command:",
324 "",
325 "       gpic filename.pic | geqn -d@@ -Tps | groff -m[macro-package] -Tps",
326 "           > filename.ps",
327 "",
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):",
334 "",
335 "       .PS 8.0",
336 "       x=0;y=3",
337 "       copy \"figa.pic\"",
338 "       x=5;y=3",
339 "       copy \"figb.pic\"",
340 "       x=0;y=0",
341 "       copy \"figc.pic\"",
342 "       x=5;y=0",
343 "       copy \"figd.pic\"",
344 "       .PE",
345 "",
346 " This will produce an 8-inch-wide figure with four graphs in two rows on top",
347 " of each other.",
348 "",
349 " One can also achieve the same thing by the command",
350 "",
351 "       set terminal gpic x y",
352 "",
353 " for example, using",
354 "",
355 "       .PS 6.0",
356 "       copy \"trig.pic\"",
357 "       .PE"
358 END_HELP(gpic)
359 #endif /* TERM_HELP */