1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: metapost.trm,v 1.38.2.2 2008/05/31 16:08:26 sfeam Exp $
5 /* GNUPLOT - metapost.trm */
8 * Copyright 1990 - 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 * GNUPLOT -- metapost.trm
40 * This terminal driver supports:
43 * Based on metafont.trm, written by
46 * Pal.Hedne@termo.unit.no;
47 * with improvements by Carsten Steger
49 * and pstricks.trm, written by
50 * David Kotz and Raymond Toy
52 * Adapted to metapost by:
53 * Daniel H. Luecking <luecking@comp.uark.edu> and
54 * L Srinivasa Mohan <mohan@chemeng.iisc.ernet.in>
64 TERM_PUBLIC void MP_options __PROTO((void));
65 TERM_PUBLIC void MP_init __PROTO((void));
66 TERM_PUBLIC void MP_graphics __PROTO((void));
67 TERM_PUBLIC void MP_text __PROTO((void));
68 TERM_PUBLIC void MP_linetype __PROTO((int linetype));
69 TERM_PUBLIC void MP_move __PROTO((unsigned int x, unsigned int y));
70 TERM_PUBLIC void MP_point __PROTO((unsigned int x, unsigned int y, int number));
71 TERM_PUBLIC void MP_pointsize __PROTO((double size));
72 TERM_PUBLIC void MP_linewidth __PROTO((double width));
73 TERM_PUBLIC void MP_vector __PROTO((unsigned int ux, unsigned int uy));
74 TERM_PUBLIC void MP_arrow __PROTO((unsigned int sx, unsigned int sy,
75 unsigned int ex, unsigned int ey,
77 TERM_PUBLIC void MP_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
78 TERM_PUBLIC int MP_justify_text __PROTO((enum JUSTIFY mode));
79 TERM_PUBLIC int MP_text_angle __PROTO((int ang));
80 TERM_PUBLIC void MP_reset __PROTO((void));
81 TERM_PUBLIC int MP_set_font __PROTO((const char *font));
82 TERM_PUBLIC void MP_boxfill __PROTO((int style, unsigned int x1,
83 unsigned int y1, unsigned int width,
84 unsigned int height));
85 TERM_PUBLIC int MP_make_palette __PROTO((t_sm_palette *));
86 TERM_PUBLIC void MP_previous_palette __PROTO((void));
87 TERM_PUBLIC void MP_set_color __PROTO((t_colorspec *));
88 TERM_PUBLIC void MP_filled_polygon __PROTO((int, gpiPoint *));
90 /* 5 inches wide by 3 inches high (default) */
94 /* gnuplot units will be one pixel if printing device has this
95 resolution. Too small resolutions (like 300) can give rough
96 appearence to curves when user tries to smooth a curve by choosing
97 high sampling rate. */
100 #define MP_XMAX (MP_XSIZE*MP_DPI)
101 #define MP_YMAX (MP_YSIZE*MP_DPI)
103 #define MP_HTIC (5*MP_DPI/72) /* nominally 5pt */
104 #define MP_VTIC (5*MP_DPI/72) /* " 5pt */
105 #define MP_HCHAR (MP_DPI*53/10/72) /* " 5.3pt */
106 #define MP_VCHAR (MP_DPI*11/72) /* " 11pt */
107 #endif /* TERM_PROTO */
109 #ifndef TERM_PROTO_ONLY
112 static double MP_xsize = MP_XSIZE;
113 static double MP_ysize = MP_YSIZE;
114 /* static double MP_xmax = MP_XMAX;
115 static double MP_ymax = MP_YMAX;
120 static char MP_fontname[MAX_ID_LEN + 1];
121 static double MP_fontsize;
122 static double MP_textmag;
123 static enum JUSTIFY MP_justify = LEFT;
124 static int MP_ang = 0;
125 static int MP_char_code = 0;
127 /* number of nodes in an output line so far */
128 static int MP_linecount = 1;
130 /* Number of point types */
131 #define MP_POINT_TYPES 10
133 /* Number of line types */
134 #define MP_LINE_TYPES 8
136 /* are we in the middle of a MP path? */
137 static TBOOLEAN MP_inline = FALSE;
138 /* colored or dashed lines? */
139 static TBOOLEAN MP_color = FALSE;
140 static TBOOLEAN MP_solid = FALSE;
142 /* compatability mode*/
143 /* static TBOOLEAN MP_notex = FALSE; */
147 static int MP_tex = MP_TEX;
148 /* add usepackage instructions for PSNFSS ? */
149 #define MP_PSNFSS_NONE 0
150 #define MP_PSNFSS_7 1
151 #define MP_PSNFSS_8 2
152 static int MP_psnfss = MP_PSNFSS_NONE;
153 /* should amstex packages be included? */
154 static int MP_amstex = 0;
155 /* add a4paper option to documentclass */
156 static int MP_a4paper = 0;
157 /* write a prologues line */
158 static int MP_prologues = -1;
160 /* has color changed? */
161 static int MP_color_changed = 0;
163 /* has a font change taken place? */
164 static TBOOLEAN MP_fontchanged = FALSE;
167 static int MP_oldline = -2;
170 static double MP_oldptsize = 1.0;
171 static double MP_oldpen = 1.0;
173 /* terminate any path in progress */
174 static void MP_endline __PROTO((void));
176 /* max number of path nodes before a newline */
180 MP_OPT_MONOCHROME, MP_OPT_COLOUR,
181 MP_OPT_SOLID, MP_OPT_DASHED,
182 MP_OPT_NOTEX, MP_OPT_TEX, MP_OPT_LATEX,
184 MP_OPT_PSNFSS, MP_OPT_PSNFSS_V7, MP_OPT_NOPSNFSS,
186 MP_OPT_FONT, MP_OPT_FONTSIZE,
187 MP_OPT_PROLOGUES, MP_OPT_NOPROLOGUES,
188 MP_OPT_MAGNIFICATION, MP_OPT_OTHER
191 static struct gen_table MP_opts[] = {
192 { "mo$nochrome", MP_OPT_MONOCHROME },
193 { "c$olor", MP_OPT_COLOUR },
194 { "c$olour", MP_OPT_COLOUR },
195 { "s$olid", MP_OPT_SOLID },
196 { "da$shed", MP_OPT_DASHED },
197 { "n$otex", MP_OPT_NOTEX },
198 { "t$ex", MP_OPT_TEX },
199 { "la$tex", MP_OPT_LATEX },
200 { "a4$paper", MP_OPT_A4PAPER },
201 { "am$stex", MP_OPT_AMSTEX },
202 { "ps$nfss", MP_OPT_PSNFSS },
203 { "psnfss-v$ersion7", MP_OPT_PSNFSS_V7 },
204 { "nops$nfss", MP_OPT_NOPSNFSS },
205 { "pro$logues", MP_OPT_PROLOGUES },
206 { "nopro$logues", MP_OPT_NOPROLOGUES },
207 { "ma$gnification", MP_OPT_MAGNIFICATION },
208 { "fo$nt", MP_OPT_FONT },
209 { NULL, MP_OPT_OTHER }
217 /* Annoying hack to handle the case of 'set termoption' after */
218 /* we have already initialized the terminal. */
225 MP_psnfss = MP_PSNFSS_NONE;
229 strcpy(MP_fontname, "cmr10");
232 while (!END_OF_COMMAND) {
233 switch (lookup_table(&MP_opts[0], c_token)) {
234 case MP_OPT_MONOCHROME:
252 strcpy(MP_fontname, "pcrr8r");
264 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */
269 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */
274 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */
275 MP_psnfss = MP_PSNFSS_8;
278 case MP_OPT_PSNFSS_V7:
279 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */
280 MP_psnfss = MP_PSNFSS_7;
283 case MP_OPT_NOPSNFSS:
284 MP_psnfss = MP_PSNFSS_NONE;
287 case MP_OPT_PROLOGUES:
289 if (!(END_OF_COMMAND)) {
290 int dummy_for_prologues;
292 if (sscanf(gp_input_line + token[c_token].start_index,
293 "%d", &dummy_for_prologues) == 1) {
294 MP_prologues = dummy_for_prologues;
299 case MP_OPT_NOPROLOGUES:
303 case MP_OPT_MAGNIFICATION:
305 if (!END_OF_COMMAND) /* global text scaling */
306 MP_textmag = (double) real(const_express(&a));
307 /* c_token++; */ /* Needed ??? */
311 if (isstringvalue(c_token)) {
312 char *s = try_to_get_string();
313 strncpy(MP_fontname, s, sizeof(MP_fontname));
318 if (isstring(c_token)) { /* font name */
319 quote_str(MP_fontname, c_token, MAX_ID_LEN);
322 if (!END_OF_COMMAND) { /*font size */
323 MP_fontsize = (double) real(const_express(&a));
330 /* minimal error recovery: */
331 if (MP_fontsize < 5.0)
333 if (MP_fontsize > 99.99)
336 term->v_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 11 / 720);
337 if (MP_tex == MP_NO_TEX) { /* Courier is a little wider than cmtt */
338 term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 6.0 / 720 + 0.5);
340 term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 5.3 / 720 + 0.5);
343 if (MP_psnfss == MP_PSNFSS_NONE) { /* using the normal font scheme */
344 sprintf(term_options,
345 "%s %s %stex%s%s mag %.3f font \"%s\" %.2f %sprologues(%d)",
346 MP_color ? "color" : "monochrome",
347 MP_solid ? "solid" : "dashed",
348 (MP_tex == MP_NO_TEX) ? "no" : (MP_tex == MP_LATEX) ? "la" : "",
349 MP_a4paper ? " a4paper" : "",
350 MP_amstex ? " amstex" : "",
352 MP_fontname, MP_fontsize,
353 (MP_prologues > -1) ? "" : "no", MP_prologues );
354 } else { /* using postscript fonts */
355 sprintf(term_options,
356 "%s %s %stex%s%s mag %.3f %s %sprologues(%d)",
357 MP_color ? "color" : "monochrome",
358 MP_solid ? "solid" : "dashed",
359 (MP_tex == MP_NO_TEX) ? "no" : (MP_tex == MP_LATEX) ? "la" : "",
360 MP_a4paper ? " a4paper" : "",
361 MP_amstex ? " amstex" : "",
363 (MP_psnfss == MP_PSNFSS_7) ? "psnsfss(v7)" : "psnsfss",
364 (MP_prologues > -1) ? "" : "no", MP_prologues );
373 MP_posx = MP_posy = 0;
374 fprintf(gpoutfile, "%%GNUPLOT Metapost output: %s\n", asctime(localtime(&now)));
375 if (MP_prologues > -1) {
376 fprintf(gpoutfile, "prologues:=%d;\n", MP_prologues);
378 if (MP_tex == MP_LATEX) {
380 %% Add \\documentclass and \\begin{dcoument} for latex\n\
381 %% NB you should set the environment variable TEX to the name of your\n\
382 %% latex executable (normally latex) inorder for metapost to work\n\
384 %% mpost --tex=latex ...\n\
387 verbatimtex\n", gpoutfile);
389 fputs("\\documentclass[a4paper]{article}\n", gpoutfile);
391 fputs("\\documentclass{article}\n", gpoutfile);
395 fputs("\\usepackage[latin1]{inputenc}\n\
396 \\usepackage[T1]{fontenc}\n\
397 \\usepackage{times,mathptmx}\n\
398 \\usepackage{helvet}\n\
399 \\usepackage{courier}\n", gpoutfile);
403 fputs("\\usepackage[latin1]{inputenc}\n\
404 \\usepackage[T1]{fontenc}\n\
405 \\usepackage{textcomp}\n\
406 \\usepackage{mathptmx}\n\
407 \\usepackage[scaled=.92]{helvet}\n\
408 \\usepackage{courier}\n\
409 \\usepackage{latexsym}\n", gpoutfile);
414 fputs("\\usepackage[intlimits]{amsmath}\n\
415 \\usepackage{amsfonts}\n", gpoutfile);
417 fputs("\\begin{document}\n\
418 etex\n% ENDPRE\n", gpoutfile);
423 defaultmpt:=mpt:=4;\n\
425 %% Have nice sharp joins on our lines\n\
427 linejoin:=mitered;\n\
429 def scalepen expr n = pickup pencircle scaled (n*th) enddef;\n\
430 def ptsize expr n = mpt:=n*defaultmpt enddef;\n\
433 fprintf(gpoutfile, "\ntextmag:=%6.3f;\n", MP_textmag);
436 vardef makepic(expr str) =\n\
437 if picture str : str scaled textmag\n\
438 % otherwise a string\n\
439 else: str infont defaultfont scaled (defaultscale*textmag)\n\
443 def infontsize(expr str, size) =\n\
444 infont str scaled (size / fontsize str)\n\
445 enddef;\n", gpoutfile);
447 if (MP_tex == MP_NO_TEX) {
448 fprintf(gpoutfile, "\n\
449 defaultfont:= \"%s\";\n\
450 defaultscale := %6.3f/fontsize defaultfont;\n", MP_fontname, MP_fontsize);
452 if (MP_tex != MP_LATEX) {
456 \\def\\setfont#1#2{%.\n\
457 \\font\\gpfont=#1 at #2pt\n\
458 \\gpfont}\n", gpoutfile);
459 fprintf(gpoutfile, "\\setfont{%s}{%5.2f}\netex\n",
460 MP_fontname, MP_fontsize);
464 color currentcolor; currentcolor:=black;\n\
466 boolean colorlines,dashedlines;\n", gpoutfile);
468 fputs("colorlines:=true;\n", gpoutfile);
470 fputs("colorlines:=false;\n", gpoutfile);
473 fputs("dashedlines:=false;\n", gpoutfile);
475 fputs("dashedlines:=true;\n", gpoutfile);
478 def _wc = withpen currentpen withcolor currentcolor enddef;\n\
479 def _ac = addto currentpicture enddef;\n\
480 def _sms = scaled mpt shifted enddef;\n\
481 % drawing point-types\n\
482 def gpdraw (expr n, x, y) =\n\
483 if n<0: _ac contour fullcircle _sms (x,y)\n\
484 elseif (n=1) or (n=3):\n\
485 _ac doublepath ptpath[n] _sms (x,y) _wc;\n\
486 _ac doublepath ptpath[n] rotated 90 _sms (x,y) _wc\n\
487 elseif n<6: _ac doublepath ptpath[n] _sms (x,y) _wc\n\
488 else: _ac contour ptpath[n] _sms (x,y) _wc\n\
492 % the point shapes\n\
495 ptpath0 = ptpath6 = (-1/2,0)--(0,-1/2)--(1/2,0)--(0,1/2)--cycle;\n\
497 ptpath1 = (-1/2,0)--(1/2,0);\n\
499 ptpath2 = ptpath7 = (-1/2,-1/2)--(1/2,-1/2)--(1/2,1/2)--(-1/2,1/2)--cycle;\n\
501 ptpath3 := (-1/2,-1/2)--(1/2,1/2);\n\
503 ptpath4 = ptpath8:= fullcircle;\n\
505 ptpath5 = ptpath9 := (0,1/2)--(-1/2,-1/2)--(1/2,-1/2)--cycle;\n\
507 def linetype expr n =\n\
508 currentcolor:= if colorlines : col[n] else: black fi;\n\
510 drawoptions(withcolor currentcolor withpen (currentpen scaled .5));\n\
514 drawoptions( if dashedlines: dashed lt[n] fi _wc);\n\
520 lt1=dashpattern(on 2 off 2); % dashes\n\
521 lt2=dashpattern(on 2 off 2 on 0.2 off 2); %dash-dot\n\
522 lt3=lt1 scaled 1.414;\n\
523 lt4=lt2 scaled 1.414;\n\
525 lt6:=lt2 scaled 2;\n\
526 lt7=dashpattern(on 0.2 off 2); %dots\n\
528 color col[],cyan, magenta, yellow;\n\
529 cyan=blue+green; magenta=red+blue;yellow=green+red;\n\
530 col[-2]:=col[-1]:=col0:=black;\n\
532 col2:=(.2,.2,1); %blue\n\
533 col3:=(1,.66,0); %orange\n\
541 def put_text(expr pic, x, y, r, j) =\n\
542 GPtext:=makepic(pic);\n\
543 GPtext:=GPtext shifted\n\
544 if j = 1: (-(ulcorner GPtext + llcorner GPtext)/2)\n\
545 elseif j = 2: (-center GPtext)\n\
546 else: (-(urcorner GPtext + lrcorner GPtext)/2)\n\
549 draw GPtext shifted (x,y)\n\
550 enddef;\n", gpoutfile);
556 /* initialize "remembered" drawing parameters */
559 MP_oldptsize = pointsize;
560 fprintf(gpoutfile, "\nbeginfig(%d);\nw:=%.3fin;h:=%.3fin;\n",
561 MP_char_code, MP_xsize, MP_ysize);
562 /* MetaPost can only handle numbers up to 4096. When MP_DPI
563 * is larger than 819, this is exceeded by (term->xmax). So we
564 * scale it and all coordinates down by factor of 10.0. And
565 * compensate by scaling a and b up.
567 fprintf(gpoutfile, "a:=w/%.1f;b:=h/%.1f;\n",
568 (term->xmax) / 10.0, (term->ymax) / 10.0);
569 fprintf(gpoutfile, "scalepen 1; ptsize %.3f;linetype -2;\n", pointsize);
571 /* reset MP_color_changed */
572 MP_color_changed = 0;
580 fputs("endfig;\n", gpoutfile);
588 if (linetype >= MP_LINE_TYPES)
589 linetype %= MP_LINE_TYPES;
592 /* reset the color in case it has been changed in MP_set_color() */
593 if (MP_color_changed) {
594 MP_oldline = linetype + 1;
595 MP_color_changed = 0;
597 if (MP_oldline != linetype) {
598 fprintf(gpoutfile, "linetype %d;\n", linetype);
599 MP_oldline = linetype;
604 MP_move(unsigned int x, unsigned int y)
606 if ((x != MP_posx) || (y != MP_posy)) {
611 } /* else we seem to be there already */
615 MP_point(unsigned int x, unsigned int y, int pt)
621 /* Print the shape defined by 'number'; number < 0 means
622 to use a dot, otherwise one of the defined points. */
624 if (pointtype >= MP_POINT_TYPES)
625 pointtype %= MP_POINT_TYPES;
626 /* Change %d to %f, divide x,y by 10 */
627 fprintf(gpoutfile, "gpdraw(%d,%.1fa,%.1fb);\n", pointtype, x / 10.0, y / 10.0);
631 MP_pointsize(double ps)
635 if (MP_oldptsize != ps) {
638 fprintf(gpoutfile, "ptsize %.3f;\n", ps);
645 MP_linewidth(double lw)
647 if (MP_oldpen != lw) {
650 fprintf(gpoutfile, "scalepen %.3f;\n", lw);
657 MP_vector(unsigned int ux, unsigned int uy)
659 if ((ux == MP_posx) && (uy == MP_posy))
660 return; /* Zero length line */
663 if (MP_linecount++ >= MP_LINEMAX) {
664 fputs("\n", gpoutfile);
669 fprintf(gpoutfile, "draw (%.1fa,%.1fb)", MP_posx / 10.0, MP_posy / 10.0);
674 fprintf(gpoutfile, "--(%.1fa,%.1fb)", MP_posx / 10.0, MP_posy / 10.0);
681 fprintf(gpoutfile, ";\n");
685 MP_arrow(unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, int head)
689 fprintf(gpoutfile, "%s (%.1fa,%.1fb)--(%.1fa,%.1fb);\n",
690 head == 1 ? "drawarrow" : "drawdblarrow",
691 sx / 10.0, sy / 10.0, ex / 10.0, ey / 10.0);
692 } else if ((sx != ex) || (sy != ey)) {
693 fprintf(gpoutfile, "draw (%.1fa,%.1fb)--(%.1fa,%.1fb);\n",
694 sx / 10.0, sy / 10.0, ex / 10.0, ey / 10.0);
695 } /* else: arrow with no length and no head = sound of one hand clapping? */
702 MP_put_text(unsigned int x, unsigned int y, const char str[])
707 /* ignore empty strings */
711 /* F***. why do drivers need to modify string args? */
712 text = gp_strdup(str);
718 switch (MP_justify) {
729 if (MP_tex == MP_NO_TEX) {
730 for (i = 0; i < strlen(text); i++)
732 text[i] = '\''; /* Replace " with ' */
733 if (MP_fontchanged) {
734 fprintf(gpoutfile, "\
735 put_text(\"%s\" infontsize(\"%s\",%5.2f), %.1fa, %.1fb, %d, %d);\n",
736 text, MP_fontname, MP_fontsize,
737 x / 10.0, y / 10.0, MP_ang, j);
739 fprintf(gpoutfile, "put_text(\"%s\", %.1fa, %.1fb, %d, %d);\n",
740 text, x / 10.0, y / 10.0, MP_ang, j);
742 } else if (MP_fontchanged) {
743 if (MP_tex != MP_LATEX) {
744 fprintf(gpoutfile, "\
745 put_text( btex \\setfont{%s}{%5.2f} %s etex, %.1fa, %.1fb, %d, %d);\n",
746 MP_fontname, MP_fontsize, text,
747 x / 10.0, y / 10.0, MP_ang, j);
749 fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n",
750 text, x / 10.0, y / 10.0, MP_ang, j);
753 fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n",
754 text, x / 10.0, y / 10.0, MP_ang, j);
761 MP_justify_text(enum JUSTIFY mode)
768 MP_text_angle(int ang)
770 /* Metapost code does the conversion */
776 MP_set_font(const char *font)
779 size_t sep = strcspn(font, ",");
780 strncpy(MP_fontname, font, sep);
781 MP_fontname[sep] = NUL;
782 sscanf(&(font[sep + 1]), "%lf", &MP_fontsize);
785 if (MP_fontsize >= 100)
788 MP_fontchanged = TRUE;
790 MP_fontchanged = FALSE;
799 if (MP_tex == MP_LATEX) {
800 fputs("% BEGPOST\n",gpoutfile);
801 fputs("verbatimtex\n",gpoutfile);
802 fputs(" \\end{document}\n",gpoutfile);
803 fputs("etex\n",gpoutfile);
804 fputs("% ENDPOST\n",gpoutfile);
806 fputs("end.\n", gpoutfile);
812 unsigned int x1, unsigned int y1,
813 unsigned int wd, unsigned int ht)
817 * - solid : 0 - 100% intensity
818 * - pattern : 0 - n pattern number
820 int fillpar = style >> 4;
828 case FS_EMPTY: /* fill with background color */
829 fprintf(gpoutfile, "\
830 fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withcolor background;\n",
831 x1 / 10.0, y1 / 10.0, (x1 + wd) / 10.0, y1 / 10.0,
832 (x1 + wd) / 10.0, (y1 + ht) / 10.0, x1 / 10.0,
836 case FS_PATTERN: /* pattern fill */
837 /* FIXME: not yet implemented, dummy it up as fill density */
841 case FS_SOLID: /* solid fill */
843 double density = (100-fillpar) * 0.01;
844 fprintf(gpoutfile,"fillcolor:=currentcolor*%.2f+background*%.2f;\n",
845 1.0-density, density);
846 MP_color_changed = 1;
848 fprintf(gpoutfile,"fillcolor:=currentcolor;\n");
849 fprintf(gpoutfile, "\
850 fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withpen (pencircle scaled 0pt) withcolor fillcolor;\n",
851 x1 / 10.0, y1 / 10.0, (x1 + wd) / 10.0, y1 / 10.0,
852 (x1 + wd) / 10.0, (y1 + ht) / 10.0, x1 / 10.0,
861 MP_make_palette(t_sm_palette *palette)
863 /* metapost can do continuous number of colours */
869 MP_set_color(t_colorspec *colorspec)
871 double gray = colorspec->value;
874 /* remeber that we changed the color, needed to reset color in MP_linetype()*/
875 MP_color_changed = 1;
880 if (!MP_color) { /* gray mode */
881 if (gray < 1e-3) gray = 0;
882 fprintf(gpoutfile, "currentcolor:=%.3gwhite;\n", gray);
883 } else { /* color mode */
884 if (colorspec->type == TC_LT) {
885 int linecolor = colorspec->lt;
886 if (linecolor >= MP_LINE_TYPES)
887 linecolor %= MP_LINE_TYPES;
889 fprintf(gpoutfile, "currentcolor:=black;\n");
890 else if (linecolor >= 0)
891 fprintf(gpoutfile, "currentcolor:=col%d;\n",linecolor);
893 if (colorspec->type == TC_FRAC) {
894 if (sm_palette.colors != 0) /* finite nb of colors explicitly requested */
895 gray = (gray >= ((double)(sm_palette.colors-1)) / sm_palette.colors) ?
896 1 : floor(gray * sm_palette.colors) / sm_palette.colors;
897 rgb1_from_gray( gray, &color );
898 } else if (colorspec->type == TC_RGB) {
899 color.r = (double)((colorspec->lt >> 16 ) & 255) / 255.;
900 color.g = (double)((colorspec->lt >> 8 ) & 255) / 255.;
901 color.b = (double)(colorspec->lt & 255) / 255.;
905 if (color.r < 1e-4) color.r = 0;
906 if (color.g < 1e-4) color.g = 0;
907 if (color.b < 1e-4) color.b = 0;
908 fprintf(gpoutfile, "currentcolor:=%.4g*red+%.4g*green+%.4g*blue;\n",
909 color.r, color.g, color.b);
915 MP_filled_polygon(int points, gpiPoint *corners)
918 int fillpar = corners->style >> 4;
919 int style = corners->style & 0xf;
925 case FS_EMPTY: /* fill with background color */
926 fprintf(gpoutfile,"fillcolor:=background;\n");
928 case FS_PATTERN: /* pattern fill implemented as partial density */
930 case FS_SOLID: /* solid fill */
932 double density = (100-fillpar) * 0.01;
933 fprintf(gpoutfile,"fillcolor:=currentcolor*%.2f+background*%.2f;\n",
934 1.0-density, density);
936 fprintf(gpoutfile,"fillcolor:=currentcolor;\n");
942 fprintf(gpoutfile, "fill ");
943 for (i = 0; i < points; i++)
944 fprintf(gpoutfile, "(%.1fa,%.1fb)%s",
945 corners[i].x / 10.0, corners[i].y / 10.0,
946 (i < points - 1 && (i + 1) % MP_LINEMAX == 0) ? "\n--" : "--");
947 fprintf(gpoutfile, "cycle withcolor fillcolor;\n");
951 MP_previous_palette()
956 #endif /* TERM_BODY */
960 TERM_TABLE_START(mp_driver)
961 "mp", "MetaPost plotting standard",
962 MP_XMAX, MP_YMAX, MP_VCHAR, MP_HCHAR,
963 MP_VTIC, MP_HTIC, MP_options, MP_init, MP_reset,
964 MP_text, null_scale, MP_graphics, MP_move, MP_vector,
965 MP_linetype, MP_put_text, MP_text_angle,
966 MP_justify_text, MP_point, MP_arrow, MP_set_font, MP_pointsize,
967 TERM_BINARY|TERM_CAN_CLIP /*flags*/,
968 0, 0, MP_boxfill, MP_linewidth
970 , 0, 0, 0, 0, 0 /* no mouse support for metapost */
973 MP_previous_palette, /* write grestore */
976 TERM_TABLE_END(mp_driver)
978 #define LAST_TERM mp_driver
980 #endif /* TERM_TABLE */
981 #endif /* TERM_PROTO_ONLY */
986 "?commands set terminal mpost",
994 " The `mp` driver produces output intended to be input to the Metapost program.",
995 " Running Metapost on the file creates EPS files containing the plots. By",
996 " default, Metapost passes all text through TeX. This has the advantage of",
997 " allowing essentially any TeX symbols in titles and labels.",
1000 " set term mp {color | colour | monochrome}",
1001 " {solid | dashed}",
1002 " {notex | tex | latex}",
1003 " {magnification <magsize>}",
1004 " {psnfss | psnfss-version7 | nopsnfss}",
1005 " {prologues <value>}",
1008 " {\"<fontname>\"} {<fontsize>}",
1010 " The option `color` causes lines to be drawn in color (on a printer or display",
1011 " that supports it), `monochrome` (or nothing) selects black lines. The option",
1012 " `solid` draws solid lines, while `dashed` (or nothing) selects lines with",
1013 " different patterns of dashes. If `solid` is selected but `color` is not,",
1014 " nearly all lines will be identical. This may occasionally be useful, so it is",
1017 " The option `notex` bypasses TeX entirely, therefore no TeX code can be used in",
1018 " labels under this option. This is intended for use on old plot files or files",
1019 " that make frequent use of common characters like `$` and `%` that require",
1020 " special handling in TeX.",
1022 " The option `tex` sets the terminal to output its text for TeX to process.",
1024 " The option `latex` sets the terminal to output its text for processing by",
1025 " LaTeX. This allows things like \\frac for fractions which LaTeX knows about",
1026 " but TeX does not. Note that you must set the environment variable TEX to the",
1027 " name of your LaTeX executable (normally latex) if you use this option or use",
1028 " `mpost --tex=<name of LaTeX executable> ...`. Otherwise metapost will try and",
1029 " use TeX to process the text and it won't work.",
1031 " Changing font sizes in TeX has no effect on the size of mathematics, and there",
1032 " is no foolproof way to make such a change, except by globally setting a",
1033 " magnification factor. This is the purpose of the `magnification` option. It",
1034 " must be followed by a scaling factor. All text (NOT the graphs) will be scaled",
1035 " by this factor. Use this if you have math that you want at some size other",
1036 " than the default 10pt. Unfortunately, all math will be the same size, but see",
1037 " the discussion below on editing the MP output. `mag` will also work under",
1038 " `notex` but there seems no point in using it as the font size option (below)",
1041 " The option `psnfss` uses postscript fonts in combination with LaTeX. Since",
1042 " this option only makes sense, if LaTeX is being used, the `latex` option is selected",
1043 " automatically. This option includes the following packages for LaTeX:",
1044 " inputenc(latin1), fontenc(T1), mathptmx, helvet(scaled=09.2), courier, latexsym ",
1047 " The option `psnfss-version7` uses also postscript fonts in LaTeX (option `latex`",
1048 " is also automatically selected), but uses the following packages with LaTeX:",
1049 " inputenc(latin1), fontenc(T1), times, mathptmx, helvet and courier.",
1051 " The option `nopsnfss` is the default and uses the standard font (cmr10 if not",
1052 " otherwise specified).",
1054 " The option `prologues` takes a value as an additional argument and adds the line",
1055 " `prologues:=<value>` to the metapost file. If a value of `2` is specified metapost",
1056 " uses postscript fonts to generate the eps-file, so that the result can be viewed",
1057 " using e.g. ghostscript. Normally the output of metapost uses TeX fonts and therefore",
1058 " has to be included in a (La)TeX file before you can look at it.",
1060 " The option `noprologues` is the default. No additional line specifying the prologue",
1063 " The option `a4paper` adds a `[a4paper]` to the documentclass. Normally letter paper",
1064 " is used (default). Since this option is only used in case of LaTeX, the `latex` option",
1065 " is selected automatically.",
1067 " The option `amstex` automatically selects the `latex` option and includes the following",
1068 " LaTeX packages: amsfonts, amsmath(intlimits). By default these packages are not",
1071 " A name in quotes selects the font that will be used when no explicit font is",
1072 " given in a `set label` or `set title`. A name recognized by TeX (a TFM file",
1073 " exists) must be used. The default is \"cmr10\" unless `notex` is selected,",
1074 " then it is \"pcrr8r\" (Courier). Even under `notex`, a TFM file is needed by",
1075 " Metapost. The file `pcrr8r.tfm` is the name given to Courier in LaTeX's psnfss",
1076 " package. If you change the font from the `notex` default, choose a font that",
1077 " matches the ASCII encoding at least in the range 32-126. `cmtt10` almost",
1078 " works, but it has a nonblank character in position 32 (space).",
1080 " The size can be any number between 5.0 and 99.99. If it is omitted, 10.0 is",
1081 " used. It is advisable to use `magstep` sizes: 10 times an integer or",
1082 " half-integer power of 1.2, rounded to two decimals, because those are the most",
1083 " available sizes of fonts in TeX systems.",
1085 " All the options are optional. If font information is given, it must be at the",
1086 " end, with size (if present) last. The size is needed to select a size for the",
1087 " font, even if the font name includes size information. For example,",
1088 " `set term mp \"cmtt12\"` selects cmtt12 shrunk to the default size 10. This",
1089 " is probably not what you want or you would have used cmtt10.",
1091 " The following common ascii characters need special treatment in TeX:",
1092 " $, &, #, %, _; |, <, >; ^, ~, \\, {, and }",
1093 " The five characters $, #, &, _, and % can simply be escaped, e.g., `\\$`.",
1094 " The three characters <, >, and | can be wrapped in math mode, e.g., `$<$`.",
1095 " The remainder require some TeX work-arounds. Any good book on TeX will give",
1098 " If you type your labels inside double quotes, backslashes in TeX code need to",
1099 " be escaped (doubled). Using single quotes will avoid having to do this, but",
1100 " then you cannot use `\\n` for line breaks. As of this writing, version 3.7 of",
1101 " gnuplot processes titles given in a `plot` command differently than in other",
1102 " places, and backslashes in TeX commands need to be doubled regardless of the",
1103 " style of quotes.",
1105 " Metapost pictures are typically used in TeX documents. Metapost deals with",
1106 " fonts pretty much the same way TeX does, which is different from most other",
1107 " document preparation programs. If the picture is included in a LaTeX document",
1108 " using the graphics package, or in a plainTeX document via epsf.tex, and then",
1109 " converted to PostScript with dvips (or other dvi-to-ps converter), the text in",
1110 " the plot will usually be handled correctly. However, the text may not appear",
1111 " if you send the Metapost output as-is to a PostScript interpreter.",
1113 "2 Metapost Instructions",
1114 "?commands set terminal mp detailed",
1115 "?set terminal mp detailed",
1116 "?set term mp detailed",
1118 "?metapost detailed",
1120 " - Set your terminal to Metapost, e.g.:",
1121 " set terminal mp mono \"cmtt12\" 12",
1123 " - Select an output-file, e.g.:",
1124 " set output \"figure.mp\"",
1126 " - Create your pictures. Each plot (or multiplot group) will generate a",
1127 " separate Metapost beginfig...endfig group. Its default size will be 5 by 3",
1128 " inches. You can change the size by saying `set size 0.5,0.5` or whatever",
1129 " fraction of the default size you want to have.",
1133 " - Generate EPS files by running Metapost on the output of gnuplot:",
1134 " mpost figure.mp OR mp figure.mp",
1135 " The name of the Metapost program depends on the system, typically `mpost` for",
1136 " a Unix machine and `mp` on many others. Metapost will generate one EPS file",
1137 " for each picture.",
1139 " - To include your pictures in your document you can use the graphics package",
1140 " in LaTeX or epsf.tex in plainTeX:",
1141 " \\usepackage{graphics} % LaTeX",
1142 " \\input epsf.tex % plainTeX",
1143 " If you use a driver other than dvips for converting TeX DVI output to PS, you",
1144 " may need to add the following line in your LaTeX document:",
1145 " \\DeclareGraphicsRule{*}{eps}{*}{}",
1146 " Each picture you made is in a separate file. The first picture is in, e.g.,",
1147 " figure.0, the second in figure.1, and so on.... To place the third picture in",
1148 " your document, for example, all you have to do is:",
1149 " \\includegraphics{figure.2} % LaTeX",
1150 " \\epsfbox{figure.2} % plainTeX",
1152 " The advantage, if any, of the mp terminal over a postscript terminal is",
1153 " editable output. Considerable effort went into making this output as clean as",
1154 " possible. For those knowledgeable in the Metapost language, the default line",
1155 " types and colors can be changed by editing the arrays `lt[]` and `col[]`.",
1156 " The choice of solid vs dashed lines, and color vs black lines can be change by",
1157 " changing the values assigned to the booleans `dashedlines` and `colorlines`.",
1158 " If the default `tex` option was in effect, global changes to the text of",
1159 " labels can be achieved by editing the `vebatimtex...etex` block. In",
1160 " particular, a LaTeX preamble can be added if desired, and then LaTeX's",
1161 " built-in size changing commands can be used for maximum flexibility. Be sure",
1162 " to set the appropriate MP configuration variable to force Metapost to run",
1163 " LaTeX instead of plainTeX."
1165 #endif /* TERM_HELP */