[BACK]Return to metapost.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/metapost.trm, Revision 1.1.1.2

1.1       maekawa     1: /*
1.1.1.2 ! ohara       2:  * $Id: metapost.trm,v 1.5.2.8 2002/10/15 19:29:18 lhecking Exp $
1.1       maekawa     3:  */
                      4:
                      5: /* GNUPLOT - metapost.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: /* 1999/04/22
                     38:  *                     GNUPLOT -- metapost.trm
                     39:  *
                     40:  *                     This terminal driver supports:
                     41:  *                             Metapost Commands
                     42:  *
                     43:  * Based on metafont.trm, written by
                     44:  *             Pl Hedne
                     45:  *             Trondheim, Norway
                     46:  *             Pal.Hedne@termo.unit.no;
                     47:  *             with improvements by Carsten Steger
                     48:  *
                     49:  * and pstricks.trm, written by
                     50:  *             David Kotz and Raymond Toy
                     51:  *
                     52:  * Adapted to metapost by:
                     53:  *             Daniel H. Luecking <luecking@comp.uark.edu> and
                     54:  *             L Srinivasa Mohan <mohan@chemeng.iisc.ernet.in>
                     55:  */
                     56:
                     57: #include "driver.h"
                     58:
                     59: #ifdef TERM_REGISTER
                     60: register_term(mp)
                     61: #endif
                     62:
                     63: #ifdef TERM_PROTO
                     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,
                     76:                                   TBOOLEAN head));
                     77: TERM_PUBLIC void MP_put_text __PROTO((unsigned int x, unsigned int y, 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((char *font));
                     82: TERM_PUBLIC void MP_boxfill __PROTO((int style,
                     83:                                     unsigned int x1, unsigned int y1,
                     84:                                     unsigned int width, unsigned int height));
                     85:
                     86: /* 5 inches wide by 3 inches high (default) */
                     87: #define MP_XSIZE 5.0
                     88: #define MP_YSIZE 3.0
                     89:
                     90: /* gnuplot units will be one pixel if printing device has this
1.1.1.2 ! ohara      91:    resolution. Too small resolutions (like 300) can give rough
        !            92:    appearence to curves when user tries to smooth a curve by choosing
        !            93:    high sampling rate. */
        !            94: #define MP_DPI (2400)
1.1       maekawa    95:
                     96: #define MP_XMAX (MP_XSIZE*MP_DPI)
                     97: #define MP_YMAX (MP_YSIZE*MP_DPI)
                     98:
                     99: #define MP_HTIC (5*MP_DPI/72)  /* nominally 5pt   */
                    100: #define MP_VTIC (5*MP_DPI/72)  /*    "      5pt   */
                    101: #define MP_HCHAR (MP_DPI*53/10/72)     /*    "      5.3pt */
                    102: #define MP_VCHAR (MP_DPI*11/72)        /*    "      11pt  */
                    103: #endif /* TERM_PROTO */
                    104:
                    105: #ifndef TERM_PROTO_ONLY
                    106: #ifdef TERM_BODY
                    107:
                    108: static double MP_xsize = MP_XSIZE;
                    109: static double MP_ysize = MP_YSIZE;
                    110: /* static double MP_xmax = MP_XMAX;
                    111:    static double MP_ymax = MP_YMAX;
                    112:  * unused, for now
                    113:  */
                    114: static int MP_posx;
                    115: static int MP_posy;
                    116: static char MP_fontname[MAX_ID_LEN + 1];
                    117: static double MP_fontsize;
                    118: static double MP_textmag;
                    119: enum JUSTIFY MP_justify = LEFT;
                    120: static int MP_ang = 0;
                    121: static int MP_char_code = 0;
                    122:
                    123: /* number of nodes in an output line so far */
                    124: static int MP_linecount = 1;
                    125:
                    126: /* Number of point types */
                    127: #define MP_POINT_TYPES 10
                    128:
                    129: /* Number of line types */
                    130: #define MP_LINE_TYPES 8
                    131:
                    132: /* are we in the middle of a MP path? */
                    133: static TBOOLEAN MP_inline = FALSE;
                    134: /* colored or dashed lines? */
                    135: static TBOOLEAN MP_color = FALSE;
                    136: static TBOOLEAN MP_solid = FALSE;
                    137:
                    138: /* compatability mode*/
1.1.1.2 ! ohara     139: /* static TBOOLEAN MP_notex = FALSE; */
        !           140: #define MP_NO_TEX 0
        !           141: #define MP_TEX 1
        !           142: #define MP_LATEX 2
        !           143: static int MP_tex = MP_TEX;
        !           144: /* add usepackage instructions for PSNFSS ? */
        !           145: #define MP_PSNFSS_NONE 0
        !           146: #define MP_PSNFSS_7    1
        !           147: #define MP_PSNFSS_8    2
        !           148: static int MP_psnfss = MP_PSNFSS_NONE;
        !           149: /* add a4paper option to documentclass */
        !           150: static int MP_a4paper = 0;
        !           151: /* write a prologues line */
        !           152: static int MP_prologues = -1;
1.1       maekawa   153: /* has a font change taken place? */
                    154: static TBOOLEAN MP_fontchanged = FALSE;
                    155:
                    156: /* The old types */
                    157: static int MP_oldline = -2;
                    158:
                    159: /* The old sizes */
                    160: static double MP_oldptsize = 1.0;
                    161: static double MP_oldpen = 1.0;
                    162:
                    163: /* terminate any path in progress */
                    164: static void MP_endline __PROTO((void));
                    165:
                    166: /* max number of path nodes before a newline */
                    167: #define MP_LINEMAX 5
                    168:
                    169: TERM_PUBLIC void
                    170: MP_options()
                    171: {
                    172:     MP_color = FALSE;
                    173:     MP_solid = FALSE;
1.1.1.2 ! ohara     174: /*    MP_notex = FALSE;*/
        !           175:     MP_tex = MP_TEX;
        !           176:     MP_a4paper = 0;
        !           177:     MP_psnfss  = MP_PSNFSS_NONE;
1.1       maekawa   178:     MP_fontsize = 10.0;
                    179:     MP_textmag = 1.0;
1.1.1.2 ! ohara     180:     MP_prologues = -1;
1.1       maekawa   181:     strcpy(MP_fontname, "cmr10");
                    182:     strcpy(default_font, "");  /* output file will store default font info */
                    183:     while (!END_OF_COMMAND) {
1.1.1.2 ! ohara     184:        if (almost_equals(c_token, "mo$nochrome")) {
1.1       maekawa   185:            MP_color = FALSE;
                    186:            c_token++;
                    187:            continue;
                    188:        }
                    189:        if (almost_equals(c_token, "c$olor") || almost_equals(c_token, "c$olour")) {
                    190:            MP_color = TRUE;
                    191:            c_token++;
                    192:            continue;
                    193:        }
                    194:        if (almost_equals(c_token, "s$olid")) {
                    195:            MP_solid = TRUE;
                    196:            c_token++;
                    197:            continue;
                    198:        }
                    199:        if (almost_equals(c_token, "da$shed")) {
                    200:            MP_solid = FALSE;
                    201:            c_token++;
                    202:            continue;
                    203:        }
                    204:        if (almost_equals(c_token, "n$otex")) {
1.1.1.2 ! ohara     205: /*         MP_notex = TRUE;*/
        !           206:             MP_tex = MP_NO_TEX;
1.1       maekawa   207:            strcpy(MP_fontname, "pcrr8r");
                    208:            c_token++;
                    209:            continue;
                    210:        }
                    211:        if (almost_equals(c_token, "t$ex")) {
1.1.1.2 ! ohara     212:            MP_tex = MP_TEX;
1.1       maekawa   213:            c_token++;
                    214:            continue;
                    215:        }
1.1.1.2 ! ohara     216:        if (almost_equals(c_token, "la$tex")) {
        !           217:            MP_tex = MP_LATEX;
        !           218:             c_token++;
        !           219:            continue;
        !           220:        }
        !           221:        if (almost_equals(c_token, "a4$paper")) {
        !           222:          MP_a4paper = 1;
        !           223:          c_token++;
        !           224:          continue;
        !           225:        }
        !           226:        if(almost_equals(c_token, "ps$nfss")) {
        !           227:          MP_psnfss = MP_PSNFSS_8;
        !           228:          c_token++;
        !           229:          continue;
        !           230:        }
        !           231:        if(almost_equals(c_token, "psnfss-v$ersion7")) {
        !           232:          MP_psnfss = MP_PSNFSS_7;
        !           233:          c_token++;
        !           234:          continue;
        !           235:        }
        !           236:        if(almost_equals(c_token, "nops$nfss")) {
        !           237:          MP_psnfss = MP_PSNFSS_NONE;
        !           238:          c_token++;
        !           239:          continue;
        !           240:        }
1.1       maekawa   241:        if (almost_equals(c_token, "de$fault")) {
                    242:            c_token++;
                    243:            continue;
                    244:        }
1.1.1.2 ! ohara     245:        if (almost_equals(c_token, "pro$logues")) {
        !           246:          int dummy_for_prologues;
        !           247:          c_token++;
        !           248:          if(!(END_OF_COMMAND)) {
        !           249:            if(sscanf(&(input_line[token[c_token].start_index]), "%d", &dummy_for_prologues) == 1) {
        !           250:              MP_prologues = dummy_for_prologues;
        !           251:            }
        !           252:            c_token++;
        !           253:          }
        !           254:          continue;
        !           255:        }
        !           256:        if (almost_equals(c_token, "nopro$logues")) {
        !           257:          MP_prologues = -1;
        !           258:          c_token++;
        !           259:          continue;
        !           260:        }
        !           261:        if (almost_equals(c_token, "ma$gnification")) {
1.1       maekawa   262:            c_token++;
                    263:            if (!END_OF_COMMAND) {      /* global text scaling */
                    264:                struct value a;
                    265:                MP_textmag = (double) real(const_express(&a));
                    266:            }
                    267:            c_token++;
                    268:            continue;
                    269:        }
                    270:        break;
                    271:     }
                    272:     if (!END_OF_COMMAND && isstring(c_token)) {                /* font name */
                    273:        quote_str(MP_fontname, c_token, MAX_ID_LEN);
                    274:        c_token++;
                    275:     }
                    276:     if (!END_OF_COMMAND) {     /*font size */
                    277:        struct value a;
                    278:        MP_fontsize = (double) real(const_express(&a));
                    279:        c_token++;
                    280:     }
                    281:     /* minimal error recovery: */
                    282:     if (MP_fontsize < 5.0)
                    283:        MP_fontsize = 5.0;
                    284:     if (MP_fontsize > 99.99)
                    285:        MP_fontsize = 99.99;
                    286:
                    287:     term->v_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 11 / 720);
1.1.1.2 ! ohara     288:     if (MP_tex == MP_NO_TEX) {         /* Courier is a little wider than cmtt */
1.1       maekawa   289:        term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 6.0 / 720 + 0.5);
                    290:     } else {
                    291:        term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 5.3 / 720 + 0.5);
                    292:     }
