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

Annotation of OpenXM_contrib/gnuplot/term/fig.trm, Revision 1.1.1.3

1.1       maekawa     1: /*
1.1.1.3 ! ohara       2:  * $Id: fig.trm,v 1.10.2.6 2002/12/11 19:24:26 lhecking Exp $
1.1       maekawa     3:  */
                      4:
                      5: /* GNUPLOT - fig.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:  *  Fig graphics language
                     42:  *
                     43:  * AUTHORS
                     44:  *  Micah Beck, David Kotz
                     45:  *
                     46:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
                     47:  *
                     48:  */
                     49:
                     50: /*
                     51:  * Original for Fig code output by Micah Beck, 1989
                     52:  * Department of Computer Science, Cornell University
                     53:  * Updated by David Kotz for gnuplot 2.0
                     54:  * More efficient output by Ian Dall
                     55:  * Updated to FIG 2.1 (with color) format by Vivek Khera
                     56:  * Updated to FIG 3.1 (higher resolution) format by Ian MacPhedran, Jan 1995
                     57:  * Updated to conform to newterm format Ian MacPhedran, Apr 1995
                     58:  * Point-count option joachim.selinger@ins.uni-stuttgart.de (JFS) Feb  9 1996
                     59:  * More options (portrait/landscape, metric/inches, size, fontsize, thickness)
                     60:  * plus symbols and depth/thickness by bernlohr@eu1.mpi-hd.mpg.de (KB) Aug 15 1996
                     61:  */
                     62:
                     63: #include "driver.h"
                     64:
                     65: #ifdef TERM_REGISTER
                     66: register_term(fig)
                     67: #endif /* TERM_REGISTER */
                     68:
                     69: #ifdef TERM_PROTO
                     70: TERM_PUBLIC void FIG_options __PROTO((void));
                     71: TERM_PUBLIC void FIG_init __PROTO((void));
                     72: TERM_PUBLIC void FIG_graphics __PROTO((void));
                     73: TERM_PUBLIC void FIG_text __PROTO((void));
                     74: TERM_PUBLIC void FIG_linetype __PROTO((int linetype));
                     75: TERM_PUBLIC void FIG_move __PROTO((unsigned int x, unsigned int y));
                     76: TERM_PUBLIC void FIG_vector __PROTO((unsigned int ux, unsigned int uy));
                     77: TERM_PUBLIC void FIG_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, TBOOLEAN head));
                     78: TERM_PUBLIC void FIG_put_text __PROTO((unsigned int x, unsigned int y, char *str));
                     79: TERM_PUBLIC int FIG_justify_text __PROTO((enum JUSTIFY mode));
                     80: TERM_PUBLIC int FIG_text_angle __PROTO((int ang));
                     81: TERM_PUBLIC void FIG_pointsize __PROTO((double arg_pointsize));
                     82: TERM_PUBLIC void FIG_linewidth __PROTO((double linewidth));
                     83: TERM_PUBLIC void FIG_reset __PROTO((void));
                     84: TERM_PUBLIC void FIG_lpoint __PROTO((unsigned int x, unsigned int y, int number));
                     85:
                     86: #define GOT_FIG_PROTO
                     87: #endif /* TERM_PROTO */
                     88:
                     89: #ifndef TERM_PROTO_ONLY
                     90: #ifdef TERM_BODY
                     91:
                     92: #include "object.h"            /* modified from the XFig distribution */
                     93: #define FIG_DEFAULT DEFAULT
                     94: #define FIG_ROMAN_FONT (0)     /* actually, the default font */
                     95:
1.1.1.3 ! ohara      96: #if METRIC
        !            97: # define INCH FALSE
        !            98: #else
        !            99: # define INCH TRUE
1.1       maekawa   100: #endif
                    101:
1.1.1.3 ! ohara     102: /* These should not be defined elsewhere - ACZ */
        !           103: /* This is now 1200 per inch */
        !           104: #define FIG_IRES        (1200)
        !           105: /* This is now 450 per cm */
        !           106: #define FIG_MRES        (450)
        !           107:
1.1       maekawa   108: #define FIG_COORD_SYS   2
                    109: #define FIG_ORIENT (FIG_portrait?"Portrait":"Landscape")
                    110: /* Could be "Portrait" */
1.1.1.3 ! ohara     111: #define FIG_JUST        "Center"
1.1       maekawa   112: /* Could be "Flush Left" */
                    113: #define FIG_UNIT (FIG_inches?"Inches":"Metric")
                    114: /* Could be "Inches" */
1.1.1.3 ! ohara     115: #define FIG_PAPER       (FIG_inches ? "Letter" : "A4")
        !           116: #define FIG_MAGNIFICATION  100.0
        !           117: #define FIG_MULTIPAGE   "Single"
        !           118: /* Could be "Multiple" */
        !           119: #define FIG_TRANSCOLOR  -2
        !           120: /* none: -2; background: -1; 0..31: foreground colors */
        !           121: /* This could probably be dropped with the support of GIFs. */
        !           122: #define FIG_TRUERES (FIG_inches ? FIG_IRES : FIG_MRES) /* ACZ */
        !           123:
        !           124: #define FIG_MAGIC       "#FIG 3.2" /* new file format - ACZ */
        !           125: #define FIG_HTIC(inch)  ((inch) ? (5*FIG_IRES)/80 : (15*FIG_MRES)/100)
        !           126: #define FIG_VTIC(inch)  ((inch) ? (5*FIG_IRES)/80 : (15*FIG_MRES)/100)
1.1       maekawa   127: #define FIG_FONT_S      (10)   /* size in points */
                    128: #define FIG_MAX_POINTS  99999L /* almost infinite ;-) */
                    129:
1.1.1.3 ! ohara     130: /* height of font in pixels: */
        !           131: #define FIG_to_pixel_v(inch,s) (((inch) ? (s)*FIG_IRES : (s)*FIG_MRES*2.54) / 72 * 3/4)
1.1       maekawa   132: /* This is fudged to enlarge the drawing area, but gives fairly good results */
1.1.1.3 ! ohara     133: /* this is a guess at the width: */
        !           134: #define FIG_to_pixel_h(inch,s) (FIG_to_pixel_v(inch,s)*6/10)
1.1       maekawa   135:
1.1.1.3 ! ohara     136: #define FIG_VCHAR       FIG_to_pixel_v(INCH,FIG_FONT_S)        /* just for default, */
        !           137: #define FIG_HCHAR       FIG_to_pixel_h(INCH,FIG_FONT_S)        /* not really used   */
1.1       maekawa   138:
                    139: enum FIG_poly_stat {
                    140:     FIG_poly_new, FIG_poly_part
                    141: };
                    142:
                    143: static int FIG_posx;
                    144: static int FIG_posy;
                    145: static long FIG_poly_vec_cnt;
                    146: static int FIG_depth = 10;
                    147: static int FIG_linedepth = 10;
                    148: static int FIG_thickness = 1;
                    149: static int FIG_default_thickness = 1;
                    150: static double FIG_current_pointsize = 1.;
                    151: static double FIG_current_linewidth = 1.;
                    152:
                    153: /* Maximum number of points per POLYLINE.
                    154:    Default 1000 (hardcoded in help section as well) */
                    155: static int FIG_poly_vec_max = 999;     /* JFS */
                    156:
                    157: static enum FIG_poly_stat FIG_polyvec_stat;
                    158:
                    159: /* 5 inches wide by 3 inches high */
1.1.1.3 ! ohara     160: #define FIG_XMAX(inch) ((inch) ? 5*FIG_IRES : 12*FIG_MRES)
        !           161: #define FIG_YMAX(inch) ((inch) ? 3*FIG_IRES :  8*FIG_MRES)
1.1       maekawa   162:
1.1.1.3 ! ohara     163: #define FIG_XOFF(inch) ((inch) ? FIG_IRES : 2*FIG_MRES)
        !           164: #define FIG_YOFF(inch) ((inch) ? FIG_IRES : 2*FIG_MRES)
1.1       maekawa   165:
                    166:
1.1.1.3 ! ohara     167: #define BFIG_HTIC(inch) ((inch) ? (7*FIG_IRES)/80 : (20*FIG_MRES)/100)
        !           168: #define BFIG_VTIC(inch) ((inch) ? (7*FIG_IRES)/80 : (20*FIG_MRES)/100)
1.1       maekawa   169: #define BFIG_FONT_S     (16)   /* size in points */
1.1.1.3 ! ohara     170: #define BFIG_VCHAR      FIG_to_pixel_v(INCH,BFIG_FONT_S)  /* height in pixels of font */
        !           171: #define BFIG_HCHAR      FIG_to_pixel_h(INCH,BFIG_FONT_S)  /* this is a guess at the width */
