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

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