1.1.1.2 ! ohara     293:     sprintf(term_options, "%s%s%s%s%6.3f \"%s\" %5.2f %d %d",
1.1       maekawa   294:            MP_color ? "color " : "", MP_solid ? "solid " : "",
1.1.1.2 ! ohara     295:            (MP_tex == MP_NO_TEX) ? "notex " : (MP_tex == MP_LATEX) ? "latex " : "", "mag ",
        !           296:            MP_textmag, MP_fontname, MP_fontsize, MP_psnfss, MP_prologues);
1.1       maekawa   297: }
                    298:
                    299: TERM_PUBLIC void
                    300: MP_init()
                    301: {
                    302:     time_t now;
                    303:     time(&now);
                    304:     MP_posx = MP_posy = 0;
                    305:     fprintf(gpoutfile, "%%GNUPLOT Metapost output: %s\n", asctime(localtime(&now)));
1.1.1.2 ! ohara     306:     if(MP_prologues > -1) {
        !           307:       fprintf(gpoutfile, "prologues:=%d;\n", MP_prologues);
        !           308:     }
        !           309:     if (MP_tex == MP_LATEX) {
        !           310:         fputs("\n\
        !           311: %% Add \\documentclass and \\begin{dcoument} for latex\n\
        !           312: %% NB you should set the environment variable TEX to the name of your\n\
        !           313: %% latex executable (normally latex) inorder for metapost to work\n\
        !           314: %% or run\n\
        !           315: %% mpost --tex=latex ...\n\
        !           316: \n\
        !           317: % BEGPRE\n\
        !           318: \\verbatimtex\n", gpoutfile);
        !           319:        if(MP_a4paper) {
        !           320:          fputs("\\documentclass[a4paper]{article}\n", gpoutfile);
        !           321:        } else {
        !           322:          fputs("\\documentclass{article}\n", gpoutfile);
        !           323:        }
        !           324:        switch(MP_psnfss) {
        !           325:          case MP_PSNFSS_7: {
        !           326:             fputs("\\usepackage[latin1]{inputenc}\n\
        !           327: \\usepackage[T1]{fontenc}\n\
        !           328: \\usepackage{times,mathptmx}\n\
        !           329: \\usepackage{helvet}\n\
        !           330: \\usepackage{courier}\n", gpoutfile);
        !           331:          } break;
        !           332:          case MP_PSNFSS_8: {
        !           333:            fputs("\\usepackage[latin1]{inputenc}\n\
        !           334: \\usepackage[T1]{fontenc}\n\
        !           335: \\usepackage{textcomp}\n\
        !           336: \\usepackage{mathptmx}\n\
        !           337: \\usepackage[scaled=.92]{helvet}\n\
        !           338: \\usepackage{courier}\n\
        !           339: \\usepackage{latexsym}\n", gpoutfile);
        !           340:          } break;
        !           341:        }
        !           342:        fputs("\\begin{document}\n\
        !           343: etex\n% ENDPRE\n",
        !           344:               gpoutfile);
        !           345:     }
        !           346:
1.1       maekawa   347:     fputs("\n\
1.1.1.2 ! ohara     348: warningcheck:=0;\n\
1.1       maekawa   349: defaultmpt:=mpt:=4;\n\
                    350: th:=.6;\n\
1.1.1.2 ! ohara     351: %% Have nice sharp joins on our lines\n\
        !           352: linecap:=butt;\n\
        !           353: linejoin:=mitered;\n\
1.1       maekawa   354: \n\
                    355: def scalepen expr n = pickup pencircle scaled (n*th) enddef;\n\
1.1.1.2 ! ohara     356: def ptsize expr n = mpt:=n*defaultmpt enddef;\n\
        !           357: \n",
1.1       maekawa   358:          gpoutfile);
                    359:
                    360:     fprintf(gpoutfile, "\ntextmag:=%6.3f;\n", MP_textmag);
                    361:
                    362:     fputs("\
                    363: vardef makepic(expr str) =\n\
                    364:   if picture str : str scaled textmag\n\
                    365:   % otherwise a string\n\
                    366:   else: str infont defaultfont scaled (defaultscale*textmag)\n\
                    367:   fi\n\
                    368: enddef;\n\
                    369: \n\
1.1.1.2 ! ohara     370: def infontsize(expr str, size) =\n\
        !           371:   infont str scaled (size / fontsize str)\n\
1.1       maekawa   372: enddef;\n",
                    373:          gpoutfile);
                    374:
1.1.1.2 ! ohara     375:     if (MP_tex == MP_NO_TEX) {
1.1       maekawa   376:        fprintf(gpoutfile, "\n\
                    377: defaultfont:= \"%s\";\n\
                    378: defaultscale := %6.3f/fontsize defaultfont;\n",
                    379:                MP_fontname, MP_fontsize);
                    380:     } else {
1.1.1.2 ! ohara     381:       if(MP_tex != MP_LATEX) {
1.1       maekawa   382:        fputs("\n\
                    383: %font changes\n\
                    384: verbatimtex\n\
1.1.1.2 ! ohara     385: \\def\\setfont#1#2{%.\n\
        !           386:   \\font\\gpfont=#1 at #2pt\n\
        !           387: \\gpfont}\n", gpoutfile);
1.1       maekawa   388:        fprintf(gpoutfile, "\\setfont{%s}{%5.2f}\netex\n",
1.1.1.2 ! ohara     389:          MP_fontname, MP_fontsize
        !           390:        );
        !           391:       }
1.1       maekawa   392:     }
                    393:     fputs("\n\
                    394: color currentcolor; currentcolor=black;\n\
                    395: boolean colorlines,dashedlines;\n",
                    396:          gpoutfile);
                    397:     if (MP_color) {
                    398:        fputs("colorlines:=true;\n", gpoutfile);
                    399:     } else {
                    400:        fputs("colorlines:=false;\n", gpoutfile);
                    401:     }
                    402:     if (MP_solid) {
                    403:        fputs("dashedlines:=false;\n", gpoutfile);
                    404:     } else {
                    405:        fputs("dashedlines:=true;\n", gpoutfile);
                    406:     }
                    407:     fputs("\n\
                    408: def _wc = withpen currentpen withcolor currentcolor enddef;\n\
                    409: def _ac = addto currentpicture enddef;\n\
                    410: def _sms = scaled mpt shifted enddef;\n\
                    411: % drawing point-types\n\
                    412: def gpdraw (expr n, x, y) =\n\
                    413:   if n<0: _ac contour fullcircle _sms (x,y)\n\
                    414:   elseif (n=1) or (n=3):\n\
                    415:     _ac doublepath ptpath[n] _sms (x,y) _wc;\n\
                    416:     _ac doublepath ptpath[n] rotated 90 _sms (x,y) _wc\n\
                    417:   elseif n<6: _ac doublepath ptpath[n] _sms (x,y) _wc\n\
                    418:   else: _ac contour ptpath[n] _sms (x,y) _wc\n\
                    419:   fi\n\
                    420: enddef;\n\
                    421: \n\
                    422: % the point shapes\n\
                    423: path ptpath[];\n\
                    424: %diamond\n\
                    425: ptpath0 = ptpath6 = (-1/2,0)--(0,-1/2)--(1/2,0)--(0,1/2)--cycle;\n\
                    426: % plus sign\n\
                    427: ptpath1 = (-1/2,0)--(1/2,0);\n\
                    428: % square\n\
                    429: ptpath2 = ptpath7 = (-1/2,-1/2)--(1/2,-1/2)--(1/2,1/2)--(-1/2,1/2)--cycle;\n\
                    430: % cross\n\
                    431: ptpath3 := (-1/2,-1/2)--(1/2,1/2);\n\
                    432: % circle:\n\
                    433: ptpath4 = ptpath8:= fullcircle;\n\
                    434: % triangle\n\
                    435: ptpath5 = ptpath9 := (0,1/2)--(-1/2,-1/2)--(1/2,-1/2)--cycle;\n\
                    436: \n\
                    437: def linetype expr n =\n\
                    438:   currentcolor:= if colorlines : col[n] else: black fi;\n\
                    439:   if n = -1 :\n\
                    440:       drawoptions(withcolor currentcolor withpen (currentpen scaled .5));\n\
                    441:   elseif n < 1 :\n\
                    442:     drawoptions(_wc);\n\
                    443:   else :\n\
                    444:     drawoptions( if dashedlines: dashed lt[n] fi _wc);\n\
                    445:   fi\n\
                    446: enddef;\n\
                    447: \n\
                    448: % dash patterns\n\
                    449: picture lt[];\n\
                    450: lt1=dashpattern(on 2 off 2); % dashes\n\
                    451: lt2=dashpattern(on 2 off 2 on 0.2 off 2); %dash-dot\n\
                    452: lt3=lt1 scaled 1.414;\n\
                    453: lt4=lt2 scaled 1.414;\n\
                    454: lt5=lt1 scaled 2;\n\
                    455: lt6:=lt2 scaled 2;\n\
                    456: lt7=dashpattern(on 0.2 off 2); %dots\n\
                    457: \n\
                    458: color col[],cyan, magenta, yellow;\n\
                    459: cyan=blue+green; magenta=red+blue;yellow=green+red;\n\
                    460: col[-2]:=col[-1]:=col0:=black;\n\
                    461: col1:=red;\n\
                    462: col2:=(.2,.2,1); %blue\n\
                    463: col3:=(1,.66,0); %orange\n\
                    464: col4:=.85*green;\n\
                    465: col5:=.9*magenta;\n\
                    466: col6:=0.85*cyan;\n\
                    467: col7:=.85*yellow;\n\
                    468: \n\
                    469: %placing text\n\
                    470: picture GPtext;\n\
                    471: def put_text(expr pic, x, y, r, j) =\n\
                    472:   GPtext:=makepic(pic);\n\
                    473:   GPtext:=GPtext shifted\n\
                    474:     if j = 1: (-(ulcorner GPtext + llcorner GPtext)/2)\n\
                    475:     elseif j = 2: (-center GPtext)\n\
                    476:     else: (-(urcorner GPtext + lrcorner GPtext)/2)\n\
                    477:     fi\n\
                    478:     rotated if r > 0: 90 else: 0 fi;\n\
                    479:   draw GPtext shifted (x,y)\n\
                    480: enddef;\n",
                    481:          gpoutfile);
                    482: }
                    483:
                    484: TERM_PUBLIC void
                    485: MP_graphics()
                    486: {
                    487:     /* initialize "remembered" drawing parameters */
                    488:     MP_oldline = -2;
                    489:     MP_oldpen = 1.0;
                    490:     MP_oldptsize = pointsize;
1.1.1.2 ! ohara     491:     fprintf(gpoutfile, "\nbeginfig(%d);\nw:=%.3fin;h:=%.3fin;\n",
1.1       maekawa   492:            MP_char_code, MP_xsize, MP_ysize);
1.1.1.2 ! ohara     493:     /* MetaPost can only handle numbers up to 4096. When MP_DPI
        !           494:        is larger than 819, this is exceeded by (term->xmax). So we
        !           495:        scale it and all coordinates down by factor of 10.0. And
        !           496:        compensate by scaling a and b up.
        !           497:     */
        !           498:     fprintf(gpoutfile, "a:=w/%.1f;b:=h/%.1f;\n", (term->xmax)/10.0, (term->ymax)/10.0);
        !           499:     fprintf(gpoutfile, "scalepen 1; ptsize %.3f;linetype -2;\n", pointsize);
1.1       maekawa   500:     MP_char_code++;
                    501: }
                    502:
                    503: TERM_PUBLIC void
                    504: MP_text()
                    505: {
                    506:     if (MP_inline)
                    507:        MP_endline();
                    508:     fputs("endfig;\n", gpoutfile);
                    509: }
                    510:
                    511: TERM_PUBLIC void
                    512: MP_linetype(lt)
                    513: int lt;
                    514: {
                    515:     int linetype = lt;
                    516:     if (linetype >= MP_LINE_TYPES)
                    517:        linetype %= MP_LINE_TYPES;
                    518:     if (MP_inline)
                    519:        MP_endline();
                    520:     if (MP_oldline != linetype) {
                    521:        fprintf(gpoutfile, "linetype %d;\n", linetype);
                    522:        MP_oldline = linetype;
                    523:     }
                    524: }
                    525:
                    526: TERM_PUBLIC void
                    527: MP_move(x, y)
                    528: unsigned int x;
                    529: unsigned int y;
                    530: {
                    531:     if ((x != MP_posx) || (y != MP_posy)) {
                    532:        if (MP_inline)
                    533:            MP_endline();
                    534:        MP_posx = x;
                    535:        MP_posy = y;
                    536:     }                          /* else we seem to be there already */
                    537: }
                    538:
                    539: TERM_PUBLIC void
                    540: MP_point(x, y, pt)
                    541: unsigned int x;
                    542: unsigned int y;
                    543: int pt;
                    544: {
                    545:     int pointtype = pt;
                    546:     if (MP_inline)
                    547:        MP_endline();
                    548:
                    549:     /* Print the shape defined by 'number'; number < 0 means
                    550:        to use a dot, otherwise one of the defined points. */
                    551:
                    552:     if (pointtype >= MP_POINT_TYPES)
                    553:        pointtype %= MP_POINT_TYPES;
1.1.1.2 ! ohara     554: /* Change %d to %f, divide x,y by 10 */
        !           555:     fprintf(gpoutfile, "gpdraw(%d,%.1fa,%.1fb);\n", pointtype, x/10.0, y/10.0);
1.1       maekawa   556: }
                    557:
                    558: TERM_PUBLIC void
                    559: MP_pointsize(ps)
                    560: double ps;
                    561: {
                    562:     if (MP_oldptsize != ps) {
                    563:        if (MP_inline)
                    564:            MP_endline();
1.1.1.2 ! ohara     565:        fprintf(gpoutfile, "ptsize %.3f;\n", ps);
1.1       maekawa   566:        MP_oldptsize = ps;
                    567:     }
                    568: }
                    569:
                    570:
                    571: TERM_PUBLIC void
                    572: MP_linewidth(lw)
                    573: double lw;
                    574: {
                    575:     if (MP_oldpen != lw) {
                    576:        if (MP_inline)
                    577:            MP_endline();
1.1.1.2 ! ohara     578:        fprintf(gpoutfile, "scalepen %.3f;\n", lw);
1.1       maekawa   579:        MP_oldpen = lw;
                    580:     }
                    581: }
                    582:
                    583:
                    584: TERM_PUBLIC void
                    585: MP_vector(ux, uy)
                    586: unsigned int ux;
                    587: unsigned int uy;
                    588: {
                    589:     if ((ux == MP_posx) && (uy == MP_posy))
                    590:        return;                 /* Zero length line */
                    591:
                    592:     if (MP_inline) {
                    593:        if (MP_linecount++ >= MP_LINEMAX) {
                    594:            fputs("\n", gpoutfile);
                    595:            MP_linecount = 1;
                    596:        }
                    597:     } else {
                    598:        MP_inline = TRUE;
1.1.1.2 ! ohara     599:        fprintf(gpoutfile, "draw (%.1fa,%.1fb)", MP_posx/10.0, MP_posy/10.0);
1.1       maekawa   600:        MP_linecount = 2;
                    601:     }
                    602:     MP_posx = ux;
                    603:     MP_posy = uy;
1.1.1.2 ! ohara     604:     fprintf(gpoutfile, "--(%.1fa,%.1fb)", MP_posx/10.0, MP_posy/10.0);
1.1       maekawa   605: }
                    606:
                    607: static void
                    608: MP_endline()
                    609: {
                    610:     MP_inline = FALSE;
                    611:     fprintf(gpoutfile, ";\n");
                    612: }
                    613:
                    614: TERM_PUBLIC void
                    615: MP_arrow(sx, sy, ex, ey, head)
                    616: unsigned int sx;
                    617: unsigned int sy;
                    618: unsigned int ex;
                    619: unsigned int ey;
                    620: TBOOLEAN head;
                    621: {
                    622:     MP_move(sx, sy);
                    623:     if (head) {
1.1.1.2 ! ohara     624:        fprintf(gpoutfile, "drawarrow (%.1fa,%.1fb)--(%.1fa,%.1fb);\n",
        !           625:                sx/10.0, sy/10.0, ex/10.0, ey/10.0);
1.1       maekawa   626:     } else if ((sx != ex) || (sy != ey)) {
1.1.1.2 ! ohara     627:        fprintf(gpoutfile, "draw (%.1fa,%.1fb)--(%.1fa,%.1fb);\n",
        !           628:                sx/10.0, sy/10.0, ex/10.0, ey/10.0);
1.1       maekawa   629:     }                          /* else: arrow with no length and no head = sound of one hand clapping? */
                    630:     MP_posx = ex;
                    631:     MP_posy = ey;
                    632:
                    633: }
                    634:
                    635: TERM_PUBLIC void
                    636: MP_put_text(x, y, str)
                    637: unsigned int x, y;
                    638: char str[];
                    639: {
                    640:     int i, j = 0;
                    641:     char *text;
                    642:
                    643:     /* ignore empty strings */
                    644:     if (!str || !*str)
                    645:        return;
                    646:
                    647:     /* F***. why do drivers need to modify string args? */
1.1.1.2 ! ohara     648:     text = gp_strdup(str);
1.1       maekawa   649:
                    650:     if (MP_inline)
                    651:        MP_endline();
                    652:
                    653:
                    654:     switch (MP_justify) {
                    655:     case LEFT:
                    656:        j = 1;
                    657:        break;
                    658:     case CENTRE:
                    659:        j = 2;
                    660:        break;
                    661:     case RIGHT:
                    662:        j = 3;
                    663:        break;
                    664:     }
1.1.1.2 ! ohara     665:     if (MP_tex == MP_NO_TEX) {
1.1       maekawa   666:        for (i = 0; i < strlen(text); i++)
                    667:            if (text[i] == '"')
                    668:                text[i] = '\''; /* Replace " with ' */
                    669:        if (MP_fontchanged) {
                    670:            fprintf(gpoutfile, "\
1.1.1.2 ! ohara     671: put_text(\"%s\" infontsize(\"%s\",%5.2f), %.1fa, %.1fb, %d, %d);\n",
        !           672:                    text, MP_fontname, MP_fontsize, x/10.0, y/10.0, MP_ang, j);
1.1       maekawa   673:        } else {
1.1.1.2 ! ohara     674:            fprintf(gpoutfile, "put_text(\"%s\", %.1fa, %.1fb, %d, %d);\n",
        !           675:                    text, x/10.0, y/10.0, MP_ang, j);
1.1       maekawa   676:        }
                    677:     } else if (MP_fontchanged) {
1.1.1.2 ! ohara     678:       if(MP_tex != MP_LATEX) {
1.1       maekawa   679:        fprintf(gpoutfile, "\
1.1.1.2 ! ohara     680: put_text( btex \\setfont{%s}{%5.2f} %s etex, %.1fa, %.1fb, %d, %d);\n",
        !           681:                MP_fontname, MP_fontsize, text, x/10.0, y/10.0, MP_ang, j);
        !           682:       } else {
        !           683:        fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n",
        !           684:                text, x/10.0, y/10.0, MP_ang, j);
        !           685:       }
1.1       maekawa   686:     } else {
1.1.1.2 ! ohara     687:        fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n",
        !           688:                text, x/10.0, y/10.0, MP_ang, j);