1.1       maekawa   172:
                    173: static F_point *FIG_points = NULL;     /* Array for the collection of points for
                    174:                                           POLYLINE, allocated on demand. */
                    175: static F_line FIG_line;
                    176:
                    177: /* 8 inches wide by 5 inches high */
1.1.1.3 ! ohara     178: #define BFIG_XMAX(inch) ((inch) ? 8*FIG_IRES : 20*FIG_MRES)
        !           179: #define BFIG_YMAX(inch) ((inch) ? 5*FIG_IRES : 15*FIG_MRES)
1.1       maekawa   180:
1.1.1.3 ! ohara     181: #define BFIG_XOFF(inch) ((inch) ? FIG_IRES : 2*FIG_MRES)
        !           182: #define BFIG_YOFF(inch) ((inch) ? FIG_IRES : 2*FIG_MRES)
1.1       maekawa   183:
                    184:
                    185: static int FIG_type;           /* negative types use real lines */
                    186: static float FIG_spacing;      /* length of dash or dot spacing */
                    187: static int FIG_justify;                /* Fig justification T_*_JUSTIFIED */
                    188: static float FIG_angle;                /* Fig text angle 0=horiz, Pi/2=vert */
                    189: static int FIG_use_color = FALSE;      /* do we use color or not? */
                    190: static int FIG_is_big = FALSE; /* big plot ? */
                    191: static int FIG_color = DEFAULT;        /* which color to use */
1.1.1.3 ! ohara     192: static int FIG_xoff = FIG_XOFF(INCH);
        !           193: static int FIG_yoff = FIG_YOFF(INCH);
1.1       maekawa   194: static int FIG_font_s = FIG_FONT_S;
                    195: static int FIG_portrait = FALSE;
