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

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

1.1       maekawa     1: /*
1.1.1.2 ! maekawa     2:  * $Id: gpic.trm,v 1.7 1998/12/14 18:39:28 lhecking Exp $
1.1       maekawa     3:  */
                      4:
                      5: /* GNUPLOT - gpic.trm -*-C-*- */
                      6:
                      7: /*[
                      8:  * Copyright 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:
                     41: /*
                     42:  * This terminal driver supports:
                     43:  *   The GPIC graphics language for groff
                     44:  *
                     45:  * AUTHOR
                     46:  *  Sigfrid Lundberg
                     47:  *
                     48:  * send your comments or suggestions to (siglun@volterra.teorekol.lu.se).
                     49:  *
                     50:  */
                     51:
                     52: /*
                     53:  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
                     54:  */
                     55:
                     56: #include "driver.h"
                     57:
                     58: #ifdef TERM_REGISTER
                     59: register_term(gpic)
                     60: #endif
                     61:
                     62: #ifdef TERM_PROTO
                     63: TERM_PUBLIC void GPIC_options __PROTO((void));
                     64: TERM_PUBLIC void GPIC_init __PROTO((void));
                     65: TERM_PUBLIC void GPIC_graphics __PROTO((void));
                     66: TERM_PUBLIC void GPIC_text __PROTO((void));
                     67: TERM_PUBLIC void GPIC_linetype __PROTO((int linetype));
                     68: TERM_PUBLIC void GPIC_move __PROTO((unsigned int x, unsigned int y));
                     69: TERM_PUBLIC void GPIC_vector __PROTO((unsigned int ux, unsigned int uy));
                     70: TERM_PUBLIC void GPIC_arrow __PROTO((unsigned int sx, unsigned int sy,
                     71:                                     unsigned int ex, unsigned int ey,
                     72:                                     TBOOLEAN head));
                     73: TERM_PUBLIC void GPIC_put_text __PROTO((unsigned int x, unsigned int y,
                     74:                                        char str[]));
                     75: TERM_PUBLIC int GPIC_justify_text __PROTO((enum JUSTIFY mode));
                     76: TERM_PUBLIC int GPIC_text_angle __PROTO((int ang));
                     77: TERM_PUBLIC void GPIC_reset __PROTO((void));
                     78: #define GPIC_DOTS_PER_INCH (300)
                     79:
                     80: /* 5 inches wide by 3 inches high (default) */
                     81: #define GPIC_XMAX (5*GPIC_DOTS_PER_INCH)
                     82: #define GPIC_YMAX (3*GPIC_DOTS_PER_INCH)
                     83:
                     84: #define GPIC_HTIC (5*GPIC_DOTS_PER_INCH/72)
                     85: #define GPIC_VTIC (5*GPIC_DOTS_PER_INCH/72)
                     86: #define GPIC_HCHAR (GPIC_DOTS_PER_INCH*53/10/72)
                     87: #define GPIC_VCHAR (GPIC_DOTS_PER_INCH*11/72)
                     88: #endif /* TERM_PROTO */
                     89:
                     90: #ifndef TERM_PROTO_ONLY
                     91: #ifdef TERM_BODY
                     92:
                     93: #define GPIC_PTS_PER_INCH (72.27)
                     94: /* dot size in pt */
                     95: #define GPIC_UNIT (GPIC_PTS_PER_INCH/GPIC_DOTS_PER_INCH)
                     96: #define GPIC_coord(x) ((float)x)/((float)GPIC_DOTS_PER_INCH)
                     97:
                     98: void GPIC_close_line __PROTO((void));
                     99: static float GPIC_x, GPIC_y;
                    100: static unsigned int GPIC_ltype;
                    101: enum JUSTIFY GPIC_justify = LEFT;
                    102:
                    103: /* for DOTS point style */
                    104:
                    105: static char *GPIC_lines[] =
                    106: {
                    107:     "thickness 1.0",           /* -2 border */
                    108:     "",                                /* -1 axes */
                    109:     "",                                /*  0 solid thin  */
                    110:     "dotted",
                    111:     "dashed 0.05",             /*  1 solid thick */
                    112:     "dashed 0.075",            /*  2 solid Thick */
                    113: };
                    114:
                    115: /* number of linetypes above */
                    116: #define GPIC_NUMLINES (sizeof(GPIC_lines)/sizeof(char *))
                    117:
                    118:
                    119: static int GPIC_linecount = 0; /* number of points in line so far */
                    120:
                    121:
                    122: TERM_PUBLIC void GPIC_options()
                    123: {
                    124:     float x, y;
                    125:     struct value a;
                    126:
                    127:     GPIC_x = 0;
                    128:     GPIC_y = 0;
                    129:
                    130:     if (!END_OF_COMMAND) {
                    131:        x = real(const_express(&a));
                    132:        if (!END_OF_COMMAND) {
                    133:            y = real(const_express(&a));
                    134:            GPIC_x = x;
                    135:            GPIC_y = y;
                    136:        }
                    137:     }
                    138:     sprintf(term_options, "Origin is at (%f,%f)", GPIC_x, GPIC_y);
                    139:
                    140: }
                    141:
                    142: TERM_PUBLIC void GPIC_init()
                    143: {
                    144:     GPIC_linetype(-1);
                    145:     fputs(".\\\"GNUPLOT: GROFF picture using the gpic preprocessor\n", gpoutfile);
                    146: }
                    147:
                    148:
                    149:
                    150: TERM_PUBLIC void GPIC_graphics()
                    151: {
                    152:     register struct termentry *t = term;
                    153:
                    154:     fprintf(gpoutfile, ".PS %f %f\n", GPIC_coord(t->xmax),
                    155:            GPIC_coord(t->ymax));
                    156:     fprintf(gpoutfile, "x=%f; y=%f\n", GPIC_x, GPIC_y);
                    157: }
                    158:
                    159:
                    160: TERM_PUBLIC void GPIC_text()
                    161: {
                    162:     GPIC_close_line();
                    163:     fputs(".PE\n", gpoutfile);
                    164: }
                    165:
                    166: TERM_PUBLIC void GPIC_linetype(linetype)
                    167: int linetype;
                    168: {
                    169:     if (linetype >= GPIC_NUMLINES - 2)
                    170:        linetype %= (GPIC_NUMLINES - 2);
                    171:     GPIC_ltype = linetype;
                    172: }
                    173:
                    174: void GPIC_close_line()
                    175: {
                    176:     if (GPIC_linecount > 0) {
                    177:        fputs("; reset linewid\n", gpoutfile);
                    178:        GPIC_linecount = 0;
                    179:     }
                    180: }
                    181:
                    182: TERM_PUBLIC void GPIC_move(x, y)
                    183: unsigned int x, y;
                    184: {
                    185:     GPIC_close_line();
                    186:     fprintf(gpoutfile, "move to (x+%f,y+%f)\n", GPIC_coord(x), GPIC_coord(y));
                    187:     GPIC_linecount = 1;
                    188: }
                    189:
                    190:
                    191: TERM_PUBLIC void GPIC_vector(ux, uy)
                    192: unsigned int ux, uy;
                    193: {
                    194:     if (GPIC_linecount == 1) {
                    195:        fprintf(gpoutfile, "line %s to (x+%f,y+%f)",
                    196:                GPIC_lines[GPIC_ltype + 2],
                    197:                GPIC_coord(ux), GPIC_coord(uy));
                    198:     } else {
                    199:        fprintf(gpoutfile, "\
                    200:  \\\n\
                    201:    then to (x+%f,y+%f)",
                    202:                GPIC_coord(ux), GPIC_coord(uy));
                    203:     }
                    204:     GPIC_linecount++;
                    205: }
                    206:
                    207:
                    208: TERM_PUBLIC void GPIC_arrow(sx, sy, ex, ey, head)
                    209: unsigned int sx, sy, ex, ey;
                    210: TBOOLEAN head;
                    211: {
                    212:     GPIC_close_line();
                    213:     if (head) {
                    214:        fprintf(gpoutfile, "arrowhead=7; arrow from x+%f,y+%f to x+%f,y+%f\n",
                    215:                GPIC_coord(sx), GPIC_coord(sy), GPIC_coord(ex), GPIC_coord(ey));
                    216:     } else {
                    217:        fprintf(gpoutfile, "line from x+%f,y+%f to x+%f,y+%f\n",
                    218:                GPIC_coord(sx), GPIC_coord(sy), GPIC_coord(ex), GPIC_coord(ey));
                    219:     }
                    220: }
                    221:
                    222:
                    223: TERM_PUBLIC void GPIC_put_text(x, y, str)
                    224: unsigned int x, y;             /* reference point of string */
                    225: char str[];                    /* the text */
                    226: {
                    227:     GPIC_close_line();
                    228:     fprintf(gpoutfile, "\"%s\" ", str);
                    229:     switch (GPIC_justify) {
                    230:     case LEFT:{
                    231:            fputs("ljust ", gpoutfile);
                    232:            break;
                    233:        }
                    234:     case CENTRE:{
                    235:            fputs(" ", gpoutfile);
                    236:            break;
                    237:        }
                    238:     case RIGHT:{
                    239:            fputs("rjust ", gpoutfile);
                    240:            break;
                    241:        }
                    242:     }
                    243:     fprintf(gpoutfile, "at x+%f,y+%f\n", GPIC_coord(x), GPIC_coord(y));
                    244: }
                    245:
                    246:
                    247:
                    248: TERM_PUBLIC int GPIC_justify_text(mode)
                    249: enum JUSTIFY mode;
                    250: {
                    251:     GPIC_justify = mode;
                    252:     return (TRUE);
                    253: }
                    254:
                    255: TERM_PUBLIC int GPIC_text_angle(ang)
                    256: int ang;
                    257: {
                    258:     GPIC_close_line();
                    259:     return (FALSE);
                    260: }
                    261:
                    262: TERM_PUBLIC void GPIC_reset()
                    263: {
                    264:     fflush(gpoutfile);
                    265: }
                    266:
                    267: #endif /* TERM_BODY */
                    268:
                    269: #ifdef TERM_TABLE
                    270:
                    271: TERM_TABLE_START(gpic_driver)
                    272:     "gpic", "GPIC -- Produce graphs in groff using the gpic preprocessor",
                    273:     GPIC_XMAX, GPIC_YMAX, GPIC_VCHAR, GPIC_HCHAR,
                    274:     GPIC_VTIC, GPIC_HTIC, GPIC_options, GPIC_init, GPIC_reset,
                    275:     GPIC_text, null_scale, GPIC_graphics, GPIC_move, GPIC_vector,
                    276:     GPIC_linetype, GPIC_put_text, GPIC_text_angle,
                    277:     GPIC_justify_text, line_and_point, GPIC_arrow, set_font_null
                    278: TERM_TABLE_END(gpic_driver)
                    279: #undef LAST_TERM
                    280: #define LAST_TERM gpic_driver
                    281:
                    282: #endif /* TERM_TABLE */
                    283: #endif /* TERM_PROTO_ONLY */
                    284:
                    285: #ifdef TERM_HELP
                    286: START_HELP(gpic)
                    287: "1 gpic",
                    288: "?commands set terminal gpic",
                    289: "?set terminal gpic",
                    290: "?set term gpic",
                    291: "?terminal gpic",
                    292: "?term gpic",
                    293: "?gpic",
                    294: " The `gpic` terminal driver generates GPIC graphs in the Free Software",
                    295: " Foundations's \"groff\" package.  The default size is 5 x 3 inches.  The only",
                    296: " option is the origin, which defaults to (0,0).",
                    297: "",
                    298: " Syntax:",
                    299: "       set terminal gpic {<x> <y>}",
                    300: "",
                    301: " where `x` and `y` are in inches.",
                    302: "",
                    303: " A simple graph can be formatted using",
                    304: "",
                    305: "       groff -p -mpic -Tps file.pic > file.ps.",
                    306: "",
                    307: " The output from pic can be pipe-lined into eqn, so it is possible to put",
                    308: " complex functions in a graph with the `set label` and `set {x/y}label`",
                    309: " commands.  For instance,",
                    310: "",
                    311: "       set ylab '@space 0 int from 0 to x alpha ( t ) roman d t@'",
                    312: "",
                    313: " will label the y axis with a nice integral if formatted with the command:",
                    314: "",
                    315: "       gpic filename.pic | geqn -d@@ -Tps | groff -m[macro-package] -Tps",
                    316: "           > filename.ps",
                    317: "",
                    318: " Figures made this way can be scaled to fit into a document.  The pic language",
                    319: " is easy to understand, so the graphs can be edited by hand if need be.  All",
                    320: " co-ordinates in the pic-file produced by `gnuplot` are given as x+gnuplotx",
                    321: " and y+gnuploty.  By default x and y are given the value 0.  If this line is",
                    322: " removed with an editor in a number of files, one can put several graphs in",
                    323: " one figure like this (default size is 5.0x3.0 inches):",
                    324: "",
                    325: "       .PS 8.0",
                    326: "       x=0;y=3",
                    327: "       copy \"figa.pic\"",
                    328: "       x=5;y=3",
                    329: "       copy \"figb.pic\"",
                    330: "       x=0;y=0",
                    331: "       copy \"figc.pic\"",
                    332: "       x=5;y=0",
                    333: "       copy \"figd.pic\"",
                    334: "       .PE",
                    335: "",
                    336: " This will produce an 8-inch-wide figure with four graphs in two rows on top",
                    337: " of each other.",
                    338: "",
                    339: " One can also achieve the same thing by the command",
                    340: "",
                    341: "       set terminal gpic x y",
                    342: "",
                    343: " for example, using",
                    344: "",
                    345: "       .PS 6.0",
                    346: "       copy \"trig.pic\"",
                    347: "       .PE"
                    348: END_HELP(gpic)
                    349: #endif /* TERM_HELP */

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