1.1       maekawa   689:     }
                    690:
                    691:     free(text);
                    692: }
                    693:
                    694: TERM_PUBLIC int
                    695: MP_justify_text(mode)
                    696: enum JUSTIFY mode;
                    697: {
                    698:     MP_justify = mode;
                    699:     return (TRUE);
                    700: }
                    701:
                    702: TERM_PUBLIC int
                    703: MP_text_angle(ang)
                    704: int ang;
                    705: {
                    706:     /* Metapost code does the conversion */
                    707:     MP_ang = ang;
                    708:     return (TRUE);
                    709: }
                    710:
                    711: TERM_PUBLIC int
                    712: MP_set_font(font)
                    713: char *font;
                    714: {
                    715:     if (*font) {
                    716:        size_t sep = strcspn(font, ",");
                    717:        strncpy(MP_fontname, font, sep);
                    718:        MP_fontname[sep] = NUL;
                    719:        sscanf(&(font[sep + 1]), "%lf", &MP_fontsize);
                    720:        if (MP_fontsize < 5)
                    721:            MP_fontsize = 5.0;
                    722:        if (MP_fontsize >= 100)
                    723:            MP_fontsize = 99.99;
                    724:        /*  */
                    725:        MP_fontchanged = TRUE;
                    726:     } else {
                    727:        MP_fontchanged = FALSE;
                    728:     }
                    729:     return TRUE;
                    730: }
                    731:
                    732:
                    733: TERM_PUBLIC void
                    734: MP_reset()
                    735: {
                    736:     fputs("end.\n", gpoutfile);
                    737: }
                    738:
                    739: TERM_PUBLIC void
                    740: MP_boxfill(sty, x1, y1, wd, ht)
                    741: int sty;
                    742: unsigned int x1, y1, wd, ht;
                    743: {
                    744:     /* for now simply clear box if sty <= 0, do nothing otherwise */
                    745:     if (MP_inline)
                    746:        MP_endline();
                    747:     if (sty <= 0)
                    748:        fprintf(gpoutfile, "\
1.1.1.2 ! ohara     749: fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withcolor background;\n",
        !           750:                x1/10.0, y1/10.0, (x1 + wd)/10.0, y1/10.0, (x1 + wd)/10.0, (y1 +
        !           751:   ht)/10.0, x1/10.0, (y1 + ht)/10.0);
1.1       maekawa   752: }
                    753:
                    754: #endif /* TERM_BODY */
                    755:
                    756: #ifdef TERM_TABLE
                    757:
                    758: TERM_TABLE_START(mp_driver)
                    759:     "mp", "MetaPost plotting standard",
                    760:     MP_XMAX, MP_YMAX, MP_VCHAR, MP_HCHAR,
                    761:     MP_VTIC, MP_HTIC, MP_options, MP_init, MP_reset,
                    762:     MP_text, null_scale, MP_graphics, MP_move, MP_vector,
                    763:     MP_linetype, MP_put_text, MP_text_angle,
                    764:     MP_justify_text, MP_point, MP_arrow, MP_set_font, MP_pointsize,
                    765:     0, 0, 0, MP_boxfill, MP_linewidth
                    766:     TERM_TABLE_END(mp_driver)
                    767: #undef LAST_TERM
                    768: #define LAST_TERM mp_driver
                    769:
                    770: #endif /* TERM_TABLE */
                    771: #endif /* TERM_PROTO_ONLY */
                    772:
                    773: #ifdef TERM_HELP
                    774: START_HELP(mp)
                    775: "1 mp",
                    776: "?commands set terminal mpost",
                    777: "?set terminal mp",
                    778: "?set term mp",
                    779: "?terminal mp",
                    780: "?term mp",
                    781: "?mp",
                    782: "?metapost",
                    783: "",
                    784: " The `mp` driver produces output intended to be input to the Metapost program.",
                    785: " Running Metapost on the file creates EPS files containing the plots. By",
                    786: " default, Metapost passes all text through TeX.  This has the advantage of",
                    787: " allowing essentially  any TeX symbols in titles and labels.",
                    788: "",
                    789: " The `mp` terminal is selected with a command of the form",