1.1.1.3 ! ohara     196: static int FIG_inches = INCH;
1.1       maekawa   197:
                    198: static void FIG_poly_clean __PROTO((enum FIG_poly_stat fig_stat));
                    199:
                    200:
                    201: #define FIG_POINT_TYPES POINT_TYPES    /* we use the same points */
                    202:
                    203:
                    204: static void FIG_poly_clean(fig_stat)
                    205: enum FIG_poly_stat fig_stat;
                    206: {
                    207:     int i, j;
                    208:     if (fig_stat == FIG_poly_part) {
                    209:        fprintf(gpoutfile, "%d %d %d %d %d %d %d %d %d %9.3f %d %d %d %d %d %ld\n\t",
                    210:                O_POLYLINE, FIG_line.type, FIG_line.style, FIG_line.thickness,
                    211:                FIG_line.pen_color, FIG_line.fill_color, FIG_line.depth,
                    212:                FIG_line.pen_style, FIG_line.fill_style, FIG_line.style_val,
                    213:                FIG_line.join_style, FIG_line.cap_style, FIG_line.radius,
                    214:                0, 0, FIG_poly_vec_cnt);
                    215:
                    216:        j = 0;
                    217:        for (i = 0; i < FIG_poly_vec_cnt; i++) {
                    218:            fprintf(gpoutfile, " %d %d", FIG_points[i].x, FIG_points[i].y);
                    219:            if (j++ > 4 && i != FIG_poly_vec_cnt - 1) {
                    220:                fputs("\n\t", gpoutfile);
                    221:                j = 0;          /* JFS */
                    222:            }
                    223:        }
                    224:        if (j != 0) {
                    225:            putc('\n', gpoutfile);
                    226:        }
                    227:        /* Give the memory back to the system because we are done with this
                    228:         * polyline. Make sure FIG_points contains NULL afterwards!
                    229:         */
                    230:        free(FIG_points);
                    231:        FIG_points = NULL;
                    232:     }
                    233:     FIG_polyvec_stat = FIG_poly_new;
                    234: }
                    235:
                    236: TERM_PUBLIC void FIG_options()
                    237: {
                    238:     static char *options_list =        /* sun cc does not concat strings */
                    239:     "expecting monochrome, color, small, big, portrait, landscape,\n\
                    240:  \t inches, metric, size <number> <number>,  fontsize <number>,\n\
                    241:  \t thickness <numer>, depth <number> or pointsmax <number>";
                    242:
                    243:     int parse_error = FALSE;
                    244:     long temp_max;
                    245:     struct value a;
                    246:     unsigned int tmax_t;
                    247:     double xsize_t, ysize_t;
                    248:
                    249:     FIG_use_color = FALSE;     /* default */
                    250:     FIG_is_big = FALSE;                /* default */
                    251:     FIG_portrait = FALSE;
                    252:     FIG_font_s = 0;
                    253:     FIG_default_thickness = 1;
                    254:     xsize_t = ysize_t = 0.;
1.1.1.3 ! ohara     255:     FIG_inches = INCH;
1.1       maekawa   256:     while (!END_OF_COMMAND) {
                    257:        if (almost_equals(c_token, "mo$nochrome")) {
                    258:            FIG_use_color = FALSE;
                    259:            c_token++;
                    260:        } else if (almost_equals(c_token, "c$olor")
                    261:                   || almost_equals(c_token, "c$olour")) {
                    262:            FIG_use_color = TRUE;
                    263:            c_token++;
                    264:        } else if (almost_equals(c_token, "sm$all")) {
                    265:            FIG_is_big = FALSE;
                    266:            c_token++;
                    267:        } else if (almost_equals(c_token, "b$ig")) {
                    268:            FIG_is_big = TRUE;
                    269:            c_token++;
                    270:        } else if (almost_equals(c_token, "in$ches")) {         /* KB */
                    271:            FIG_inches = TRUE;
                    272:            c_token++;
                    273:        } else if (almost_equals(c_token, "me$tric")) {         /* KB */
                    274:            FIG_inches = FALSE;
                    275:            c_token++;
                    276:        } else if (almost_equals(c_token, "por$trait")) {       /* KB */
                    277:            /* KB: Would have preferred "p$ortrait" but that would */
                    278:            /*     collide with "p$ointsmax" below. */
                    279:            FIG_portrait = TRUE;
                    280:            c_token++;
                    281:        } else if (almost_equals(c_token, "l$andscape")) {      /* KB */
                    282:            FIG_portrait = FALSE;
                    283:            c_token++;
                    284:        } else if (almost_equals(c_token, "si$ze")) {   /* KB */
                    285:            c_token++;
                    286:            if (END_OF_COMMAND) {
                    287:                int_error("size: 2 numbers expected", c_token);
                    288:            } else {
                    289:                xsize_t = real(const_express(&a));
                    290:                if (END_OF_COMMAND) {
                    291:                    int_error("size: 2 numbers expected", c_token);
                    292:                    xsize_t = 0.;
                    293:                } else {
                    294:                    ysize_t = real(const_express(&a));
                    295:                }
                    296:                if (xsize_t < 2. || ysize_t < 2. || xsize_t > 99. || ysize_t > 99.) {
                    297:                    if (xsize_t != 0. || ysize_t != 0.)
                    298:                        int_error("size: out of range", c_token);
                    299:                    xsize_t = ysize_t = 0.;
                    300:                }
                    301:            }
                    302:        } else if (almost_equals(c_token, "f$ontsize")) {       /* KB */
                    303:            c_token++;
                    304:            if (END_OF_COMMAND) {
                    305:                int_error("fontsize: number expected", c_token);
                    306:            } else {
                    307:                FIG_font_s = (int) real(const_express(&a));
                    308:                if (FIG_font_s < 5 || FIG_font_s > 36) {
                    309:                    int_error("fontsize out of range", c_token - 1);
                    310:                    FIG_font_s = 0;
                    311:                }
                    312:            }
                    313:        } else if (almost_equals(c_token, "t$hickness")) {      /* KB */
                    314:            c_token++;
                    315:            if (END_OF_COMMAND) {
                    316:                int_error("thickness: number expected", c_token);
                    317:            } else {
                    318:                FIG_default_thickness = (int) real(const_express(&a));
                    319:                if (FIG_default_thickness < 1 || FIG_default_thickness > 10) {
                    320:                    int_error("thickness out of range", c_token - 1);
                    321:                    FIG_default_thickness = 1;
                    322:                }
                    323:            }
                    324:        } else if (almost_equals(c_token, "d$epth")) {  /* KB */
                    325:            c_token++;
                    326:            if (END_OF_COMMAND) {
                    327:                int_error("depth: number expected", c_token);
                    328:            } else {
                    329:                FIG_depth = (int) real(const_express(&a));
                    330:                if (FIG_depth < 0 || FIG_depth > 99) {
                    331:                    int_error("depth out of range", c_token - 1);
                    332:                    FIG_depth = 10;
                    333:                }
                    334:                FIG_linedepth = FIG_depth;
                    335:            }
                    336:        } else if (almost_equals(c_token, "poi$ntsmax")) {      /* JFS */
                    337:            /* Skip the word and then expect the number ! */
                    338:            c_token++;
                    339:            if (END_OF_COMMAND) {
                    340:                int_error("max. points per polyline: number expected", c_token);
                    341:            } else {
                    342:                temp_max = (long) real(const_express(&a));
                    343:                /* Now check the range for the number */
                    344:                if ((temp_max > 1) && (temp_max < (FIG_MAX_POINTS + 2))) {
                    345:                    /* OK. subtract one to the right number! See other numbers... */
                    346:                    FIG_poly_vec_max = temp_max - 1;
                    347:                } else {
                    348:                    char t[128];
                    349:
                    350:                    sprintf(t, "pointsmax: number out of range (2,%ld)",
                    351:                            (FIG_MAX_POINTS + 1));
                    352:                    int_error(t, c_token);
                    353:                }
                    354:            }
                    355:        } else {
                    356:            parse_error = TRUE;
                    357:            int_error(options_list, c_token);
                    358:        }
                    359:     }
                    360:
                    361:     sprintf(term_options, "%s %s %s %d %s %s %s %d %s %d %s %d",
                    362:            FIG_use_color ? "color" : "monochrome",
                    363:            FIG_is_big ? "big" : "small",
                    364:            "pointsmax",
                    365:            FIG_poly_vec_max + 1,
                    366:            FIG_portrait ? "portrait" : "landscape",
                    367:            FIG_inches ? "inches" : "metric",
                    368:            "fontsize", (FIG_font_s > 0 ? FIG_font_s :
                    369:                         (FIG_is_big ? BFIG_FONT_S : FIG_FONT_S)),
                    370:            "thickness", FIG_default_thickness, "depth", FIG_depth);    /* JFS, KB */
                    371:     if (xsize_t > 0. && ysize_t > 0.) {
                    372:        if (xsize_t - (int) xsize_t == 0. && ysize_t - (int) ysize_t == 0.)
                    373:            sprintf(term_options + strlen(term_options),
                    374:                    " size %d %d", (int) xsize_t, (int) ysize_t);
                    375:        else
                    376:            sprintf(term_options + strlen(term_options),
                    377:                    " size %f %f", xsize_t, ysize_t);
                    378:     }
                    379:     if (!FIG_is_big) {
                    380:        if (FIG_font_s == 0)    /* KB */
                    381:            FIG_font_s = FIG_FONT_S;
1.1.1.3 ! ohara     382:        term->xmax = FIG_XMAX(FIG_inches);
        !           383:        term->ymax = FIG_YMAX(FIG_inches);
        !           384:        term->v_tic = FIG_VTIC(FIG_inches);
        !           385:        term->h_tic = FIG_HTIC(FIG_inches);
        !           386:        FIG_xoff = FIG_XOFF(FIG_inches);
        !           387:        FIG_yoff = FIG_YOFF(FIG_inches);
1.1       maekawa   388:     } else {
                    389:        if (FIG_font_s == 0)    /* KB */
                    390:            FIG_font_s = BFIG_FONT_S;
1.1.1.3 ! ohara     391:        term->xmax = BFIG_XMAX(FIG_inches);
        !           392:        term->ymax = BFIG_YMAX(FIG_inches);
        !           393:        term->v_tic = BFIG_VTIC(FIG_inches);
        !           394:        term->h_tic = BFIG_HTIC(FIG_inches);
        !           395:        FIG_xoff = BFIG_XOFF(FIG_inches);
        !           396:        FIG_yoff = BFIG_YOFF(FIG_inches);
1.1       maekawa   397:     }
                    398:     if (FIG_portrait) {                /* KB */
                    399:        tmax_t = term->xmax;
                    400:        term->xmax = term->ymax;
                    401:        term->ymax = tmax_t;
                    402:     }
                    403:     if (xsize_t > 0. && ysize_t > 0.) {
1.1.1.3 ! ohara     404:        term->xmax = (unsigned int) (xsize_t * FIG_TRUERES);
        !           405:        term->ymax = (unsigned int) (ysize_t * FIG_TRUERES);
1.1       maekawa   406:     }
1.1.1.3 ! ohara     407:     term->v_char = FIG_to_pixel_v(FIG_inches, FIG_font_s);
        !           408:     term->h_char = FIG_to_pixel_h(FIG_inches, FIG_font_s);
1.1       maekawa   409:     FIG_thickness = FIG_default_thickness;
                    410:     if (parse_error) {         /* JFS, KB */
                    411:        int_error(options_list, c_token);
                    412:     }
                    413: }
                    414:
                    415: TERM_PUBLIC void FIG_init()
                    416: {
                    417:     FIG_posx = FIG_posy = 0;
                    418:     FIG_polyvec_stat = FIG_poly_new;
                    419:     FIG_linetype(-1);
                    420:     FIG_justify_text(LEFT);
                    421:     FIG_text_angle(0);
                    422:
                    423:     FIG_line.tagged = FIG_DEFAULT;
                    424:     FIG_line.distrib = FIG_DEFAULT;
                    425:     FIG_line.type = T_POLYLINE;
                    426:     FIG_line.style = 0;
                    427:     FIG_line.thickness = FIG_thickness;
                    428:     FIG_line.fill_style = -1;
                    429:     FIG_line.depth = FIG_linedepth;
                    430:     FIG_line.pen_style = 0;
                    431:     FIG_line.for_arrow = NULL;
                    432:     FIG_line.back_arrow = NULL;
                    433:     FIG_line.cap_style = 0;
                    434:     FIG_line.join_style = 0;
                    435:     FIG_line.style_val = 0.0;
                    436:     FIG_line.radius = 0;
                    437:     FIG_line.pic = NULL;
                    438:     FIG_line.next = NULL;
                    439:
                    440:     fprintf(gpoutfile, "\
                    441: %s\n\
1.1.1.3 ! ohara     442: %s\n%s\n\
        !           443: %s\n%s\n\
        !           444: %.2f\n%s\n%d\n\
        !           445: %d %d\n",
1.1       maekawa   446:            FIG_MAGIC,
                    447:            FIG_ORIENT, FIG_JUST,
1.1.1.3 ! ohara     448:            FIG_UNIT, FIG_PAPER,
        !           449:            FIG_MAGNIFICATION, FIG_MULTIPAGE, FIG_TRANSCOLOR,
        !           450:            FIG_IRES, FIG_COORD_SYS);
1.1       maekawa   451: }
                    452:
                    453:
                    454: TERM_PUBLIC void FIG_graphics()
                    455: {
                    456:     FIG_posx = FIG_posy = 0;
                    457:     FIG_polyvec_stat = FIG_poly_new;
                    458:     /* there is no way to have separate pictures in a FIG file */
                    459: }
                    460:
                    461:
                    462: TERM_PUBLIC void FIG_text()
                    463: {
                    464:     /* there is no way to have separate pictures in a FIG file */
                    465:     FIG_poly_clean(FIG_polyvec_stat);
                    466:     FIG_posx = FIG_posy = 0;
                    467:     fflush(gpoutfile);
                    468: }
                    469:
                    470:
                    471: /* Line types for FIG work like this:
                    472:  *  for monochrome:
                    473:  *  -2 : solid (border)
                    474:  *  -1 : dotted 4 (axes)
                    475:  *   0 : solid (first curve)
                    476:  *   1 : dotted 3
                    477:  *   2 : dashed 3
                    478:  *   3 : dotted 6
                    479:  *   4 : dashed 6
                    480:  *   ... ...
                    481:  *  for color, cycle through colors. once colors are used up, repeat colors
                    482:  *   but start using dashed lines of different dash length. don't use white
                    483:  *   as a color.
                    484:  */
                    485:
                    486: TERM_PUBLIC void FIG_linetype(linetype)
                    487: int linetype;                  /* expect linetype >= -2 */
                    488: {
                    489:     int last_FIG_type = FIG_type;
                    490:     int last_FIG_spacing = FIG_spacing;
                    491:     int last_FIG_color = FIG_color;
                    492:     int last_FIG_depth = FIG_linedepth;
                    493:     int last_FIG_thickness = FIG_thickness;
                    494:
                    495:     FIG_linedepth = FIG_depth;
                    496:     FIG_thickness = FIG_current_linewidth * FIG_default_thickness;
                    497:     if (FIG_thickness < 1)
                    498:        FIG_thickness = 1;
                    499:     FIG_color = DEFAULT;
                    500:
                    501:     if (linetype < -2)
                    502:        linetype = -2;
                    503:
                    504:     switch (linetype) {
                    505:     case 0:
                    506:     case -2:{
                    507:            FIG_type = SOLID_LINE;
                    508:            FIG_spacing = 0.0;
                    509:            if (FIG_use_color)
                    510:                FIG_color = BLACK;
                    511:            break;
                    512:        }
                    513:     case -1:{
                    514:            FIG_type = DOTTED_LINE;
                    515:            FIG_spacing = 4.0;  /* gap */
                    516:            if (FIG_use_color)
                    517:                FIG_color = BLACK;
                    518:            break;
                    519:        }
                    520:     default:{
                    521: /* now linetype >= 1 *//* shouldn't be negative anyway */
                    522:            FIG_linedepth = FIG_depth + linetype / 1000;
                    523:            linetype %= 1000;
                    524:            /* Thickness of lines is either included in the linetype */
                    525:            /* (in Fig units) or the default is scaled with the */
                    526:            /* current 'linewidth'. */
                    527:            if ((FIG_thickness = linetype / 100) == 0)
                    528:                FIG_thickness = FIG_current_linewidth * FIG_default_thickness;
                    529:            if (FIG_thickness < 1)      /* Less than 1 would be invisible */
                    530:                FIG_thickness = 1;
                    531:            linetype %= 100;
                    532:            if (FIG_use_color) {
                    533:                FIG_type = (linetype >= WHITE);         /* dashed line */
                    534:                FIG_color = linetype % WHITE;
                    535:                FIG_spacing = (linetype / WHITE) * 3;
                    536:            } else {            /* monochrome */
                    537:                FIG_type = linetype % 2 + 1;    /* dotted, dashed, ... */
                    538:                FIG_spacing = (linetype + 1) / 2 * 3;
                    539:            }
                    540:            break;
                    541:        }
                    542:     }
                    543:     if (FIG_type != last_FIG_type || FIG_spacing != last_FIG_spacing ||
                    544:        FIG_color != last_FIG_color || FIG_linedepth != last_FIG_depth ||
                    545:        FIG_thickness != last_FIG_thickness)
                    546:        FIG_poly_clean(FIG_polyvec_stat);
                    547: }
                    548:
                    549: TERM_PUBLIC void FIG_move(x, y)
                    550: unsigned int x, y;
                    551: {
                    552:     int last_FIG_posx = FIG_posx;
                    553:     int last_FIG_posy = FIG_posy;
                    554:     FIG_posx = x;
                    555:     FIG_posy = y;
                    556:     if (FIG_posx != last_FIG_posx || FIG_posy != last_FIG_posy)
                    557:        FIG_poly_clean(FIG_polyvec_stat);
                    558: }
                    559:
                    560:
                    561: TERM_PUBLIC void FIG_vector(ux, uy)
                    562: unsigned int ux, uy;
                    563: {
                    564:     int x = ux, y = uy;
                    565:
                    566:     if (FIG_polyvec_stat != FIG_poly_part) {
                    567:        FIG_line.pen_color = FIG_color;
                    568:        FIG_line.fill_color = FIG_color;
                    569:        FIG_line.style = FIG_type;
                    570:        FIG_line.style_val = FIG_spacing;
                    571:        FIG_line.depth = FIG_linedepth;
                    572:        FIG_line.thickness = FIG_thickness;
                    573:        FIG_poly_vec_cnt = 0;
                    574:        /* allocate memory for the first point */
                    575:        FIG_points = (F_point *) gp_realloc(FIG_points, sizeof(F_point), "FIG_points");         /* JFS */
                    576:        FIG_points[FIG_poly_vec_cnt].x = FIG_xoff + FIG_posx;
                    577:        FIG_points[FIG_poly_vec_cnt].y = term->ymax
                    578:            + FIG_yoff - FIG_posy;
                    579:
                    580:        FIG_poly_vec_cnt = 1;
                    581:        FIG_polyvec_stat = FIG_poly_part;
                    582:     }
                    583:     /* allocate memory for the next point */
                    584:     FIG_points = (F_point *) gp_realloc(FIG_points, (FIG_poly_vec_cnt + 1) *
                    585:                                        sizeof(F_point), "FIG_points");         /* JFS */
                    586:     FIG_points[FIG_poly_vec_cnt].x = FIG_xoff + x;
                    587:     FIG_points[FIG_poly_vec_cnt].y = term->ymax + FIG_yoff - y;
                    588:
                    589:     FIG_poly_vec_cnt++;
                    590:     if (FIG_poly_vec_cnt > FIG_poly_vec_max)
                    591:        FIG_poly_clean(FIG_polyvec_stat);
                    592:
                    593:     FIG_posx = x;
                    594:     FIG_posy = y;
                    595: }
                    596:
                    597:
                    598: TERM_PUBLIC void FIG_arrow(sx, sy, ex, ey, head)
                    599: unsigned int sx, sy;           /* start coord */
                    600: unsigned int ex, ey;           /* end coord */
                    601: TBOOLEAN head;
                    602: {
                    603:     FIG_poly_clean(FIG_polyvec_stat);
                    604:     fprintf(gpoutfile, "%d %d %d %d %d %d %d %d %d %9.3f %d %d %d %d %d %d\n",
                    605:            O_POLYLINE, FIG_line.type, FIG_line.style, FIG_line.thickness,
                    606:            FIG_line.pen_color, FIG_line.fill_color, FIG_line.depth,
                    607:            FIG_line.pen_style, FIG_line.fill_style, FIG_line.style_val,
                    608:            FIG_line.join_style, FIG_line.cap_style, FIG_line.radius,
                    609:            head ? 1 : 0, 0, 2);
                    610:
                    611:     /* arrow line */
                    612:     if (head)
                    613:        fprintf(gpoutfile, "%d %d %.3f %.3f %.3f\n",
                    614:                0, 0, 1.0,
                    615:                (double) (term->h_tic / 2 + 1),
                    616:                (double) term->h_tic);
                    617:     fprintf(gpoutfile, "%d %d %d %d\n",
                    618:            FIG_xoff + sx, FIG_yoff + term->ymax - sy,
                    619:            FIG_yoff + ex, FIG_yoff + term->ymax - ey);
                    620:
                    621:     FIG_posx = ex;
                    622:     FIG_posy = ey;
                    623: }
                    624:
                    625:
                    626: TERM_PUBLIC void FIG_put_text(x, y, str)
                    627: unsigned int x, y;
                    628: char *str;
                    629: {
1.1.1.3 ! ohara     630:     int has_latex_command = 0;
        !           631:
1.1       maekawa   632:     if (strlen(str) == 0)
                    633:        return;
                    634:     FIG_poly_clean(FIG_polyvec_stat);
1.1.1.3 ! ohara     635:     if(FIG_angle != 0.0)
        !           636:        x += term->v_char / 2;  /* assuming horizontally center justified */
        !           637:     else
        !           638:        y -= term->v_char / 2;  /* assuming vertical center justified */
        !           639:     /*
        !           640:      * gnuplot used to create SPECIAL_TEXT for all text strings, but this
        !           641:      * is only really needed if str contains LaTeX commands. we assume that
        !           642:      * a string contains LaTeX commands if it contains a backslash.
        !           643:      */
        !           644:     if (strchr(str,'\\'))
        !           645:        has_latex_command = SPECIAL_TEXT;
1.1       maekawa   646:
                    647:     fprintf(gpoutfile, "%d %d %d %d %d %d %6.3f %6.3f %d %6.3f %6.3f %d %d %s\\001\n",
1.1.1.2   maekawa   648:            OBJ_TEXT, FIG_justify, FIG_color, 0, FIG_DEFAULT,
1.1       maekawa   649:            FIG_ROMAN_FONT, (float) FIG_font_s,
1.1.1.3 ! ohara     650:            FIG_angle, has_latex_command, (float) term->v_char,
1.1       maekawa   651:            (float) term->h_char * strlen(str),
                    652:            FIG_xoff + x, term->ymax + FIG_yoff - y, str);
                    653: }
                    654:
                    655: TERM_PUBLIC int FIG_justify_text(mode)
                    656: enum JUSTIFY mode;
                    657: {
                    658:     switch (mode) {
                    659:     case LEFT:
                    660:        FIG_justify = T_LEFT_JUSTIFIED;
                    661:        break;
                    662:     case CENTRE:
                    663:        FIG_justify = T_CENTER_JUSTIFIED;
                    664:        break;
                    665:     case RIGHT:
                    666:        FIG_justify = T_RIGHT_JUSTIFIED;
                    667:        break;
                    668:        /* shouldn't happen */
                    669:     default:
                    670:        FIG_justify = T_LEFT_JUSTIFIED;
                    671:        return (FALSE);
                    672:        break;
                    673:     }
                    674:     return (TRUE);
                    675: }
                    676:
                    677: TERM_PUBLIC int FIG_text_angle(ang)
                    678: int ang;
                    679: {
                    680:     if (ang)
1.1.1.3 ! ohara     681:        FIG_angle = M_PI_2;     /* vertical is pi/2 radians */
1.1       maekawa   682:     else
                    683:        FIG_angle = 0.0;        /* horizontal */
                    684:     return (TRUE);
                    685: }
                    686:
                    687: TERM_PUBLIC void FIG_lpoint(x, y, number)
                    688: unsigned int x, y;
                    689: int number;
                    690: {
                    691:     FIG_type = 0;              /* Solid lines for marker outline */
                    692:     if (number % 100 >= 49 && number % 100 < 99) {     /* circles, squares, triangles */
                    693:        int r, d, h, xpc, ypc;
                    694:        int line_color, fill_color, fill_style;
                    695:        int cnum, tnum, color, depth;
                    696:
                    697:        FIG_poly_clean(FIG_polyvec_stat);
                    698:        depth = FIG_linedepth - 1;      /* Above error bars */
                    699:        if (number > 1000)
                    700:            depth = FIG_depth + number / 1000 - 1;
                    701:        number %= 1000;
                    702:        if (depth < 0)
                    703:            depth = 0;
                    704:        if (number < 100)
                    705:            color = FIG_color;
                    706:        else if (FIG_use_color)
                    707:            color = number / 100 - 1;
                    708:        else if (number / 100 >= WHITE)
                    709:            color = WHITE;
                    710:        else
                    711:            color = DEFAULT;
                    712:        number %= 100;
                    713:        cnum = (number + 1) % 10;
                    714:        tnum = (number - 49) / 10;
                    715:        if (cnum < 5)
                    716:            line_color = (FIG_use_color ? BLACK : DEFAULT);
                    717:        else
                    718:            line_color = FIG_color;
                    719:        fill_color = color;
                    720:        if (cnum == 0 || cnum == 5)
                    721:            fill_style = -1;
                    722:        else
                    723:            fill_style = (cnum % 5) * 5;
                    724:
                    725:        xpc = FIG_xoff + x;
                    726:        ypc = term->ymax + FIG_yoff - y;
                    727:
                    728:        if (tnum == 0) {        /* circle */
                    729:            r = FIG_current_pointsize * term->v_char / 4 + 1;
                    730:            fprintf(gpoutfile,
                    731:                    "1 3 %d %d %d %d %d %d %d %6.3f 1 0.000 %d %d %d %d %d %d %d %d\n",
                    732:                    FIG_type, FIG_thickness, line_color,
                    733:                    fill_color, depth, 0, fill_style, FIG_spacing,
                    734:                    xpc, ypc, r, r, xpc, ypc, xpc, ypc - r);
                    735:        } else {
                    736:            fprintf(gpoutfile, "2 3 %d %d %d %d %d %d %d %6.3f 0 0 0 0 0 ",
                    737:                    FIG_type, FIG_thickness, line_color,
                    738:                    fill_color, depth, 0, fill_style, FIG_spacing);
                    739:
                    740:            if (tnum == 1) {    /* square */
                    741:                d = FIG_current_pointsize * term->v_char / 4 + 1;
                    742:                fprintf(gpoutfile, "5\n\t%d %d %d %d %d %d %d %d %d %d\n",
                    743:                        xpc - d, ypc - d, xpc - d, ypc + d, xpc + d, ypc + d, xpc + d, ypc - d,
                    744:                        xpc - d, ypc - d);
                    745:            } else if (tnum == 2) {     /* diamond */
                    746:                d = FIG_current_pointsize * term->v_char / 3 + 1;
                    747:                fprintf(gpoutfile, "5\n\t%d %d %d %d %d %d %d %d %d %d\n",
                    748:                        xpc - d, ypc, xpc, ypc + d, xpc + d, ypc, xpc, ypc - d, xpc - d, ypc);
                    749:            } else if (tnum == 3) {     /* triangle up */
                    750:                d = FIG_current_pointsize * term->v_char / 3 + 1;
                    751:                h = d * 4 / 7;  /* About d times one 3rd of sqrt(3) */
                    752:                fprintf(gpoutfile, "4\n\t%d %d %d %d %d %d %d %d\n",
                    753:                        xpc - d, ypc + h, xpc, ypc - 2 * h, xpc + d, ypc + h, xpc - d, ypc + h);
                    754:            } else if (tnum == 4) {     /* triangle down */
                    755:                d = FIG_current_pointsize * term->v_char / 3 + 1;
                    756:                h = d * 4 / 7;
                    757:                fprintf(gpoutfile, "4\n\t%d %d %d %d %d %d %d %d\n",
                    758:                        xpc - d, ypc - h, xpc, ypc + 2 * h, xpc + d, ypc - h, xpc - d, ypc - h);
                    759:            }
                    760:        }
                    761:     } else
                    762:        do_point(x, y, number);
                    763: }
                    764:
                    765: TERM_PUBLIC void FIG_pointsize(arg_pointsize)
                    766: double arg_pointsize;
                    767: {
                    768:     FIG_current_pointsize = arg_pointsize;
                    769:     /* Bug-fix by hkeller@gwdg.de and K.B.: set pointsize for do_point() */
                    770:     do_pointsize(arg_pointsize * FIG_font_s / (double) FIG_FONT_S);
                    771: }
                    772:
                    773: TERM_PUBLIC void FIG_linewidth(linewidth)
                    774: double linewidth;
                    775: {
                    776:     FIG_current_linewidth = linewidth;
                    777: }
                    778:
                    779: TERM_PUBLIC void FIG_reset()
                    780: {
                    781:     FIG_poly_clean(FIG_polyvec_stat);
                    782:     FIG_posx = FIG_posy = 0;
                    783:     fflush(gpoutfile);
                    784: }
                    785:
                    786: #endif /* TERM_BODY */
                    787:
                    788: #ifdef TERM_TABLE
                    789:
                    790: TERM_TABLE_START(fig_driver)
