Changed russian description a little bit
[gnuplot] / term / gnugraph.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: gnugraph.trm,v 1.24 2006/07/21 02:35:46 sfeam Exp $
3  */
4
5 /* GNUPLOT -- gnugraph.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  * This terminal driver supports:
41  *  GNU plot(5) graphics language
42  *
43  * AUTHORS
44  *  Tony Richardson from the unixplot.trm by Colin Kelley, Thomas Williams,
45  *  and Russell Lang and from post.trm by Russell Lang.
46  *
47  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
48  */
49
50 /*
51  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
52  */
53
54 /*
55  * Name changed from "unixplot" to "gnugraph" to distinguish the two different
56  * drivers. Also avoids duplications in the complete gnuplot documentation.
57  * (March 2003)
58  */
59
60 /*
61  * This version of the 'unixplot' driver produces device independent
62  * output.  I've chosen parameter values so that the PostScript output
63  * produced by plot2ps is 5" x 3".  You can use the 'set size' command
64  * to get output up to 8.25" x 8.25", i.e. size values larger than
65  * 1 are okay.
66  */
67
68 /*
69 Unixplot library writes to stdout.  A fix was put in place by
70 ..!arizona!naucse!jdc to let set term and set output redirect
71 stdout.  All other terminals write to gpoutfile.
72 */
73
74 /* This is a device independent format, so the output should look
75  * look "reasonable" on any output device.  I set things up there so
76  * that the output of plot2ps is 5" x 3" (standard GNUPLOT size).
77  * You can use GNUPLOT's size command to obtain plots to almost the
78  * 8.25" x 8.25" limit.
79  */
80
81 #include "driver.h"
82
83 #ifdef TERM_REGISTER
84 register_term(gnugraph)
85 #endif
86
87 #ifdef TERM_PROTO
88 TERM_PUBLIC void UP_options __PROTO((void));
89 TERM_PUBLIC void UP_init __PROTO((void));
90 TERM_PUBLIC void UP_graphics __PROTO((void));
91 TERM_PUBLIC void UP_text __PROTO((void));
92 TERM_PUBLIC void UP_linetype __PROTO((int linetype));
93 TERM_PUBLIC void UP_move __PROTO((unsigned int x, unsigned int y));
94 TERM_PUBLIC void UP_vector __PROTO((unsigned int x, unsigned int y));
95 TERM_PUBLIC void UP_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
96 TERM_PUBLIC int UP_text_angle __PROTO((int ang));
97 TERM_PUBLIC int UP_justify_text __PROTO((enum JUSTIFY mode));
98 TERM_PUBLIC void UP_reset __PROTO((void));
99 #define UP_XMAX 19859
100 #define UP_YMAX 11565
101 /* UP_VCHAR = ((UP_FONTSIZE*UP_YMAX)/(UP_YINCHES*72))
102             = UP_FONTSIZE*UP_VFONTSC
103    UP_HCHAR = ((UP_FONTSIZE/2)*UP_XMAX)/(UP_XINCHES*72))
104             = UP_FONTSIZE*UP_HFONTSC
105 */
106
107 #define UP_VFONTSC  53.5
108 #define UP_VCHAR    535         /* 10 * VFONTSC */
109 #define UP_HFONTSC  27.6
110 #define UP_HCHAR    276         /* 10 * HFONTSC */
111
112 #define UP_VTIC (UP_YMAX/80)
113 #define UP_HTIC (UP_XMAX/80)
114 #endif /* TERM_PROTO */
115
116 #ifndef TERM_PROTO_ONLY
117 #ifdef TERM_BODY
118
119 #define DEFAULT_GNUGRAPHFONT "Courier"
120
121 /* Name of font */
122 char up_font[MAX_ID_LEN+1] = DEFAULT_GNUGRAPHFONT;
123 int up_fontsize = 10;
124
125 /* plot2ps produces a 8.25" x 8.25" square. */
126 #define UP_SCREENX 32768
127 #define UP_SCREENY 32768
128 #define UP_SCRXINC 8.25
129 #define UP_SCRYINC 8.25
130
131 /* We want a 5" x 3" graph by default. */
132 #define UP_XINCHES 5
133 #define UP_YINCHES 3
134 /* UP_XMAX = (UP_SCREENX*UP_XINCHES)/UP_SCRXINC
135    UP_YMAX (UP_SCREENY*UP_YINCHES)/UP_SCRYINC */
136
137 #define UP_XLAST (UP_XMAX - 1)
138 #define UP_YLAST (UP_YMAX - 1)
139
140 /* These offsets center plot2ps output in the middle of the page.  The
141  * amount of resizing that can be done is limited. */
142 /*
143  * #define UP_XOFF 6454
144  * #define UP_YOFF 10601
145  */
146
147 /* These offsets give a 1" offset from the lower left corner.  This
148  * gives a greater range of permissible values in GNUPLOT's size
149  * command. */
150 #define UP_XOFF 3972
151 #define UP_YOFF 3972
152
153 enum JUSTIFY up_justify = LEFT;
154
155 #define ROTATE(angle) pl_textangle(90*angle)
156
157 static int handle_global;              /* T.Walter 1999-05-23 */
158
159 /* We don't include plot.h from plotutils because of
160  * the name clash with ../plot.h.
161  */
162 extern int pl_openpl __PROTO((void));
163 extern int pl_space __PROTO((int, int, int, int));
164 extern int pl_fontname __PROTO((const char *));
165 extern int pl_fontsize __PROTO((int));
166 extern int pl_erase __PROTO((void));
167 extern int pl_linemod __PROTO((const char *));
168 extern int pl_move __PROTO((int, int));
169 extern int pl_cont __PROTO((int, int));
170 extern int pl_alabel __PROTO((int, int, const char *));
171 extern int pl_textangle __PROTO((int));
172 extern int pl_closepl __PROTO((void));
173 /* T.Walter added: */
174 extern int pl_parampl __PROTO((const char *parameter, void *value));
175 extern int pl_newpl __PROTO((const char *type, FILE *infile, FILE *outfile, FILE *errfile));
176 extern int pl_selectpl __PROTO((int handle));
177 extern int pl_deletepl __PROTO((int handle));
178 extern double pl_ffontsize __PROTO((double size));
179
180 /* Formats supported by GNU plotutils */
181 enum PL_types {
182     PL_X, PL_PNM, PL_GIF, PL_AI, PL_PS, PL_CGM, PL_FIG, PL_PCL5,
183     PL_HPGL, PL_TEK, PL_META, PL_INVALID
184 };
185
186 struct gen_table term_up_pt_tbl[] =
187 {
188     { "X", PL_X },
189     { "pnm", PL_PNM },
190     { "gif", PL_GIF },
191     { "ai", PL_AI },
192     { "ps", PL_PS },
193     { "cgm", PL_CGM },
194     { "fig", PL_FIG },
195     { "pcl5", PL_PCL5 },
196     { "hpgl", PL_HPGL },
197     { "tek", PL_TEK },
198     { "meta", PL_META },
199     { NULL, PL_INVALID }
200 };
201
202 /* Plot type, default */
203 static int pl_plottype = PL_META;
204
205 /* Plot size, default */
206 static char pl_pagesize[MAX_ID_LEN+1] = "a4";
207
208 enum UP_id { UP_DEFAULT, UP_PAGESIZE, UP_PLOTTYPE, UP_OTHER };
209
210 static struct gen_table UP_opts[] =
211 {
212     { "d$efault", UP_DEFAULT },
213     { "s$ize", UP_PAGESIZE },
214     { "t$ype", UP_PLOTTYPE },
215     { NULL, UP_OTHER }
216 };
217
218 TERM_PUBLIC void
219 UP_options()
220 {
221     struct value a;
222
223     while (!END_OF_COMMAND) {
224         switch(lookup_table(&UP_opts[0],c_token)) {
225         case UP_DEFAULT:
226             strcpy(up_font, DEFAULT_GNUGRAPHFONT);
227             up_fontsize = 10;
228             term->v_char = (unsigned int) (up_fontsize * UP_VFONTSC);
229             term->h_char = (unsigned int) (up_fontsize * UP_HFONTSC);
230             c_token++;
231             break;
232         case UP_PAGESIZE:
233             c_token++;
234             /* user is responsible for valid page size specification, e.g.
235              * "a4", "letter", "b5", "a4,xoffset=-5mm,yoffset=2.0cm".
236              * See GNU plotutils documentation for details. */
237             quote_str(pl_pagesize, c_token, MAX_ID_LEN);
238             /* else use default quietly */
239             c_token++;
240             break;
241         case UP_PLOTTYPE:
242             c_token++;
243             pl_plottype = lookup_table(&term_up_pt_tbl[0],c_token);
244             if (pl_plottype == PL_INVALID)
245                 pl_plottype = PL_META;
246             c_token++;
247             break;
248         case UP_OTHER:
249         default:
250             if (isstring(c_token)) {
251                 quote_str(up_font, c_token, MAX_ID_LEN);
252                 c_token++;
253             }
254             if (!END_OF_COMMAND) {
255                 /* We have font size specified */
256                 up_fontsize = (int) real(const_express(&a));
257                 term->v_char = (unsigned int) (up_fontsize * UP_VFONTSC);
258                 term->h_char = (unsigned int) (up_fontsize * UP_HFONTSC);
259             }
260         }
261     }
262
263     sprintf(term_options, "\"%s\" %d size \"%s\" type %s",
264             up_font,
265             up_fontsize,
266             pl_pagesize,
267             term_up_pt_tbl[pl_plottype].key);
268 }
269
270 TERM_PUBLIC void
271 UP_init()
272 {
273 #if 1
274     pl_parampl ("PAGESIZE", pl_pagesize);
275
276     if ((handle_global = pl_newpl (term_up_pt_tbl[pl_plottype].key,
277                                    NULL, gpoutfile, stderr)) < 0) {
278         int_error(NO_CARET, "GNU plotutils (gnugraph) failed to create \"%s\" plotter.",
279                   term_up_pt_tbl[pl_plottype].key);
280     }
281
282     pl_selectpl (handle_global);         /* select the Plotter for use */
283
284     pl_openpl ();
285     pl_space (0, 0, UP_SCREENX - 1, UP_SCREENY - 1);
286     pl_fontname (up_font);
287
288     /* T.Walter: Try to find the correct font size */
289 # if 0
290     pl_fontsize (up_fontsize);  too small
291     pl_fontsize (up_fontsize*10);  too small
292     pl_fontsize (up_fontsize*100);  too large
293     pl_fontsize (up_fontsize*0.0525*GPMIN((UP_XMAX), (UP_YMAX)));  too large
294     pl_fontsize (up_fontsize/72.0*GPMIN((UP_XMAX), (UP_YMAX)));  too large
295     pl_fontsize (up_fontsize/72.0*0.0525*GPMIN((UP_XMAX), (UP_YMAX)));  too small
296     pl_fontsize (up_fontsize/72.0*0.0525*GPMIN((UP_SCREENX), (UP_SCREENY))); too small
297     pl_fontsize (up_fontsize/72.0*GPMIN((UP_SCREENX), (UP_SCREENY)));  too large
298     pl_fontsize (up_fontsize/72.0*8*0.0525*GPMIN((UP_XMAX), (UP_YMAX))); just about too large
299 # endif /* 0 */
300     pl_fontsize (up_fontsize/72.0*0.0525*GPMIN((UP_SCREENX), (UP_SCREENY)));
301
302 #else  /* Old code */
303     pl_openpl();
304     pl_space (0, 0, UP_SCREENX - 1, UP_SCREENY - 1);
305     pl_fontname (up_font);
306 #endif
307     pl_fontsize(up_fontsize);
308 }
309
310
311 TERM_PUBLIC void
312 UP_graphics()
313 {
314     pl_erase();
315 }
316
317
318 TERM_PUBLIC void
319 UP_text()
320 {
321     /* Flush here so that output will be complete. */
322     fflush(stdout);
323 }
324
325
326 TERM_PUBLIC void
327 UP_linetype(int linetype)
328 {
329     /* T.Walter, 1999-05-23 */
330     static char *lt[2+5] = { "solid", "longdashed", "solid", "dotted",
331                              "shortdashed", "dotdashed", "longdashed"};
332
333     if (linetype < -2)
334         linetype = LT_BLACK;
335
336     if (linetype >= 5)
337         linetype %= 5;
338
339     pl_linemod(lt[linetype + 2]);
340 }
341
342
343 TERM_PUBLIC void
344 UP_move(unsigned int x, unsigned int y)
345 {
346     pl_move(x + UP_XOFF, y + UP_YOFF);
347 }
348
349
350 TERM_PUBLIC void
351 UP_vector(unsigned int x, unsigned int y)
352 {
353     pl_cont(x + UP_XOFF, y + UP_YOFF);
354 }
355
356
357 TERM_PUBLIC void
358 UP_put_text(unsigned int x, unsigned int y, const char str[])
359 {
360     UP_move(x, y);              /* Don't adjust x and y! It's done in UP_move. */
361     switch (up_justify) {
362     case LEFT:
363         pl_alabel('l', 'c', str);
364         break;
365     case CENTRE:
366         pl_alabel('c', 'c', str);
367         break;
368     case RIGHT:
369         pl_alabel('r', 'c', str);
370         break;
371     }
372
373 }
374
375 TERM_PUBLIC int
376 UP_text_angle(int ang)
377 {
378     ROTATE(ang ? 1 : 0);
379     return TRUE;
380 }
381
382 TERM_PUBLIC int
383 UP_justify_text(enum JUSTIFY mode)
384 {
385     up_justify = mode;
386     return TRUE;
387 }
388
389 TERM_PUBLIC void
390 UP_reset()
391 {
392     pl_closepl();
393
394     /* T.Walter, 1999-05-23 */
395
396     pl_selectpl (0);                     /* default plotter */
397
398     if (pl_deletepl (handle_global) < 0) /* delete plotter we used above */
399         fprintf (stderr, "GNU Plotutils (gnugraph) is not able to delete Plotter\n");
400
401 }
402
403 #endif /* TERM_BODY */
404
405 #ifdef TERM_TABLE
406
407 TERM_TABLE_START(gnugraph_driver)
408     "gnugraph", "GNU plot(1) format [\042fontname\042 font_size]",
409     UP_XMAX, UP_YMAX, UP_VCHAR, UP_HCHAR,
410     UP_VTIC, UP_HTIC, UP_options, UP_init, UP_reset,
411     UP_text, null_scale, UP_graphics, UP_move, UP_vector,
412     UP_linetype, UP_put_text, UP_text_angle,
413     UP_justify_text, line_and_point, do_arrow, set_font_null
414 TERM_TABLE_END(gnugraph_driver)
415
416 #undef LAST_TERM
417 #define LAST_TERM gnugraph_driver
418
419 #endif /* TERM_TABLE */
420 #endif /* TERM_PROTO_ONLY */
421
422 #define TERM_HELP_GNUGRAPH
423 #ifdef TERM_HELP
424 START_HELP(gnugraph)
425 "1 Gnugraph(GNU plotutils)",
426 "?commands set terminal gnugraph",
427 "?set terminal gnugraph",
428 "?set term gnugraph",
429 "?terminal gnugraph",
430 "?term gnugraph",
431 "?gnugraph",
432 " The `gnugraph` driver produces device-independent output in the GNU plot",
433 " graphics language.  The default size of the PostScript results generated by",
434 " \"plot2ps\" is 5 x 3 inches; this can be increased up to about 8.25 x 8.25 by",
435 " `set size`.",
436 "",
437 " Syntax:",
438 "       set terminal gnugraph {\"<fontname>\"} {<fontsize>}",
439 "                             {type <pt>} {size \"<size>\"}",
440 "",
441 " which defaults to 10-point \"Courier\".",
442 "",
443 " For `type`, the following options are accepted: `X`, `pnm`, `gif`, `ai`,",
444 " `ps`, `cgm`, `fig`, `pcl5`, `hpgl`, `tek`, and `meta` (default). The",
445 " `size` option (default is a4) is passed straight through to plotutils, it's",
446 " the user's responsibility to provide correct values. Details can be found",
447 " in the plotutils documentation.",
448 "",
449 " Examples:",
450 "       set terminal gnugraph type hpgl size \"a4\"",
451 "       set terminal gnugraph size \"a4,xoffset=-5mm,yoffset=2.0cm\" type pnm",
452 "",
453 " There is a non-GNU version of the `gnugraph` driver which cannot be compiled",
454 " unless this version is left out."
455 END_HELP(gnugraph)
456 #endif