1.1.1.2 ! ohara     790: "    set term mp {color} {solid} {notex|tex|latex} {mag <magsize>} {\"<name>\"}",
        !           791: "                {<size>}",
1.1       maekawa   792: " The option `color` causes lines to be drawn in color (on a printer or display",
                    793: " that supports it), `monochrome` (or nothing) selects black lines.  The option",
                    794: " `solid` draws solid lines, while `dashed` (or nothing) selects lines with",
                    795: " different patterns of dashes.  If `solid` is selected but `color` is not,",
                    796: " nearly all lines will be identical.  This may occasionally be useful, so it is",
                    797: " allowed.",
                    798: "",
                    799: " The option `notex` bypasses TeX entirely, therefore no TeX code can be used in",
                    800: " labels under this option.  This is intended for use on old plot files or files",
                    801: " that make frequent use of common characters like `$` and `%` that require",
                    802: " special handling in TeX.",
1.1.1.2 ! ohara     803: "",
        !           804: "",
        !           805: " The option `tex` sets the terminal to output its text for TeX to process.",
        !           806: "",
        !           807: " The option `latex` sets the terminal to output its text for processing by",
        !           808: " LaTeX. This allows things like \\frac for fractions which LaTeX knows about",
        !           809: " but TeX does not.  Note that you must set the environment variable TEX to the",
        !           810: " name of your LaTeX executable (normally latex) if you use this option. ",
        !           811: " Otherwise metapost will try and use TeX to process the text and it won't work.",