1.1.1.3 ! ohara     791:     "fig", "FIG 3.2 graphics language: X graphics editor",
        !           792:     FIG_XMAX(INCH), FIG_YMAX(INCH), FIG_VCHAR, FIG_HCHAR,
        !           793:     FIG_VTIC(INCH), FIG_HTIC(INCH), FIG_options, FIG_init, FIG_reset,
1.1       maekawa   794:     FIG_text, null_scale, FIG_graphics, FIG_move, FIG_vector,
                    795:     FIG_linetype, FIG_put_text, FIG_text_angle, FIG_justify_text,
                    796:     FIG_lpoint, FIG_arrow, set_font_null, FIG_pointsize,
                    797:     0 /*flags */ , 0 /*suspend */ , 0 /*resume */ , 0 /*fillbox */ ,
                    798:     FIG_linewidth
                    799: TERM_TABLE_END(fig_driver)
                    800:
                    801: #undef LAST_TERM
                    802: #define LAST_TERM fig_driver
                    803: #endif /* TERM_TABLE */
                    804: #endif /* TERM_PROTO_ONLY */
                    805:
                    806: #ifdef TERM_HELP
                    807: START_HELP(fig)
                    808: "1 fig",
                    809: "?commands set terminal fig",
                    810: "?set terminal fig",
                    811: "?set term fig",
                    812: "?terminal fig",
                    813: "?term fig",
                    814: "?fig",
                    815: " The `fig` terminal device generates output in the Fig graphics language.",
                    816: "",
                    817: " Syntax:",
                    818: "       set terminal fig {monochrome | color} {small | big}",
                    819: "                        {pointsmax <max_points>}",
                    820: "                        {landscape | portrait}",
                    821: "                        {metric | inches}",
                    822: "                        {fontsize <fsize>}",
                    823: "                        {size <xsize> <ysize>}",
                    824: "                        {thickness <units>}",
                    825: "                        {depth <layer>}",
                    826: "",
                    827: " `monochrome` and `color` determine whether the picture is black-and-white or",
                    828: " `color`.  `small` and `big` produce a 5x3 or 8x5 inch graph in the default",
                    829: " `landscape` mode and 3x5 or 5x8 inches in `portrait` mode.  <max_points>",
                    830: " sets the maximum number of points per polyline.  Default units for editing",
                    831: " with \"xfig\" may be `metric` or `inches`.  `fontsize` sets the size of the",
                    832: " text font to <fsize> points.  `size` sets (overrides) the size of the drawing",
                    833: " area to <xsize>*<ysize> in units of inches or centimeters depending on the",
                    834: " `inches` or `metric` setting in effect.  `depth` sets the default depth layer",
                    835: " for all lines and text.  The default depth is 10 to leave room for adding",
                    836: " material with \"xfig\" on top of the plot.",
                    837: "",
                    838: " `thickness` sets the default line thickness, which is 1 if not specified.",
                    839: " Overriding the thickness can be achieved by adding a multiple of 100 to the",
