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

Annotation of OpenXM_contrib/gnuplot/term/tpic.trm, Revision 1.1

1.1     ! maekawa     1: /*
        !             2:  * $Id: tpic.trm,v 1.19 1998/04/14 00:18:12 drd Exp $
        !             3:  */
        !             4:
        !             5: /* GNUPLOT - tpic.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: /*
        !            38:  * This file is included by ../term.c.
        !            39:  *
        !            40:  * This terminal driver supports:
        !            41:  *   The tpic \specials (version 2.2) for LaTeX.
        !            42:  *
        !            43:  * AUTHORS
        !            44:  *   Oh-Yeah?   3 Sep. 1992 (closely following eepic.trm by David Kotz)
        !            45:  *   A. Woo     5 Oct. 1992 (removed ansi prototypes for braindead compilers)
        !            46:  *
        !            47:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
        !            48:  *
        !            49:  */
        !            50: /*
        !            51:  *  This file contains the tpic terminal driver for use with LaTeX.
        !            52:  *  This is an alternative to the latex and eepic drivers. You need
        !            53:  *  a printer driver that supports the tpic \specials version 2.2.
        !            54:  *
        !            55:  * Comparison with the eepic driver (eepic.trm):
        !            56:  *  Merits
        !            57:  *    - More point and line types
        !            58:  *    - Options to change point size, linewidth, dot & dash intervals
        !            59:  *    - Dotted and dashed lines for high-sample-rate curves (but may
        !            60:  *      depend on tpic (da & dt) implementation of your dvi driver :-)
        !            61:  *    - Overlapped points made fancier by tpic shading facility
        !            62:  *    - Optional comments for trimming figure margins
        !            63:  *    - No need for epic and eepic macros
        !            64:  *  Drawback
        !            65:  *    - You cannot use eepicemu macro for non-tpic-support dvi drivers
        !            66:  *
        !            67:  * LATEX must also be defined.
        !            68:  */
        !            69:
        !            70:
        !            71: /* These parameters can be modified as you like, through options.  Say
        !            72:    "set terminal tpic <pointsize> <linewidth> <interval>".  <pointsize>
        !            73:    and <linewidth> are integers in milli-inches; <interval> is a float
        !            74:    in inches.  If non-positive value is specified, the default (below)
        !            75:    is chosen.
        !            76: */
        !            77:
        !            78: /*
        !            79:  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
        !            80:  */
        !            81:
        !            82: #include "driver.h"
        !            83:
        !            84: #ifdef TERM_REGISTER
        !            85: register_term(tpic)
        !            86: #endif
        !            87:
        !            88: #ifdef TERM_PROTO
        !            89: TERM_PUBLIC void TPIC_options __PROTO((void));         /* get size options */
        !            90: TERM_PUBLIC void TPIC_init __PROTO((void));
        !            91: TERM_PUBLIC void TPIC_reset __PROTO((void));
        !            92: TERM_PUBLIC void TPIC_text __PROTO((void));
        !            93: TERM_PUBLIC void TPIC_graphics __PROTO((void));
        !            94: TERM_PUBLIC void TPIC_move __PROTO((unsigned int x, unsigned int y));
        !            95: TERM_PUBLIC void TPIC_vector __PROTO((unsigned int ux, unsigned int uy));
        !            96: TERM_PUBLIC void TPIC_linetype __PROTO((int linetype));
        !            97: TERM_PUBLIC void TPIC_put_text __PROTO((unsigned int x, unsigned int y, char *str));   /* ref point and text */
        !            98: TERM_PUBLIC int TPIC_text_angle __PROTO((int ang));
        !            99: TERM_PUBLIC int TPIC_justify_text __PROTO((enum JUSTIFY mode));
        !           100: TERM_PUBLIC void TPIC_point __PROTO((unsigned int x, unsigned int y, int number));
        !           101: TERM_PUBLIC void TPIC_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, TBOOLEAN head));
        !           102:
        !           103: /* tpic \specials unit in inches (1 milli-inch) */
        !           104: #define TPIC_UNIT 0.001
        !           105:
        !           106: /* 5 inches wide by 3 inches high (default) */
        !           107: #define TPIC_XMAX (unsigned int) (5 / TPIC_UNIT)
        !           108: #define TPIC_YMAX (unsigned int) (3 / TPIC_UNIT)
        !           109: #define TPIC_PTS_PER_UNIT (72.27 * TPIC_UNIT)
        !           110: #define TPIC_HTIC  (unsigned int) ( 5.0 / TPIC_PTS_PER_UNIT)   /* 5pt */
        !           111: #define TPIC_VTIC  (unsigned int) ( 5.0 / TPIC_PTS_PER_UNIT)   /* 5pt */
        !           112: #define TPIC_HCHAR (unsigned int) ( 5.3 / TPIC_PTS_PER_UNIT)   /* 5.3pt */
        !           113: #define TPIC_VCHAR (unsigned int) (11.0 / TPIC_PTS_PER_UNIT)   /* 11pt */
        !           114: #endif /* TERM_PROTO */
        !           115:
        !           116: #ifndef TERM_PROTO_ONLY
        !           117: #ifdef TERM_BODY
        !           118: static int tpic_pointsize = 40;        /* min point radius   (in milli-inches) */
        !           119: static int tpic_linewidth = 6; /* min line thickness (in milli-inches) */
        !           120: static double tpic_interval = 0.1;     /* min dot & dash intervals (in inches) */
        !           121:
        !           122: /* ARROWS: same code as for LATEX */
        !           123: /* figure out the best arrow. in latex.trm */
        !           124: void best_latex_arrow __PROTO((int sx, int sy, int ex, int ey, int who, TBOOLEAN head));
        !           125:
        !           126: /* all prototypes ... */
        !           127: static void tpic_startline __PROTO((void));    /* private */
        !           128: static void tpic_endline __PROTO((void));      /* private */
        !           129: static void tpic_pushpath __PROTO((unsigned int x, unsigned int y));   /* private */
        !           130: static void tpic_scanpath __PROTO((void));
        !           131: void tpic_diamond __PROTO((int size));
        !           132: void tpic_plus __PROTO((int size));
        !           133: void tpic_box __PROTO((int size));
        !           134: void tpic_times __PROTO((int size));
        !           135: void tpic_triangle __PROTO((int size));
        !           136: void tpic_star __PROTO((int size));
        !           137: void tpic_hexagon __PROTO((int size));
        !           138: void tpic_circle __PROTO((int size));
        !           139: void tpic_doublecircle __PROTO((int size));
        !           140: void tpic_vercircle __PROTO((int size));       /* circle with | */
        !           141: void tpic_horcircle __PROTO((int size));       /* circle with - */
        !           142: void tpic_pluscircle __PROTO((int size));      /* circle with + */
        !           143: void tpic_timescircle __PROTO((int size));     /* circle with times */
        !           144: void tpic_starcircle __PROTO((int size));      /* circle with star */
        !           145: void tpic_dotcircle __PROTO((int size));       /* circle with dot (black circle) */
        !           146: void tpic_diamondcircle __PROTO((int size));   /* circle with black diamond */
        !           147: void tpic_boxcircle __PROTO((int size));       /* circle with black box */
        !           148: void tpic_trianglecircle __PROTO((int size));  /* circle with black triangle */
        !           149: void tpic_hexagoncircle __PROTO((int size));   /* circle with black hexagon */
        !           150: void tpic_plustimescircle __PROTO((int size)); /* no more idea ... with plus & times */
        !           151: void tpic_abspath __PROTO((unsigned int x, unsigned int y));   /* absolute coord */
        !           152: void tpic_path __PROTO((int x, int y));
        !           153: void tpic_flush __PROTO((void));
        !           154: void tpic_arc __PROTO((int radius));   /* actually, draw a full circle */
        !           155: void tpic_shade __PROTO((double grayscale));
        !           156: void tpic_pen __PROTO((int thickness));
        !           157: void tpic_dottedflush __PROTO((double interval));
        !           158: void tpic_dashedflush __PROTO((double interval));
        !           159:
        !           160: typedef enum {
        !           161:     tpic_none, tpic_white, tpic_gray, tpic_black
        !           162: } tpic_shadestyle;
        !           163: typedef enum {
        !           164:     tpic_nosize, tpic_small, tpic_medium, tpic_large
        !           165: } tpic_size;
        !           166: typedef void (*tpic_function) __PROTO((int size));
        !           167:
        !           168: typedef struct {
        !           169:     tpic_shadestyle shadestyle;
        !           170:     tpic_size size;
        !           171:     tpic_function function;
        !           172: } tpic_point_info;
        !           173:
        !           174: /* POINTS */
        !           175: static /*GPFAR */ tpic_point_info GPFAR tpic_point[] =
        !           176: {
        !           177:     {tpic_white, tpic_medium, tpic_diamond},
        !           178:     {tpic_none, tpic_medium, tpic_plus},
        !           179:     {tpic_white, tpic_medium, tpic_box},
        !           180:     {tpic_none, tpic_medium, tpic_times},
        !           181:     {tpic_white, tpic_medium, tpic_triangle},
        !           182:     {tpic_none, tpic_medium, tpic_star},
        !           183:     {tpic_white, tpic_small, tpic_circle},
        !           184:     {tpic_white, tpic_medium, tpic_circle},
        !           185:     {tpic_white, tpic_large, tpic_circle},
        !           186:     {tpic_black, tpic_small, tpic_circle},
        !           187:     {tpic_black, tpic_medium, tpic_circle},
        !           188:     {tpic_black, tpic_large, tpic_circle},
        !           189:     {tpic_black, tpic_medium, tpic_diamond},
        !           190:     {tpic_black, tpic_medium, tpic_box},
        !           191:     {tpic_black, tpic_medium, tpic_triangle},
        !           192:     {tpic_white, tpic_medium, tpic_hexagon},
        !           193:     {tpic_black, tpic_medium, tpic_hexagon},
        !           194:     {tpic_white, tpic_medium, tpic_doublecircle},
        !           195:     {tpic_white, tpic_medium, tpic_vercircle},
        !           196:     {tpic_white, tpic_medium, tpic_horcircle},
        !           197:     {tpic_white, tpic_medium, tpic_pluscircle},
        !           198:     {tpic_white, tpic_medium, tpic_timescircle},
        !           199:     {tpic_white, tpic_medium, tpic_starcircle},
        !           200:     {tpic_black, tpic_medium, tpic_doublecircle},
        !           201:     {tpic_white, tpic_medium, tpic_dotcircle},
        !           202:     {tpic_white, tpic_medium, tpic_diamondcircle},
        !           203:     {tpic_white, tpic_medium, tpic_boxcircle},
        !           204:     {tpic_white, tpic_medium, tpic_trianglecircle},
        !           205:     {tpic_white, tpic_medium, tpic_hexagoncircle},
        !           206:     {tpic_white, tpic_medium, tpic_plustimescircle}
        !           207: };
        !           208:
        !           209: typedef enum {
        !           210:     tpic_solid, tpic_dotted, tpic_dashed,
        !           211:     tpic_dashed_sdot, tpic_dashed_ddot
        !           212: } tpic_linestyle;
        !           213: typedef struct {
        !           214:     tpic_size thickness, interval;
        !           215:     tpic_linestyle linestyle;
        !           216: } tpic_line_info;
        !           217:
        !           218: /* LINES */
        !           219: static /*GPFAR */ tpic_line_info GPFAR tpic_line[] =
        !           220: {
        !           221:     {tpic_medium, tpic_nosize, tpic_solid},    /* -2 border */
        !           222:     {tpic_small, tpic_small, tpic_dashed},     /* -1 axes */
        !           223:     {tpic_small, tpic_nosize, tpic_solid},
        !           224:     {tpic_medium, tpic_nosize, tpic_solid},
        !           225:     {tpic_large, tpic_nosize, tpic_solid},
        !           226:     {tpic_small, tpic_small, tpic_dotted},
        !           227:     {tpic_medium, tpic_small, tpic_dotted},
        !           228:     {tpic_large, tpic_small, tpic_dotted},
        !           229:     {tpic_small, tpic_small, tpic_dashed},
        !           230:     {tpic_medium, tpic_small, tpic_dashed},
        !           231:     {tpic_large, tpic_small, tpic_dashed},
        !           232:     {tpic_small, tpic_small, tpic_dashed_sdot},                /* dash with single dots */
        !           233:     {tpic_medium, tpic_small, tpic_dashed_sdot},
        !           234:     {tpic_large, tpic_small, tpic_dashed_sdot},
        !           235:     {tpic_small, tpic_small, tpic_dashed_ddot},                /* dash with double dots */
        !           236:     {tpic_medium, tpic_small, tpic_dashed_ddot},
        !           237:     {tpic_large, tpic_small, tpic_dashed_ddot},
        !           238:     {tpic_small, tpic_medium, tpic_dotted},
        !           239:     {tpic_medium, tpic_medium, tpic_dotted},
        !           240:     {tpic_large, tpic_medium, tpic_dotted},
        !           241:     {tpic_small, tpic_medium, tpic_dashed},
        !           242:     {tpic_medium, tpic_medium, tpic_dashed},
        !           243:     {tpic_large, tpic_medium, tpic_dashed},
        !           244:     {tpic_small, tpic_medium, tpic_dashed_sdot},
        !           245:     {tpic_medium, tpic_medium, tpic_dashed_sdot},
        !           246:     {tpic_large, tpic_medium, tpic_dashed_sdot},
        !           247:     {tpic_small, tpic_medium, tpic_dashed_ddot},
        !           248:     {tpic_medium, tpic_medium, tpic_dashed_ddot},
        !           249:     {tpic_large, tpic_medium, tpic_dashed_ddot},
        !           250:     {tpic_small, tpic_large, tpic_dotted},
        !           251:     {tpic_medium, tpic_large, tpic_dotted},
        !           252:     {tpic_large, tpic_large, tpic_dotted},
        !           253:     {tpic_small, tpic_large, tpic_dashed},
        !           254:     {tpic_medium, tpic_large, tpic_dashed},
        !           255:     {tpic_large, tpic_large, tpic_dashed},
        !           256:     {tpic_small, tpic_large, tpic_dashed_sdot},
        !           257:     {tpic_medium, tpic_large, tpic_dashed_sdot},
        !           258:     {tpic_large, tpic_large, tpic_dashed_sdot},
        !           259:     {tpic_small, tpic_large, tpic_dashed_ddot},
        !           260:     {tpic_medium, tpic_large, tpic_dashed_ddot},
        !           261:     {tpic_large, tpic_large, tpic_dashed_ddot}
        !           262: };
        !           263:
        !           264: TERM_PUBLIC void TPIC_options()
        !           265: {                              /* get size options */
        !           266:     struct value a;
        !           267:     int ptsize, linewidth;
        !           268:     double interval;
        !           269:
        !           270:     if (!END_OF_COMMAND) {
        !           271:        ptsize = (int) real(const_express(&a));
        !           272:        if (ptsize > 0)
        !           273:            tpic_pointsize = ptsize;
        !           274:     }
        !           275:     if (!END_OF_COMMAND) {
        !           276:        linewidth = (int) real(const_express(&a));
        !           277:        if (linewidth > 0)
        !           278:            tpic_linewidth = linewidth;
        !           279:     }
        !           280:     if (!END_OF_COMMAND) {
        !           281:        interval = (double) real(const_express(&a));
        !           282:        if (interval > 0)
        !           283:            tpic_interval = interval;
        !           284:     }
        !           285:     sprintf(term_options, "%d %d %f", tpic_pointsize, tpic_linewidth,
        !           286:            tpic_interval);
        !           287: }
        !           288:
        !           289: static unsigned int tpic_posx; /* current position */
        !           290: static unsigned int tpic_posy;
        !           291: static int tpic_point_types;
        !           292: static int tpic_numlines;
        !           293:
        !           294: TERM_PUBLIC void TPIC_init()
        !           295: {
        !           296:     static char GPFAR tpic1[] = "\
        !           297: %% GNUPLOT: LaTeX picture using tpic \\specials\n\
        !           298: %%          with %d point types and %d line types\n\
        !           299: %% Options: pointsize = %d, linewidth = %d, interval = %f\n\
        !           300: %% To change above options, say:\n\
        !           301: %% set terminal tpic pointsize_value linewidth_value interval_value\n\
        !           302: %% (pointsize and linewidth - integers in milli-inches.\n\
        !           303: %%  interval - a float in inches.  If zero is specified, \n\
        !           304: %%  the default value is chosen.)\n\
        !           305: \\setlength{\\unitlength}{%fin}%%\n";
        !           306:     tpic_point_types = sizeof(tpic_point) / sizeof(tpic_point[0]);
        !           307:     tpic_numlines = sizeof(tpic_line) / sizeof(tpic_line[0]);
        !           308:
        !           309:     tpic_posx = tpic_posy = 0;
        !           310:     TPIC_linetype(-1);
        !           311:     fprintf(gpoutfile, tpic1,
        !           312:            tpic_point_types, tpic_numlines - 2,
        !           313:            tpic_pointsize, tpic_linewidth, tpic_interval,
        !           314:            TPIC_UNIT);
        !           315: }
        !           316:
        !           317: TERM_PUBLIC void TPIC_reset()
        !           318: {
        !           319:     tpic_endline();
        !           320:     tpic_posx = tpic_posy = 0;
        !           321: }
        !           322:
        !           323: TERM_PUBLIC void TPIC_text()
        !           324: {
        !           325:     tpic_endline();
        !           326:     fputs("\\end{picture}\n", gpoutfile);
        !           327: }
        !           328:
        !           329: TERM_PUBLIC void TPIC_graphics()
        !           330: {
        !           331:     register struct termentry *t = term;
        !           332:     int left, right, top, bottom;      /* margins */
        !           333:     static char GPFAR begin[] = "%s\\begin{picture}(%d,%d)(%d,%d)%% %s\n";
        !           334:
        !           335:     fprintf(gpoutfile, begin, "", t->xmax, t->ymax, 0, 0, "");
        !           336:
        !           337:     /* the following is dependent on boundary() function in graphics.c */
        !           338:     left = TPIC_HCHAR * 12;
        !           339:     right = TPIC_HCHAR * 2 + TPIC_HTIC;
        !           340:     bottom = TPIC_VCHAR * 7 / 2 + 1;
        !           341:     top = TPIC_VCHAR * 5 / 2 - 1;
        !           342:     fprintf(gpoutfile, begin, "%% ", t->xmax - left, t->ymax, left, 0,
        !           343:            "trim left margin");
        !           344:     fprintf(gpoutfile, begin, "%% ", t->xmax - right, t->ymax, 0, 0,
        !           345:            "trim right margin");
        !           346:     fprintf(gpoutfile, begin, "%% ", t->xmax - left - right, t->ymax, left, 0,
        !           347:            "trim left & right margins");
        !           348:     fprintf(gpoutfile, begin, "%% ", t->xmax, t->ymax - top, 0, 0,
        !           349:            "trim top margin");
        !           350:     fprintf(gpoutfile, begin, "%% ", t->xmax, t->ymax - bottom, 0, bottom,
        !           351:            "trim bottom margin");
        !           352:     fprintf(gpoutfile, begin, "%% ", t->xmax, t->ymax - top - bottom, 0, bottom,
        !           353:            "trim top & bottom margins");
        !           354:
        !           355:     fputs("\\footnotesize%\n", gpoutfile);
        !           356: }
        !           357:
        !           358: TERM_PUBLIC void TPIC_move(x, y)
        !           359: unsigned int x;
        !           360: unsigned int y;
        !           361: {
        !           362:     tpic_endline();
        !           363:     tpic_posx = x;
        !           364:     tpic_posy = y;
        !           365: }
        !           366:
        !           367: #define TPIC_LINEMAX 100       /* max value for linecount */
        !           368: static TBOOLEAN tpic_inline = FALSE;   /* are we in the middle of a line */
        !           369: static int tpic_linecount = 0; /* number of points in line so far */
        !           370:
        !           371: TERM_PUBLIC void TPIC_vector(ux, uy)
        !           372: unsigned int ux;
        !           373: unsigned int uy;
        !           374: {
        !           375:     if (!tpic_inline) {
        !           376:        tpic_startline();
        !           377:     } else if (tpic_linecount >= TPIC_LINEMAX) {
        !           378:        /* Even though we are in middle of a path, we may start a new path
        !           379:           command once in a while; if they are too long, latex will choke. */
        !           380:        tpic_endline();
        !           381:        tpic_startline();
        !           382:     }
        !           383:     tpic_pushpath(ux, uy);
        !           384:     tpic_posx = ux;
        !           385:     tpic_posy = uy;
        !           386: }
        !           387:
        !           388: static int tpic_linetype;      /* current line type */
        !           389:
        !           390: static void tpic_startline()
        !           391: {                              /* private */
        !           392:     int thickness = 1;
        !           393:
        !           394:     tpic_inline = TRUE;
        !           395:     switch (tpic_line[tpic_linetype + 2].thickness) {
        !           396:     case tpic_small:
        !           397:        thickness = tpic_linewidth;
        !           398:        break;
        !           399:     case tpic_medium:
        !           400:        thickness = (int) (tpic_linewidth * 3);
        !           401:        break;
        !           402:     case tpic_large:
        !           403:        thickness = (int) (tpic_linewidth * 5);
        !           404:        break;
        !           405:     default:
        !           406:        break;
        !           407:     }
        !           408:     tpic_pen(thickness);
        !           409:     tpic_linecount = 0;
        !           410:     tpic_pushpath(tpic_posx, tpic_posy);
        !           411:     return;
        !           412: }
        !           413:
        !           414: static void tpic_endline()
        !           415: {                              /* private */
        !           416:     double interval = 1;
        !           417:
        !           418:     if (tpic_inline) {
        !           419:        tpic_scanpath();        /* draw actually */
        !           420:        switch (tpic_line[tpic_linetype + 2].interval) {
        !           421:        case tpic_small:
        !           422:            interval = tpic_interval;
        !           423:            break;
        !           424:        case tpic_medium:
        !           425:            interval = tpic_interval * 2;
        !           426:            break;
        !           427:        case tpic_large:
        !           428:            interval = tpic_interval * 3;
        !           429:            break;
        !           430:        case tpic_nosize:
        !           431:            break;
        !           432:        }
        !           433:        switch (tpic_line[tpic_linetype + 2].linestyle) {
        !           434:        case tpic_solid:
        !           435:            tpic_flush();
        !           436:            break;
        !           437:        case tpic_dotted:
        !           438:            tpic_dottedflush(interval);
        !           439:            break;
        !           440:        case tpic_dashed:
        !           441:            tpic_dashedflush(interval);
        !           442:            break;
        !           443:        case tpic_dashed_sdot:  /* dashed with single dots in between */
        !           444:            tpic_dashedflush(interval);
        !           445:            tpic_scanpath();    /* draw again */
        !           446:            tpic_dottedflush(interval / 2);
        !           447:            break;
        !           448:        case tpic_dashed_ddot:  /* dashed with double dots in between */
        !           449:            tpic_dashedflush(interval);
        !           450:            tpic_scanpath();    /* draw again */
        !           451:            tpic_dottedflush(interval / 3);
        !           452:            break;
        !           453:        }
        !           454:        tpic_inline = FALSE;
        !           455:     }
        !           456:     return;
        !           457: }
        !           458:
        !           459: /* private: stack functions */
        !           460: static unsigned int pathpoint[TPIC_LINEMAX][2];                /* point stack */
        !           461:
        !           462: static void tpic_pushpath(x, y)
        !           463: unsigned int x;
        !           464: unsigned int y;                        /* private */
        !           465: {
        !           466:     if (tpic_linecount < TPIC_LINEMAX) {
        !           467:        pathpoint[tpic_linecount][0] = x;
        !           468:        pathpoint[tpic_linecount][1] = y;
        !           469:        tpic_linecount++;
        !           470:     }
        !           471:     return;
        !           472: }
        !           473:
        !           474: static void tpic_scanpath()
        !           475: {
        !           476:     int i;
        !           477:
        !           478:     for (i = 0; i < tpic_linecount; i++)
        !           479:        tpic_abspath(pathpoint[i][0], pathpoint[i][1]);
        !           480:     return;
        !           481: }
        !           482:
        !           483: TERM_PUBLIC void TPIC_linetype(linetype)
        !           484: int linetype;
        !           485: {
        !           486:     tpic_endline();
        !           487:     if (linetype >= tpic_numlines - 2)
        !           488:        linetype %= (tpic_numlines - 2);
        !           489:     tpic_linetype = linetype;
        !           490: }
        !           491:
        !           492: static int tpic_angle = 0;     /* 0 = horizontal, 1 = vertical */
        !           493: static enum JUSTIFY tpic_justify = LEFT;
        !           494:
        !           495: TERM_PUBLIC void TPIC_put_text(x, y, str)
        !           496: unsigned int x;
        !           497: unsigned int y;
        !           498: char *str;                     /* ref point and text */
        !           499: {
        !           500:     char *justify = NULL;
        !           501:
        !           502:     tpic_endline();
        !           503:     fprintf(gpoutfile, "\\put(%d,%d)", x, y);
        !           504:
        !           505:     if ((str[0] == '{') || (str[0] == '[')) {
        !           506:        fprintf(gpoutfile, "{\\makebox(0,0)%s}\n", str);
        !           507:     } else
        !           508:        switch (tpic_angle) {
        !           509:        case 0:         /* horizontal */
        !           510:            switch (tpic_justify) {
        !           511:            case LEFT:
        !           512:                justify = "[l]";
        !           513:                break;
        !           514:            case CENTRE:
        !           515:                justify = "";
        !           516:                break;
        !           517:            case RIGHT:
        !           518:                justify = "[r]";
        !           519:                break;
        !           520:            }
        !           521:            fprintf(gpoutfile, "{\\makebox(0,0)%s{%s}}\n", justify, str);
        !           522:            break;
        !           523:        case 1:         /* vertical */
        !           524:            /* we can't really write text vertically, but will put the ylabel
        !           525:               centred at the left of the plot, and then we'll make a \shortstack */
        !           526:            switch (tpic_justify) {
        !           527:            case LEFT:
        !           528:                justify = "[lb]";
        !           529:                break;
        !           530:            case CENTRE:
        !           531:                justify = "[l]";
        !           532:                break;
        !           533:            case RIGHT:
        !           534:                justify = "[lt]";
        !           535:                break;
        !           536:            }
        !           537:            fprintf(gpoutfile, "{\\makebox(0,0)%s{\\shortstack{%s}}}\n",
        !           538:                    justify, str);
        !           539:            break;
        !           540:        }
        !           541: }
        !           542:
        !           543: TERM_PUBLIC int TPIC_text_angle(ang)
        !           544: int ang;
        !           545: {
        !           546:     tpic_angle = ang;
        !           547:     return (TRUE);
        !           548: }
        !           549:
        !           550: TERM_PUBLIC int TPIC_justify_text(mode)
        !           551: enum JUSTIFY mode;
        !           552: {
        !           553:     tpic_justify = mode;
        !           554:     return (TRUE);
        !           555: }
        !           556:
        !           557: TERM_PUBLIC void TPIC_point(x, y, number)
        !           558: unsigned int x;
        !           559: unsigned int y;
        !           560: int number;
        !           561: {
        !           562:     int size = 0;
        !           563:
        !           564:     TPIC_move(x, y);
        !           565:
        !           566:     /* Print the character defined by 'number'; number < 0 means
        !           567:        to use a dot, otherwise one of the defined points. */
        !           568:
        !           569:     fprintf(gpoutfile, "\\put(%d,%d){", x, y); /* start putting */
        !           570:
        !           571:     if (number < 0) {
        !           572:        fprintf(gpoutfile, "\\rule{.1pt}{.1pt}");       /* tiny dot */
        !           573:     } else {
        !           574:        number %= tpic_point_types;
        !           575:        switch (tpic_point[number].shadestyle) {
        !           576:        case tpic_white:
        !           577:            tpic_pen(tpic_linewidth);   /* set it thin */
        !           578:            tpic_shade(0.0);
        !           579:            break;
        !           580:        case tpic_gray:
        !           581:            tpic_pen(tpic_linewidth);
        !           582:            tpic_shade(0.5);
        !           583:            break;
        !           584:        case tpic_black:
        !           585:            tpic_pen(tpic_linewidth);
        !           586:            tpic_shade(1.0);
        !           587:            break;
        !           588:        case tpic_none:
        !           589:            tpic_pen(tpic_linewidth * 3);       /* set it thick */
        !           590:            break;
        !           591:        }
        !           592:        switch (tpic_point[number].size) {
        !           593:        case tpic_small:
        !           594:            size = tpic_pointsize;
        !           595:            break;
        !           596:        case tpic_medium:
        !           597:            size = (int) (tpic_pointsize * 1.4142);
        !           598:            break;
        !           599:        case tpic_large:
        !           600:            size = (int) (tpic_pointsize * 2.0);
        !           601:            break;
        !           602:        default:
        !           603:            break;
        !           604:        }
        !           605:        (tpic_point[number].function) (size);
        !           606:     }
        !           607:
        !           608:     fputs("}%%\n", gpoutfile); /* end putting */
        !           609: }
        !           610:
        !           611: TERM_PUBLIC void TPIC_arrow(sx, sy, ex, ey, head)
        !           612: unsigned int sx;
        !           613: unsigned int sy;
        !           614: unsigned int ex;
        !           615: unsigned int ey;
        !           616: TBOOLEAN head;
        !           617: {
        !           618:     best_latex_arrow(sx, sy, ex, ey, 1, head); /* call latex routine */
        !           619:     tpic_posx = ex;
        !           620:     tpic_posy = ey;
        !           621: }
        !           622:
        !           623: /* private: draw points with tpic commands */
        !           624:
        !           625: void tpic_diamond(size)
        !           626: int size;
        !           627: {
        !           628:     size = (int) (size * 1.4142);      /* spread by sqrt(2) */
        !           629:
        !           630:     tpic_path(0, size);
        !           631:     tpic_path(-size, 0);
        !           632:     tpic_path(0, -size);
        !           633:     tpic_path(size, 0);
        !           634:     tpic_path(0, size);
        !           635:     tpic_flush();
        !           636:     return;
        !           637: }
        !           638:
        !           639: void tpic_plus(size)
        !           640: int size;
        !           641: {
        !           642:     tpic_path(0, size);
        !           643:     tpic_path(0, -size);
        !           644:     tpic_flush();
        !           645:     tpic_path(size, 0);
        !           646:     tpic_path(-size, 0);
        !           647:     tpic_flush();
        !           648:     return;
        !           649: }
        !           650:
        !           651: void tpic_box(size)
        !           652: int size;
        !           653: {
        !           654:     tpic_path(size, size);
        !           655:     tpic_path(-size, size);
        !           656:     tpic_path(-size, -size);
        !           657:     tpic_path(size, -size);
        !           658:     tpic_path(size, size);
        !           659:     tpic_flush();
        !           660:     return;
        !           661: }
        !           662:
        !           663: void tpic_times(size)
        !           664: int size;
        !           665: {
        !           666:     size = (int) (size / 1.4142);      /* reduce by sqrt(2) */
        !           667:
        !           668:     tpic_path(size, size);
        !           669:     tpic_path(-size, -size);
        !           670:     tpic_flush();
        !           671:     tpic_path(size, -size);
        !           672:     tpic_path(-size, size);
        !           673:     tpic_flush();
        !           674:     return;
        !           675: }
        !           676:
        !           677: void tpic_triangle(size)
        !           678: int size;
        !           679: {
        !           680:     int x;
        !           681:
        !           682:     size = (int) (size / 1.6119);      /* reduce by sqrt(3 * sqrt(3) / 2) */
        !           683:     x = (int) (size * 1.7321);
        !           684:
        !           685:     tpic_path(0, -size * 2);
        !           686:     tpic_path(-x, size);
        !           687:     tpic_path(x, size);
        !           688:     tpic_path(0, -size * 2);
        !           689:     tpic_flush();
        !           690:     return;
        !           691: }
        !           692:
        !           693: void tpic_star(size)
        !           694: int size;
        !           695: {
        !           696:     int x;
        !           697:
        !           698:     size = (int) (size / 2);   /* reduce by 2 */
        !           699:     x = (int) (size * 1.7321);
        !           700:
        !           701:     tpic_path(0, size * 2);
        !           702:     tpic_path(0, -size * 2);
        !           703:     tpic_flush();
        !           704:     tpic_path(x, size);
        !           705:     tpic_path(-x, -size);
        !           706:     tpic_flush();
        !           707:     tpic_path(x, -size);
        !           708:     tpic_path(-x, size);
        !           709:     tpic_flush();
        !           710:     return;
        !           711: }
        !           712:
        !           713: void tpic_hexagon(size)
        !           714: int size;
        !           715: {
        !           716:     int x;
        !           717:
        !           718:     size = (int) (size / 2);   /* reduce by 2 */
        !           719:     x = (int) (size * 1.7321);
        !           720:
        !           721:     tpic_path(0, size * 2);
        !           722:     tpic_path(-x, size);
        !           723:     tpic_path(-x, -size);
        !           724:     tpic_path(0, -size * 2);
        !           725:     tpic_path(x, -size);
        !           726:     tpic_path(x, size);
        !           727:     tpic_path(0, size * 2);
        !           728:     tpic_flush();
        !           729:     return;
        !           730: }
        !           731:
        !           732: void tpic_circle(size)
        !           733: int size;
        !           734: {
        !           735:     tpic_arc(size);
        !           736:     return;
        !           737: }
        !           738:
        !           739: void tpic_doublecircle(size)
        !           740: int size;
        !           741: {
        !           742:     tpic_arc(size);
        !           743:     tpic_shade(0.0);
        !           744:     tpic_arc(size / 2);
        !           745:     return;
        !           746: }
        !           747:
        !           748: void tpic_vercircle(size)
        !           749: int size;                      /* circle with | */
        !           750: {
        !           751:     tpic_arc(size);
        !           752:     tpic_path(0, size);
        !           753:     tpic_path(0, -size);
        !           754:     tpic_flush();
        !           755:     return;
        !           756: }
        !           757:
        !           758: void tpic_horcircle(size)
        !           759: int size;                      /* circle with - */
        !           760: {
        !           761:     tpic_arc(size);
        !           762:     tpic_path(size, 0);
        !           763:     tpic_path(-size, 0);
        !           764:     tpic_flush();
        !           765:     return;
        !           766: }
        !           767:
        !           768: void tpic_pluscircle(size)
        !           769: int size;                      /* circle with + */
        !           770: {
        !           771:     tpic_arc(size);
        !           772:     tpic_plus(size);
        !           773:     return;
        !           774: }
        !           775:
        !           776: void tpic_timescircle(size)
        !           777: int size;                      /* circle with times */
        !           778: {
        !           779:     tpic_arc(size);
        !           780:     tpic_times(size);
        !           781:     return;
        !           782: }
        !           783:
        !           784: void tpic_starcircle(size)
        !           785: int size;                      /* circle with star */
        !           786: {
        !           787:     tpic_arc(size);
        !           788:     tpic_star(size);
        !           789:     return;
        !           790: }
        !           791:
        !           792: void tpic_dotcircle(size)
        !           793: int size;                      /* circle with dot (black circle) */
        !           794: {
        !           795:     tpic_arc(size);
        !           796:     tpic_shade(1.0);
        !           797:     tpic_arc(size / 2);
        !           798:     return;
        !           799: }
        !           800:
        !           801: void tpic_diamondcircle(size)
        !           802: int size;                      /* not enough? circle with black diamond */
        !           803: {
        !           804:     tpic_arc(size);
        !           805:     tpic_shade(1.0);
        !           806:     tpic_diamond((int) (size / 1.5));
        !           807:     return;
        !           808: }
        !           809:
        !           810: void tpic_boxcircle(size)
        !           811: int size;                      /* need more? circle with black box */
        !           812: {
        !           813:     tpic_arc(size);
        !           814:     tpic_shade(1.0);
        !           815:     tpic_box((int) (size / 1.5));
        !           816:     return;
        !           817: }
        !           818:
        !           819: void tpic_trianglecircle(size)
        !           820: int size;                      /* circle with black triangle */
        !           821: {
        !           822:     tpic_arc(size);
        !           823:     tpic_shade(1.0);
        !           824:     tpic_triangle((int) (size / 1.5));
        !           825:     return;
        !           826: }
        !           827:
        !           828: void tpic_hexagoncircle(size)
        !           829: int size;                      /* how about circle with black hexagon? */
        !           830: {
        !           831:     tpic_arc(size);
        !           832:     tpic_shade(1.0);
        !           833:     tpic_hexagon((int) (size / 1.2));
        !           834:     return;
        !           835: }
        !           836:
        !           837: void tpic_plustimescircle(size)
        !           838: int size;                      /* no more idea ... with plus & times */
        !           839: {
        !           840:     tpic_arc(size);
        !           841:     tpic_plus(size);
        !           842:     tpic_times(size);
        !           843:     return;
        !           844: }
        !           845:
        !           846: /* private: draw lines */
        !           847:
        !           848: void tpic_abspath(x, y)
        !           849: unsigned int x;
        !           850: unsigned int y;                        /* absolute coord */
        !           851: {
        !           852:     fprintf(gpoutfile, "\\put(%u,%u){", x, y); /* start putting */
        !           853:     tpic_path(0, 0);
        !           854:     fputs("}%\n", gpoutfile);  /* end putting */
        !           855:     return;
        !           856: }
        !           857:
        !           858: /* private: tpic primitive functions */
        !           859:
        !           860: void tpic_path(x, y)
        !           861: int x;
        !           862: int y;
        !           863: {
        !           864:     fprintf(gpoutfile, "\\special{pa %d %d}", x, y);
        !           865:     return;
        !           866: }
        !           867:
        !           868: void tpic_flush()
        !           869: {
        !           870:     fputs("\\special{fp}%\n", gpoutfile);
        !           871:     return;
        !           872: }
        !           873:
        !           874: void tpic_arc(radius)
        !           875: int radius;                    /* actually, draw a full circle */
        !           876: {
        !           877:     fprintf(gpoutfile, "\\special{ar 0 0 %d %d 0 7}", radius, radius);
        !           878:     return;
        !           879: }
        !           880:
        !           881: void tpic_shade(grayscale)
        !           882: double grayscale;
        !           883: {
        !           884:     fprintf(gpoutfile, "\\special{sh %f}", grayscale);
        !           885:     return;
        !           886: }
        !           887:
        !           888: void tpic_pen(thickness)
        !           889: int thickness;
        !           890: {
        !           891:     fprintf(gpoutfile, "\\special{pn %d}", thickness);
        !           892:     return;
        !           893: }
        !           894:
        !           895: void tpic_dottedflush(interval)
        !           896: double interval;
        !           897: {
        !           898:     fprintf(gpoutfile, "\\special{dt %f}%%\n", interval);
        !           899:     return;
        !           900: }
        !           901:
        !           902: void tpic_dashedflush(interval)
        !           903: double interval;
        !           904: {
        !           905:     fprintf(gpoutfile, "\\special{da %f}%%\n", interval);
        !           906:     return;
        !           907: }
        !           908:
        !           909: #endif /* TERM_BODY */
        !           910:
        !           911: #ifdef TERM_TABLE
        !           912:
        !           913: TERM_TABLE_START(tpic_driver)
        !           914:     "tpic", "TPIC -- LaTeX picture environment with tpic \\specials",
        !           915:     TPIC_XMAX, TPIC_YMAX, TPIC_VCHAR, TPIC_HCHAR,
        !           916:     TPIC_VTIC, TPIC_HTIC, TPIC_options, TPIC_init, TPIC_reset,
        !           917:     TPIC_text, null_scale, TPIC_graphics, TPIC_move, TPIC_vector,
        !           918:     TPIC_linetype, TPIC_put_text, TPIC_text_angle,
        !           919:     TPIC_justify_text, TPIC_point, TPIC_arrow, set_font_null
        !           920: TERM_TABLE_END(tpic_driver)
        !           921:
        !           922: #undef LAST_TERM
        !           923: #define LAST_TERM tpic_driver
        !           924:
        !           925: #endif /* TERM_TABLE */
        !           926: #endif /* TERM_PROTO_ONLY */
        !           927:
        !           928: #ifdef TERM_HELP
        !           929: START_HELP(tpic)
        !           930: "1 tpic",
        !           931: "?commands set terminal tpic",
        !           932: "?set terminal tpic",
        !           933: "?set term tpic",
        !           934: "?terminal tpic",
        !           935: "?term tpic",
        !           936: "?tpic",
        !           937: " The `tpic` terminal driver supports the LaTeX picture environment with tpic",
        !           938: " \\specials.  It is an alternative to the `latex` and `eepic` terminal drivers.",
        !           939: " Options are the point size, line width, and dot-dash interval.",
        !           940: "",
        !           941: " Syntax:",
        !           942: "       set terminal tpic <pointsize> <linewidth> <interval>",
        !           943: "",
        !           944: " where `pointsize` and `linewidth` are integers in milli-inches and `interval`",
        !           945: " is a float in inches.  If a non-positive value is specified, the default is",
        !           946: " chosen: pointsize = 40, linewidth = 6, interval = 0.1.",
        !           947: "",
        !           948: " All drivers for LaTeX offer a special way of controlling text positioning:",
        !           949: " If any text string begins with '{', you also need to include a '}' at the",
        !           950: " end of the text, and the whole text will be centered both horizontally",
        !           951: " and vertically by LaTeX. --- If the text string begins with '[', you need",
        !           952: " to continue it with: a position specification (up to two out of t,b,l,r),",
        !           953: " ']{', the text itself, and finally, '}'. The text itself may be anything",
        !           954: " LaTeX can typeset as an LR-box. \\rule{}{}'s may help for best positioning.",
        !           955: "",
        !           956: " Examples:",
        !           957: " About label positioning:",
        !           958: " Use gnuplot defaults (mostly sensible, but sometimes not really best):",
        !           959: "        set title '\\LaTeX\\ -- $ \\gamma $'",
        !           960: " Force centering both horizontally and vertically:",
        !           961: "        set label '{\\LaTeX\\ -- $ \\gamma $}' at 0,0",
        !           962: " Specify own positioning (top here):",
        !           963: "        set xlabel '[t]{\\LaTeX\\ -- $ \\gamma $}'",
        !           964: " The other label -- account for long ticlabels:",
        !           965: "        set ylabel '[r]{\\LaTeX\\ -- $ \\gamma $\\rule{7mm}{0pt}'"
        !           966: END_HELP(tpic)
        !           967: #endif /* TERM_TABLE */

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