1.1       maekawa   812: "",
                    813: " Changing font sizes in TeX has no effect on the size of mathematics, and there",
                    814: " is no foolproof way to make such a change, except by globally  setting a",
                    815: " magnification factor. This is the purpose of the `magnification` option. It",
                    816: " must be followed by a scaling factor. All text (NOT the graphs) will be scaled",
                    817: " by this factor. Use this if you have math that you want at some size other",
                    818: " than the default 10pt. Unfortunately, all math will be the same size, but see",
                    819: " the discussion below on editing the MP output. `mag` will also work under",
                    820: " `notex` but there seems no point in using it as the font size option (below)",
                    821: " works as well.",
                    822: "",
                    823: " A name in quotes selects the font that will be used when no explicit font is",
                    824: " given in a `set label` or `set title`.  A name recognized by TeX (a TFM file",
                    825: " exists) must be used.  The default is \"cmr10\" unless `notex` is selected,",
                    826: " then it is \"pcrr8r\" (Courier).  Even under `notex`, a TFM file is needed by",
                    827: " Metapost. The file `pcrr8r.tfm` is the name given to Courier in LaTeX's psnfss",
                    828: " package.  If you change the font from the `notex` default, choose a font that",
                    829: " matches the ASCII encoding at least in the range 32-126.  `cmtt10` almost",
                    830: " works, but it has a nonblank character in position 32 (space).",
                    831: "",
                    832: " The size can be any number between 5.0 and 99.99.  If it is omitted, 10.0 is",
                    833: " used.  It is advisable to use `magstep` sizes: 10 times an integer or",
                    834: " half-integer power of 1.2, rounded to two decimals, because those are the most",
                    835: " available sizes of fonts in TeX systems.",
                    836: "",
                    837: " All the options are optional.  If font information is given, it must be at the",
                    838: " end, with size (if present) last.  The size is needed to select a size for the",
                    839: " font, even if the font name includes size information.  For example,",
                    840: " `set term mp \"cmtt12\"` selects cmtt12 shrunk to the default size 10.  This",
                    841: " is probably not what you want or you would have used cmtt10.",
                    842: "",
                    843: " The following common ascii characters need special treatment in TeX:",
                    844: "    $, &, #, %, _;  |, <, >;  ^, ~,  \\, {, and }",
                    845: " The five characters $, #, &, _, and % can simply be escaped, e.g., `\\$`.",
                    846: " The three characters <, >, and | can be wrapped in math mode, e.g., `$<$`.",
                    847: " The remainder require some TeX work-arounds.  Any good book on TeX will give",
                    848: " some guidance.",
                    849: "",
                    850: " If you type your labels inside double quotes, backslashes in TeX code need to",
                    851: " be escaped (doubled). Using single quotes will avoid having to do this, but",
                    852: " then you cannot use `\\n` for line breaks.  As of this writing, version 3.7 of",
                    853: " gnuplot processess titles given in a `plot` command differently than in other",
                    854: " places, and backslashes in TeX commands need to be doubled regardless of the",
                    855: " style of quotes.",
                    856: "",
                    857: " Metapost pictures are typically used in TeX documents.  Metapost deals with",
                    858: " fonts pretty much the same way TeX does, which is different from most other",
                    859: " document preparation programs.  If the picture is included in a LaTeX document",
                    860: " using the graphics package, or in a plainTeX document via epsf.tex, and then",
                    861: " converted to PostScript with dvips (or other dvi-to-ps converter), the text in",
                    862: " the plot will usually be handled correctly.  However, the text may not appear",
                    863: " if you send the Metapost output as-is to a PostScript interpreter.",
                    864: "",
                    865: "2 Metapost Instructions",
                    866: "?commands set terminal mp detailed",
                    867: "?set terminal mp detailed",
                    868: "?set term mp detailed",
                    869: "?mp detailed",
                    870: "?metapost detailed",
                    871: "",
                    872: " - Set your terminal to Metapost, e.g.:",
                    873: "    set terminal mp mono \"cmtt12\" 12",
                    874: "",
                    875: " - Select an output-file, e.g.:",
                    876: "    set output \"figure.mp\"",
                    877: "",
                    878: " - Create your pictures.  Each plot (or multiplot group) will generate a",
                    879: " separate Metapost beginfig...endfig group.  Its default size will be 5 by 3",
                    880: " inches.  You can change the size by saying `set size 0.5,0.5` or whatever",
                    881: " fraction of the default size you want to have.",
                    882: "",
                    883: " - Quit gnuplot.",
                    884: "",
                    885: " - Generate EPS files by running Metapost on the output of gnuplot:",
                    886: "    mpost figure.mp  OR  mp figure.mp",
                    887: " The name of the Metapost program depends on the system, typically `mpost` for",
                    888: " a Unix machine and `mp` on many others.  Metapost will generate one EPS file",
                    889: " for each picture.",
                    890: "",
                    891: " - To include your pictures in your document you can use the graphics package",
                    892: " in LaTeX or epsf.tex in plainTeX:",
                    893: "    \\usepackage{graphics} % LaTeX",
                    894: "    \\input epsf.tex       % plainTeX",
                    895: " If you use a driver other than dvips for converting TeX DVI output to PS, you",
                    896: " may need to add the following line in your LaTeX document:",
                    897: "    \\DeclareGraphicsRule{*}{eps}{*}{}",
                    898: " Each picture you made is in a separate file.  The first picture is in, e.g.,",
                    899: " figure.0, the second in figure.1, and so on....  To place the third picture in",
                    900: " your document, for example, all you have to do is:",
                    901: "    \\includegraphics{figure.2} % LaTeX",
                    902: "    \\epsfbox{figure.2}         % plainTeX",
                    903: "",
                    904: " The advantage, if any, of the mp terminal over a postscript terminal is",
                    905: " editable output.  Considerable effort went into making this output as clean as",
                    906: " possible.  For those knowledgeable in the Metapost language, the default line",
                    907: " types and colors can be changed by editing the arrays `lt[]` and `col[]`.",
                    908: " The choice of solid vs dashed lines, and color vs black lines can be change by",
                    909: " changing the values assigned to the booleans `dashedlines` and `colorlines`.",
                    910: " If the default `tex` option was in effect, global changes to the text of",
                    911: " labels can be achieved by editing the `vebatimtex...etex` block.  In",
                    912: " particular, a LaTeX preamble can be added if desired, and then LaTeX's",
                    913: " built-in size changing commands can be used for maximum flexibility. Be sure",
                    914: " to set the appropriate MP configuration variable to force Metapost to run",
                    915: " LaTeX instead of plainTeX."
                    916: END_HELP(mp)
                    917: #endif /* TERM_HELP */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>