1.1.1.3 ! ohara     840: " `linetype` value for a `plot` command.  In a similar way the `depth`",
1.1       maekawa   841: " of plot elements (with respect to the default depth) can be controlled by",
                    842: " adding a multiple of 1000 to <linetype>.  The depth is then <layer> +",
                    843: " <linetype>/1000 and the thickness is (<linetype>%1000)/100 or, if that is",
                    844: " zero, the default line thickness.",
                    845: "",
                    846: " Additional point-plot symbols are also available with the `fig` driver. The",
                    847: " symbols can be used through `pointtype` values % 100 above 50, with different",
                    848: " fill intensities controlled by <pointtype> % 5 and outlines in black (for",
                    849: " <pointtype> % 10 < 5) or in the current color.  Available symbols are",
                    850: "         50 - 59:  circles",
                    851: "         60 - 69:  squares",
                    852: "         70 - 79:  diamonds",
                    853: "         80 - 89:  upwards triangles",
                    854: "         90 - 99:  downwards triangles",
                    855: " The size of these symbols is linked to the font size.  The depth of symbols",
                    856: " is by default one less than the depth for lines to achieve nice error bars.",
                    857: " If <pointtype> is above 1000, the depth is <layer> + <pointtype>/1000-1.  If",
                    858: " <pointtype>%1000 is above 100, the fill color is (<pointtype>%1000)/100-1.",
                    859: "",
                    860: " Available fill colors are (from 1 to 9): black, blue, green, cyan, red,",
                    861: " magenta, yellow, white and dark blue (in monochrome mode: black for 1 to 6",
                    862: " and white for 7 to 9).",
                    863: "",
                    864: " See `plot with` for details of <linetype> and <pointtype>.",
                    865: "",
                    866: " The `big` option is a substitute for the `bfig` terminal in earlier versions,",
                    867: " which is no longer supported.",
                    868: "",
                    869: " Examples:",
                    870: "       set terminal fig monochrome small pointsmax 1000  # defaults",
                    871: "",
                    872: "       plot 'file.dat' with points linetype 102 pointtype 759",
                    873: " would produce circles with a blue outline of width 1 and yellow fill color.",
                    874: "",
                    875: "       plot 'file.dat' using 1:2:3 with err linetype 1 pointtype 554",
                    876: " would produce errorbars with black lines and circles filled red.  These",
                    877: " circles are one layer above the lines (at depth 9 by default).",
                    878: "",
                    879: " To plot the error bars on top of the circles use",
                    880: "       plot 'file.dat' using 1:2:3 with err linetype 1 pointtype 2554"
                    881: END_HELP(fig)
                    882: #endif /* TERM_HELP */
                    883:
                    884:
                    885:
                    886:
                    887: #if 0
                    888:
                    889: /* I hope this is enough to stop compilers looking in here
                    890:  * (I think that anything inside #if 0 is still strictly
                    891:  *  required to be valid C, rather than just any old junk
                    892:  *  like this.)
                    893:  */
                    894:
                    895: /*
                    896:  * FIG : Facility for Interactive Generation of figures
                    897:  * Copyright (c) 1985 by Supoj Sutanthavibul
                    898:  * Parts Copyright (c) 1994 by Brian V. Smith
                    899:  * Parts Copyright (c) 1991 by Paul King
                    900:  *
                    901:  * The X Consortium, and any party obtaining a copy of these files from
                    902:  * the X Consortium, directly or indirectly, is granted, free of charge, a
                    903:  * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
                    904:  * nonexclusive right and license to deal in this software and
                    905:  * documentation files (the "Software"), including without limitation the
                    906:  * rights to use, copy, modify, merge, publish, distribute, sublicense,
                    907:  * and/or sell copies of the Software, and to permit persons who receive
                    908:  * copies from any such party to do so, with the only requirement being
                    909:  * that this copyright notice remain intact.  This license includes without
                    910:  * limitation a license to do the foregoing actions under any patents of
                    911:  * the party supplying this software to the X Consortium.
                    912:  */
                    913:
                    914: /*
                    915: The only difference from version 3.0 to version 3.1 is that the position
                    916: of the "magnet" has been shifted by 14 Fig units.
                    917: In the 2.1 and older versions of xfig the grid was in multiples of 5 Fig
                    918: units, but they were on intervals 4, 9, 14, 19, etc.
                    919: When version 3.0 was created, coordinates were simply multiplied by the
                    920: ratio of the resolutions (1200/80 = 15) so values like 4 became 60 instead
                    921: of 74 ((4+1)*15 - 1).
                    922:
                    923: This means that figures converted from 2.1 and older files are offset by
                    924: 14 Fig units but new objects entered with version 3.0 are correct.
                    925:
                    926: In version 3.1 the magnet grid is at intervals 0, 75, 150, etc instead of
                    927: -1, 74, 149, etc.
                    928: Figures from 2.1 and older are correctly converted now and a warning is popped
                    929: up when you read in a version 3.0 file that says you may have to offset the
                    930: figure when you load it, using the x and y offsets in the file panel.
                    931:
                    932: --------------------------------------------------------------------------------
                    933: Description of the Fig Format Follows
                    934: --------------------------------------------------------------------------------
                    935:
                    936: (1) The very first line is a comment line containing the name and version:
                    937:        #FIG 3.1
                    938:
                    939:     The character # at the first column of a line indicates that the line
                    940:     is a comment line which will be ignored.
                    941:
                    942: (2) The first non-comment line consists of two numbers and two strings:
                    943:
                    944:        int     fig_resolution          (Fig units/inch)
                    945:        string  orientation             ("Landscape" or "Portrait")
                    946:        string  justification           ("Center" or "Flush Left")
                    947:        string  units                   ("Metric" or "Inches")
                    948:        int     coordinate_system       (1: origin is the lower left corner (NOT USED)
                    949:                                         2: upper left)
                    950:
                    951:     Fig_resolution is the resolution of the figure in the file.
                    952:     Xfig will always write the file with a resolution of 1200ppi so it
                    953:     will scale the figure upon reading it in if its resolution is different
                    954:     from 1200ppi.  Pixels are assumed to be square.
                    955:
                    956:     Xfig will read the orientation string and change the canvas to match
                    957:     either the Landscape or Portrait mode of the figure file.
                    958:
                    959:     The units specification is self-explanatory.
                    960:
                    961:     The coordinate_system variable is ignored - the origin is ALWAYS the
                    962:     upper-left corner.
                    963:
                    964:     ** Coordinates are given in "fig_resolution" units.
                    965:     ** Line thicknesses are given in 1/80 of an inch ("display units").  The
                    966:        minimum line thickness is 0 (no line is drawn) and the maximum is 500.
                    967:     ** dash-lengths/dot-gaps are given in 1/80 of an inch.
                    968:
                    969:
                    970: (3) The rest of the file contains various objects.  An object can be one
                    971:     of six classes (or types).
                    972:
                    973:        0)      Color pseudo-object.
                    974:        1)      Arc.
                    975:        2)      Ellipse which is a generalization of circle.
                    976:        3)      Polyline which includes polygon and box.
                    977:        4)      Spline which includes closed/open control/interpolated spline.
                    978:        5)      Text.
                    979:        6)      Compound object which is composed of one or more objects.
                    980:
                    981:     In the following elaboration on object formats, every value of Fig
                    982:     output are separated by blank characters or new line ('\n').  The
                    983:     value of the unused parameters will be -1.
                    984:
                    985:     Some fields are described as "enumeration type" or "bit vector"; the
                    986:     values which these fields can take are defined in the header file object.h.
                    987:     The pen_style field is unused.
                    988:     These values may be defined in some future version of Fig.
                    989:
                    990:     The two color fields (pen and fill; pen only, for texts) are
                    991:     defined as follows:
                    992:
                    993:            -1 = Default
                    994:             0 = Black
                    995:             1 = Blue
                    996:             2 = Green
                    997:             3 = Cyan
                    998:             4 = Red
                    999:             5 = Magenta
                   1000:             6 = Yellow
                   1001:             7 = White
                   1002:          8-11 = four shades of blue (dark to lighter)
                   1003:         12-14 = three shades of green (dark to lighter)
                   1004:         15-17 = three shades of cyan (dark to lighter)
                   1005:         18-20 = three shades of red (dark to lighter)
                   1006:         21-23 = three shades of magenta (dark to lighter)
                   1007:         24-26 = three shades of brown (dark to lighter)
                   1008:         27-30 = four shades of pink (dark to lighter)
                   1009:            31 = Gold
                   1010:
                   1011:         values from 32 to 543 (512 total) are user colors and
                   1012:         are defined in color pseudo-objects (type 0)
                   1013:
                   1014:     For WHITE color, the area fill field is defined as follows:
                   1015:
                   1016:        -1 = not filled
                   1017:         0 = black
                   1018:        ...  values from 1 to 19 are shades of grey, from darker to lighter
                   1019:        20 = white
                   1020:        21-40 not used
                   1021:        41-56 see patterns for colors, below
                   1022:
                   1023:     For BLACK or DEFAULT color, the area fill field is defined as follows:
                   1024:
                   1025:        -1 = not filled
                   1026:         0 = white
                   1027:        ...  values from 1 to 19 are shades of grey, from lighter to darker
                   1028:        20 = black
                   1029:        21-40 not used
                   1030:        41-56 see patterns for colors, below
                   1031:
                   1032:     For all other colors, the area fill field is defined as follows:
                   1033:
                   1034:        -1 = not filled
                   1035:         0 = black
                   1036:        ...  values from 1 to 19 are "shades" of the color, from darker to lighter.
                   1037:                A shade is defined as the color mixed with black
                   1038:        20 = full saturation of the color
                   1039:        ...  values from 21 to 39 are "tints" of the color from the color to white.
                   1040:                A tint is defined as the color mixed with white
                   1041:        40 = white
                   1042:        41 = 30 degree left diagonal pattern
                   1043:        42 = 30 degree right diagonal pattern
                   1044:        43 = 30 degree crosshatch
                   1045:        44 = 45 degree left diagonal pattern
                   1046:        45 = 45 degree right diagonal pattern
                   1047:        46 = 45 degree crosshatch
                   1048:        47 = bricks
                   1049:        48 = circles
                   1050:        49 = horizontal lines
                   1051:        50 = vertical lines
                   1052:        51 = crosshatch
                   1053:        52 = fish scales
                   1054:        53 = small fish scales
                   1055:        54 = octagons
                   1056:        55 = horizontal "tire treads"
                   1057:        56 = vertical "tire treads"
                   1058:
                   1059:     The depth field is defined as follows:
                   1060:
                   1061:         0 ... 999 where larger value means object is deeper than (under)
                   1062:                   objects with smaller depth
                   1063:
                   1064:     The line_style field is defined as follows:
                   1065:
                   1066:        -1 = Default
                   1067:         0 = Solid
                   1068:         1 = Dashed
                   1069:         2 = Dotted
                   1070:
                   1071:     The style_val field is defined as the length, in 1/80 inches, of the on/off
                   1072:     dashes for dashed lines, and the distance between the dots, in 1/80 inches,
                   1073:     for dotted lines.
                   1074:
                   1075:     The join_style field is defined FOR LINES only as follows:
                   1076:
                   1077:         0 = Miter (the default in xfig 2.1 and earlier)
                   1078:         1 = Bevel
                   1079:         2 = Round
                   1080:
                   1081:     The cap_style field is defined FOR LINES, OPEN SPLINES and ARCS only as follows:
                   1082:
                   1083:         0 = Butt (the default in xfig 2.1 and earlier)
                   1084:         1 = Round
                   1085:         2 = Projecting
                   1086:
                   1087:     The arrow_type field is defined for LINES, ARCS and OPEN SPLINES
                   1088:     only as follows:
                   1089:
                   1090:         0 = Stick-type (the default in xfig 2.1 and earlier)
                   1091:         1 = Closed triangle:
                   1092:                |\
                   1093:                |  \
                   1094:                |    \
                   1095:                |    /
                   1096:                |  /
                   1097:                |/
                   1098:         2 = Closed with "indented" butt:
                   1099:                |\
                   1100:                \  \
                   1101:                 \   \
                   1102:                  \    \
                   1103:                  /    /
                   1104:                 /   /
                   1105:                /  /
                   1106:                |/
                   1107:         3 = Closed with "pointed" butt:
                   1108:                   |\
                   1109:                  /   \
                   1110:                 /      \
                   1111:                /         \
                   1112:                \         /
                   1113:                 \      /
                   1114:                  \   /
                   1115:                   |/
                   1116:
                   1117:     The arrow_style field is defined for LINES, ARCS and OPEN SPLINES
                   1118:     only as follows:
                   1119:
                   1120:         0 = Hollow (actually filled with white)
                   1121:         1 = Filled with pen_color
                   1122:
                   1123: (3.0) OBJECT DEFINITION:
                   1124:
                   1125:     (3.1) Color Pseudo-objects (user-defined colors)
                   1126:          This is used to define arbitrary colors beyond the 32 standard colors.
                   1127:          The color objects must be defined before any other Fig objects.
                   1128:
                   1129:     First line:
                   1130:        type    name                    (brief description)
                   1131:        ----    ----                    -------------------
                   1132:        int     object_code             (always 0)
                   1133:        int     color_number            (color number, from 32-543 (512 total))
                   1134:      hex string        rgb values              (hexadecimal string describing red,
                   1135:                                         green and blue values (e.g. #330099) )
                   1136:
                   1137:     (3.2) ARC
                   1138:
                   1139:     First line:
                   1140:        type    name                    (brief description)
                   1141:        ----    ----                    -------------------
                   1142:        int     object_code             (always 5)
                   1143:        int     sub_type                (0: pie-wedge (closed)
                   1144:                                         1: open ended arc)
                   1145:        int     line_style              (enumeration type)
                   1146:        int     line_thickness          (1/80 inch)
                   1147:        int     pen_color               (enumeration type, pen color)
                   1148:        int     fill_color              (enumeration type, fill color)
                   1149:        int     depth                   (enumeration type)
                   1150:        int     pen_style               (pen style, not used)
                   1151:        int     area_fill               (enumeration type, -1 = no fill)
                   1152:        float   style_val               (1/80 inch)
                   1153:        int     cap_style               (enumeration type)
                   1154:        int     direction               (0: clockwise, 1: counterclockwise)
                   1155:        int     forward_arrow           (0: no forward arrow, 1: on)
                   1156:        int     backward_arrow          (0: no forward arrow, 1: on)
                   1157:        float   center_x, center_y      (center of the arc)
                   1158:        int     x1, y1                  (Fig units, the 1st point the user entered)
                   1159:        int     x2, y2                  (Fig units, the 2nd point)
                   1160:        int     x3, y3                  (Fig units, the last point)
                   1161:
                   1162:     Forward arrow line (Optional; absent if forward_arrow is 0):
                   1163:        type    name                    (brief description)
                   1164:        ----    ----                    -------------------
                   1165:        int     arrow_type              (enumeration type)
                   1166:        int     arrow_style             (enumeration type)
                   1167:        float   arrow_thickness         (1/80 inch)
                   1168:        float   arrow_width             (Fig units)
                   1169:        float   arrow_height            (Fig units)
                   1170:
                   1171:     Backward arrow line (Optional; absent if backward_arrow is 0):
                   1172:        type    name                    (brief description)
                   1173:        ----    ----                    -------------------
                   1174:        int     arrow_type              (enumeration type)
                   1175:        int     arrow_style             (enumeration type)
                   1176:        float   arrow_thickness         (1/80 inch)
                   1177:        float   arrow_width             (Fig units)
                   1178:        float   arrow_height            (Fig units)
                   1179:
                   1180:     (3.3) COMPOUND
                   1181:
                   1182:     A line with object code 6 signifies the start of a compound.
                   1183:     There are four more numbers on this line which indicate the
                   1184:     upper right corner and the lower left corner of the bounding
                   1185:     box of this compound.  A line with object code -6 signifies
                   1186:     the end of the compound.  Compound may be nested.
                   1187:
                   1188:     First line:
                   1189:        type    name                    (brief description)
                   1190:        ----    ----                    -------------------
                   1191:        int     object_code             (always 6)
                   1192:        int     upperright_corner_x     (Fig units)
                   1193:        int     upperright_corner_y     (Fig units)
                   1194:        int     lowerleft_corner_x      (Fig units)
                   1195:        int     lowerleft_corner_y      (Fig units)
                   1196:
                   1197:     Subsequent lines:
                   1198:        objects
                   1199:        .
                   1200:        .
                   1201:
                   1202:     Last line:
                   1203:        -6
                   1204:
                   1205:     (3.4) ELLIPSE
                   1206:
                   1207:     First line:
                   1208:        type    name                    (brief description)
                   1209:        ----    ----                    -------------------
                   1210:        int     object_code             (always 1)
                   1211:        int     sub_type                (1: ellipse defined by radiuses
                   1212:                                         2: ellipse defined by diameters
                   1213:                                         3: circle defined by radius
                   1214:                                         4: circle defined by diameter)
                   1215:        int     line_style              (enumeration type)
                   1216:        int     thickness               (1/80 inch)
                   1217:        int     pen_color               (enumeration type, pen color)
                   1218:        int     fill_color              (enumeration type, fill color)
                   1219:        int     depth                   (enumeration type)
                   1220:        int     pen_style               (pen style, not used)
                   1221:        int     area_fill               (enumeration type, -1 = no fill)
                   1222:        float   style_val               (1/80 inch)
                   1223:        int     direction               (always 1)
                   1224:        float   angle                   (radians, the angle of the x-axis)
                   1225:        int     center_x, center_y      (Fig units)
                   1226:        int     radius_x, radius_y      (Fig units)
                   1227:        int     start_x, start_y        (Fig units; the 1st point entered)
                   1228:        int     end_x, end_y            (Fig units; the last point entered)
                   1229:
                   1230:     (3.5) POLYLINE
                   1231:
                   1232:     First line:
                   1233:        type    name                    (brief description)
                   1234:        ----    ----                    -------------------
                   1235:        int     object_code             (always 2)
                   1236:        int     sub_type                (1: polyline
                   1237:                                         2: box
                   1238:                                         3: polygon
                   1239:                                         4: arc-box)
                   1240:                                         5: imported-picture bounding-box)
                   1241:        int     line_style              (enumeration type)
                   1242:        int     thickness               (1/80 inch)
                   1243:        int     pen_color               (enumeration type, pen color)
                   1244:        int     fill_color              (enumeration type, fill color)
                   1245:        int     depth                   (enumeration type)
                   1246:        int     pen_style               (pen style, not used)
                   1247:        int     area_fill               (enumeration type, -1 = no fill)
                   1248:        float   style_val               (1/80 inch)
                   1249:        int     join_style              (enumeration type)
                   1250:        int     cap_style               (enumeration type, only used for POLYLINE)
                   1251:        int     radius                  (1/80 inch, radius of arc-boxes)
                   1252:        int     forward_arrow           (0: off, 1: on)
                   1253:        int     backward_arrow          (0: off, 1: on)
                   1254:        int     npoints                 (number of points in line)
                   1255:
                   1256:     Forward arrow line: same as ARC object
                   1257:
                   1258:     Backward arrow line: same as ARC object
                   1259:
                   1260:     Points line:
                   1261:        type    name                    (brief description)
                   1262:        ----    ----                    -------------------
                   1263:        int     x1, y1                  (Fig units)
                   1264:        int     x2, y2                  (Fig units)
                   1265:          .
                   1266:          .
                   1267:        int     xnpoints ynpoints       (this will be the same as the 1st
                   1268:                                        point for polygon and box)
                   1269:
                   1270:     PIC line:
                   1271:        type    name                    (brief description)
                   1272:        ----    ----                    -------------------
                   1273:        boolean flipped                 orientation = normal (0) or flipped (1)
                   1274:        char    file[]                  name of picture file to import
                   1275:
                   1276:     (3.6) SPLINE
                   1277:
                   1278:     First line:
                   1279:        type    name                    (brief description)
                   1280:        ----    ----                    -------------------
                   1281:        int     object_code             (always 3)
                   1282:        int     sub_type                (0: open spline
                   1283:                                         1: closed spline
                   1284:                                         2: open interpolated spline
                   1285:                                         3: closed interpolated spline)
                   1286:        int     line_style              (See the end of this section)
                   1287:        int     thickness               (1/80 inch)
                   1288:        int     pen_color               (enumeration type, pen color)
                   1289:        int     fill_color              (enumeration type, fill color)
                   1290:        int     depth                   (enumeration type)
                   1291:        int     pen_style               (pen style, not used)
                   1292:        int     area_fill               (enumeration type, -1 = no fill)
                   1293:        float   style_val               (1/80 inch)
                   1294:        int     cap_style               (enumeration type, only used for open splines)
                   1295:        int     forward_arrow           (0: off, 1: on)
                   1296:        int     backward_arrow          (0: off, 1: on)
                   1297:        int     npoints                 (number of control points in spline)
                   1298:
                   1299:     Forward arrow line: same as ARC object
                   1300:
                   1301:     Backward arrow line: same as ARC object
                   1302:
                   1303:     Points line: same as POLYLINE object
                   1304:
                   1305:     Control points line (absent if sub_type is 0 or 1):
                   1306:        Control points of interpolated spline.  There are two control
                   1307:        points for each knots.  A section i, of the spline is drawn
                   1308:        using Bezier cubic with the following four points:
                   1309:                (x ,y ), (rx ,ry ), (lx   , ly   ), (x   , y   ).
                   1310:                  i  i      i   i      i+1    i+1     i+1   i+1
                   1311:        For closed interpolated spline the last pair of control points,
                   1312:        (lxnpoints,lynpoints) and (rxnpoints,rynpoints) (which can be ignored),
                   1313:        are the same as (lx1,ly1) and (rx1,ry1) respectively.
                   1314:
                   1315:        type    name                    (brief description)
                   1316:        ----    ----                    -------------------
                   1317:        float   lx1, ly1                (Fig units)
                   1318:        float   rx1, ry1                (Fig units)
                   1319:        float   lx2, ly2                (Fig units)
                   1320:        float   rx2, ry2                (Fig units)
                   1321:          .
                   1322:          .
                   1323:        float   lxnpoints, lynpoints    (Fig units)
                   1324:        float   rxnpoints, rynpoints    (Fig units)
                   1325:
                   1326:     (3.7) TEXT
                   1327:        type    name                    (brief description)
                   1328:        ----    ----                    -------------------
                   1329:        int     object                  (always 4)
                   1330:        int     sub_type                (0: Left justified
                   1331:                                         1: Center justified
                   1332:                                         2: Right justified)
                   1333:        int     color                   (enumeration type)
                   1334:        int     depth                   (enumeration type)
                   1335:        int     pen_style               (enumeration , not used)
                   1336:        int     font                    (enumeration type)
                   1337:        float   font_size               (font size in points)
                   1338:        float   angle                   (radians, the angle of the text)
                   1339:        int     font_flags              (bit vector)
                   1340:        float   height                  (Fig units)
                   1341:        float   length                  (Fig units)
                   1342:        int     x, y                    (Fig units, coordinate of the origin
                   1343:                                         of the string.  If sub_type = 0, it is
                   1344:                                         the lower left corner of the string.
                   1345:                                         If sub_type = 1, it is the lower
                   1346:                                         center.  Otherwise it is the lower
                   1347:                                         right corner of the string.)
                   1348:        char    string[]                (ASCII characters; starts after a blank
                   1349:                                         character following the last number and
                   1350:                                         ends before the sequence '\001'.  This
                   1351:                                         sequence is not part of the string.
                   1352:                                         Characters above octal 177 are
                   1353:                                         represented by \xxx where xxx is the
                   1354:                                         octal value.  This permits Fig files to
                   1355:                                         be edited with 7-bit editors and sent
                   1356:                                         by e-mail without data loss.
                   1357:                                         Note that the string may contain '\n'.)
                   1358:
                   1359:     The font_flags field is defined as follows:
                   1360:
                   1361:         Bit    Description
                   1362:
                   1363:          0     Rigid text (text doesn't scale when scaling compound objects)
                   1364:          1     Special text (for LaTeX)
                   1365:          2     PostScript font (otherwise LaTeX font is used)
                   1366:          3     Hidden text
                   1367:
                   1368:     The font field is defined as follows:
                   1369:
                   1370:        For font_flags bit 2 = 0 (LaTeX fonts):
                   1371:
                   1372:         0      Default font
                   1373:         1      Roman
                   1374:         2      Bold
                   1375:         3      Italic
                   1376:         4      Sans Serif
                   1377:         5      Typewriter
                   1378:
                   1379:        For font_flags bit 3 = 1 (PostScript fonts):
                   1380:
                   1381:        -1      Default font
                   1382:         0      Times Roman
                   1383:         1      Times Italic
                   1384:         2      Times Bold
                   1385:         3      Times Bold Italic
                   1386:         4      AvantGarde Book
                   1387:         5      AvantGarde Book Oblique
                   1388:         6      AvantGarde Demi
                   1389:         7      AvantGarde Demi Oblique
                   1390:         8      Bookman Light
                   1391:         9      Bookman Light Italic
                   1392:        10      Bookman Demi
                   1393:        11      Bookman Demi Italic
                   1394:        12      Courier
                   1395:        13      Courier Oblique
                   1396:        14      Courier Bold
                   1397:        15      Courier Bold Oblique
                   1398:        16      Helvetica
                   1399:        17      Helvetica Oblique
                   1400:        18      Helvetica Bold
                   1401:        19      Helvetica Bold Oblique
                   1402:        20      Helvetica Narrow
                   1403:        21      Helvetica Narrow Oblique
                   1404:        22      Helvetica Narrow Bold
                   1405:        23      Helvetica Narrow Bold Oblique
                   1406:        24      New Century Schoolbook Roman
                   1407:        25      New Century Schoolbook Italic
                   1408:        26      New Century Schoolbook Bold
                   1409:        27      New Century Schoolbook Bold Italic
                   1410:        28      Palatino Roman
                   1411:        29      Palatino Italic
                   1412:        30      Palatino Bold
                   1413:        31      Palatino Bold Italic
                   1414:        32      Symbol
                   1415:        33      Zapf Chancery Medium Italic
                   1416:        34      Zapf Dingbats
                   1417: */
                   1418:
                   1419: #endif

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