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

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

1.1       maekawa     1: /*
1.1.1.3 ! ohara       2:  * $Id: ai.trm,v 1.9.2.1 1999/11/20 17:59:44 lhecking Exp $
1.1       maekawa     3:  *
                      4:  */
                      5:
                      6: /* GNUPLOT - ai.trm */
                      7:
                      8: /*[
                      9:  * Copyright 1991, 1992, 1993, 1998
                     10:  *
                     11:  * Permission to use, copy, and distribute this software and its
                     12:  * documentation for any purpose with or without fee is hereby granted,
                     13:  * provided that the above copyright notice appear in all copies and
                     14:  * that both that copyright notice and this permission notice appear
                     15:  * in supporting documentation.
                     16:  *
                     17:  * Permission to modify the software is granted, but not the right to
                     18:  * distribute the complete modified source code.  Modifications are to
                     19:  * be distributed as patches to the released version.  Permission to
                     20:  * distribute binaries produced by compiling modified sources is granted,
                     21:  * provided you
                     22:  *   1. distribute the corresponding source modifications from the
                     23:  *    released version in the form of a patch file along with the binaries,
                     24:  *   2. add special version identification to distinguish your version
                     25:  *    in addition to the base release version number,
                     26:  *   3. provide your name and address as the primary contact for the
                     27:  *    support of your modified version, and
                     28:  *   4. retain our contact information in regard to use of the base
                     29:  *    software.
                     30:  * Permission to distribute the released version of the source code along
                     31:  * with corresponding source modifications in the form of a patch file is
                     32:  * granted with same provisions 2 through 4 for binary distributions.
                     33:  *
                     34:  * This software is provided "as is" without express or implied warranty
                     35:  * to the extent permitted by applicable law.
                     36: ]*/
                     37:
                     38: /*
                     39:  * This file is included by ../term.c.
                     40:  *
                     41:  * This terminal driver supports:
                     42:  *     aifm
                     43:  *
                     44:  * AUTHORS
                     45:  *  Ray Ghanbari
                     46:  *
                     47:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
                     48:  *
                     49:  * The 'aifm' driver produces files editable by Adobe Illustrator 3.0
                     50:  * To change font to Courier and font size to 20pts use
                     51:  * 'set term aifm "Courier" 20'.
                     52:  * To switch to color output use
                     53:  * 'set term aifm color'.
                     54:  */
                     55:
                     56:  /* AIFM driver by Ray Ghanbari, ray@mtl.mit.edu,
                     57:   *   based on PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
                     58:
                     59: /* Changed to 3.6 terminal format, David C. Schooley, 9/29/95 */
                     60: /* Improved multiple plot support, David C. Schooley, 6/5/95 */
                     61: /* Compatiblity with Illustrator 7.0, David C. Schooley, 6/5/95 */
                     62: /* Font and size support for labels, David C. Schooley, 6/5/95 */
                     63:
                     64: #include "driver.h"
                     65:
                     66: #ifdef TERM_REGISTER
                     67: register_term(aifm)
                     68: #endif
                     69:
                     70: #ifdef TERM_PROTO
                     71: TERM_PUBLIC void AI_init __PROTO((void));
                     72: TERM_PUBLIC void AI_graphics __PROTO((void));
                     73: TERM_PUBLIC void AI_text __PROTO((void));
                     74: TERM_PUBLIC void AI_linetype __PROTO((int linetype));
                     75: TERM_PUBLIC void AI_move __PROTO((unsigned int x, unsigned int y));
                     76: TERM_PUBLIC void AI_vector __PROTO((unsigned int x, unsigned int y));
                     77: TERM_PUBLIC void AI_put_text __PROTO((unsigned int x, unsigned int y, char *str));
                     78: TERM_PUBLIC int AI_text_angle __PROTO((int ang));
                     79: TERM_PUBLIC void AI_reset __PROTO((void));
                     80: TERM_PUBLIC void AI_options __PROTO((void));
                     81: TERM_PUBLIC int AI_justify_text __PROTO((enum JUSTIFY mode));
                     82: TERM_PUBLIC void AI_suspend __PROTO(());
                     83: TERM_PUBLIC void AI_resume __PROTO(());
                     84: TERM_PUBLIC int AI_set_font __PROTO((char *font));
                     85:
                     86: #define AI_XOFF        50              /* page offset in pts */
                     87: #define AI_YOFF        50
                     88:
                     89: #define AI_XMAX 5000
                     90: #define AI_YMAX 3500
                     91:
                     92: #define AI_XLAST (AI_XMAX - 1)
                     93: #define AI_YLAST (AI_YMAX - 1)
                     94:
                     95: #define AI_VTIC (AI_YMAX/80)
                     96: #define AI_HTIC (AI_YMAX/80)
                     97:
                     98: #define AI_SC (10.0)           /* scale is 1pt = 10 units */
                     99: #define AI_LW (0.5*AI_SC)      /* linewidth = 0.5 pts */
                    100:
                    101: #define AI_VCHAR (14*AI_SC)    /* default is 14 point characters */
                    102: #define AI_HCHAR (14*AI_SC*6/10)
                    103:
                    104: #endif
                    105:
                    106:
                    107:
                    108: #ifndef TERM_PROTO_ONLY
                    109: #ifdef TERM_BODY
                    110:
                    111: char ai_font[MAX_ID_LEN + 1] = "Times-Roman";  /* name of font */
                    112: int ai_fontsize = 14;          /* size of font in pts */
                    113: char ai_oldfont[MAX_ID_LEN + 1] = "Times-Roman";       /* name of font */
                    114: int ai_oldfontsize = 14;       /* size of font in pts */
                    115: TBOOLEAN ai_color = FALSE;
                    116: TBOOLEAN ai_stroke = FALSE;
                    117: int ai_page = 0;               /* page count */
                    118: int ai_path_count = 0;         /* count of lines in path */
                    119: int ai_ang = 0;                        /* text angle */
                    120: int ai_subgroup_level = 0;     /* depth of sub-groups */
                    121: int ai_multiplot_group = 0;    /* group for multiplot */
                    122: enum JUSTIFY ai_justify = LEFT;        /* text is flush left */
                    123:
                    124:
                    125: TERM_PUBLIC void AI_options()
                    126: {
                    127:     if (!END_OF_COMMAND) {
                    128:        if (almost_equals(c_token, "d$efault")) {
                    129:            ai_color = FALSE;
                    130:            strcpy(ai_font, "Times-Roman");
                    131:            ai_fontsize = 14;
                    132:            strcpy(ai_oldfont, "Times-Roman");
                    133:            ai_oldfontsize = 14;
                    134:            c_token++;
                    135:        }
                    136:     }
                    137:     if (!END_OF_COMMAND) {
                    138:        if (almost_equals(c_token, "m$onochrome")) {
                    139:            ai_color = FALSE;
                    140:            c_token++;
                    141:        } else if (almost_equals(c_token, "c$olor")
                    142:                   || almost_equals(c_token, "c$olour")) {
                    143:            ai_color = TRUE;
                    144:            c_token++;
                    145:        }
                    146:     }
                    147:     if (!END_OF_COMMAND && isstring(c_token)) {
                    148:        quote_str(ai_font, c_token, MAX_ID_LEN);
                    149:        strcpy(ai_oldfont, ai_font);
                    150:        c_token++;
                    151:     }
                    152:     if (!END_OF_COMMAND) {
                    153:        /* We have font size specified */
                    154:        struct value a;
                    155:        ai_fontsize = (int) real(const_express(&a));
                    156:        ai_oldfontsize = ai_fontsize;
                    157:        c_token++;
                    158:        term->v_char = (unsigned int) (ai_fontsize * AI_SC);
                    159:        term->h_char = (unsigned int) (ai_fontsize * AI_SC * 6 / 10);
                    160:     }
                    161:     sprintf(term_options, "%s \"%s\" %d",
                    162:            ai_color ? "color" : "monochrome", ai_font, ai_fontsize);
                    163: }
                    164:
                    165:
                    166: TERM_PUBLIC void AI_init()
                    167: {
                    168:     ai_page = 0;
                    169:
                    170:     fprintf(gpoutfile, "%%!PS-Adobe-2.0 EPSF-1.2\n\
                    171: %%%%Creator: Adobe Illustrator(TM) 3.2\n\
                    172: %%%%TrueCreator: gnuplot %s patchlevel %s ai terminal\n\
                    173: %%%%BoundingBox: %d %d %d %d\n\
                    174: %%%%Template:\n\
                    175: %%%%EndComments\n\
                    176: %%%%EndProlog\n",
1.1.1.3 ! ohara     177:            gnuplot_version, gnuplot_patchlevel,
1.1       maekawa   178:            AI_XOFF, AI_YOFF,
                    179:            (int) ((AI_XMAX) / AI_SC + 0.5 + AI_XOFF),
                    180:            (int) ((AI_YMAX) / AI_SC + 0.5 + AI_YOFF));
                    181: }
                    182:
                    183:
                    184: TERM_PUBLIC void AI_graphics()
                    185: {
                    186:     ai_page++;
                    187: /*     fprintf(gpoutfile,"%%%%Page: %d %d\n",ai_page,ai_page);*/
                    188:     fputs("\
                    189: 0 G\n\
                    190: 1 j\n\
                    191: 1 J\n\
                    192: u\n", gpoutfile);
                    193:     ai_path_count = 0;
                    194:     ai_stroke = FALSE;
                    195: }
                    196:
                    197:
                    198: TERM_PUBLIC void AI_text()
                    199: {
                    200:     if (ai_stroke) {
                    201:        fputs("S\n", gpoutfile);
                    202:        ai_stroke = FALSE;
                    203:     }
                    204:     while (ai_subgroup_level) {
                    205:        fputs("U\n", gpoutfile);
                    206:        ai_subgroup_level--;
                    207:     }
                    208:     fputs("U\n", gpoutfile);
                    209:     ai_path_count = 0;
                    210:     ai_multiplot_group = 0;
                    211: }
                    212:
                    213:
                    214: TERM_PUBLIC void AI_reset()
                    215: {
                    216:     fputs("%%%%Trailer\n", gpoutfile);
                    217: /*     fprintf(gpoutfile,"%%%%Pages: %d\n",ai_page);*/
                    218: }
                    219:
                    220:
                    221: TERM_PUBLIC void AI_linetype(linetype)
                    222: int linetype;
                    223: {
                    224:     if (ai_stroke) {
                    225:        fputs("S\n", gpoutfile);
                    226:        ai_stroke = FALSE;
                    227:     }
                    228:     if (ai_subgroup_level) {
                    229:        fputs("U\n", gpoutfile);
                    230:        ai_subgroup_level--;
                    231:     }
                    232:     if (linetype == -2 && multiplot) {
                    233:        /* for each new plot, line_type gets called twice with a value of -2.
                    234:           It gets called once for the border and again for the tics.
                    235:           This code will need to be changed if gnuplot's behavior changes.
                    236:         */
                    237:        switch (ai_multiplot_group) {
                    238:        case 0:
                    239:            fputs("u\n", gpoutfile);
                    240:            ai_subgroup_level++;
                    241:            ai_multiplot_group = 1;
                    242:            break;
                    243:        case 1:
                    244:            ai_multiplot_group = 2;
                    245:            break;
                    246:        case 2:
                    247:            ai_multiplot_group = 1;
                    248:            fputs("U\nu\n", gpoutfile);
                    249:            break;
                    250:        }
                    251:     }
                    252:     if (linetype == -2 && !multiplot) {
                    253:        if (ai_multiplot_group) {
                    254:            fputs("U\n", gpoutfile);
                    255:            ai_subgroup_level--;
                    256:            ai_multiplot_group = 0;
                    257:        }
                    258:     }
                    259:     fputs("u\n", gpoutfile);
                    260:     ai_subgroup_level++;
                    261:
                    262:     switch (linetype) {
                    263:     case -2:
                    264:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC * 2.0);
                    265:        if (ai_color) {
                    266:            fputs("0 0 0 1 K\n", gpoutfile);
                    267:        } else {
                    268:            fputs("[] 0 d\n", gpoutfile);
                    269:        }
                    270:        break;
                    271:
                    272:     case -1:
                    273:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC / 2.0);
                    274:        if (ai_color) {
                    275:            fputs("0 0 0 1 K\n", gpoutfile);
                    276:        } else {
                    277:            fputs("[1 2] 0 d\n", gpoutfile);
                    278:        }
                    279:        break;
                    280:
                    281:     case 0:
                    282:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    283:        if (ai_color) {
                    284:            fputs("1 0 1 0 K\n", gpoutfile);
                    285:        } else {
                    286:            fputs("[] 0 d\n", gpoutfile);
                    287:        }
                    288:        break;
                    289:
                    290:     case 1:
                    291:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    292:        if (ai_color) {
                    293:            fputs("1 1 0 0 K\n", gpoutfile);
                    294:        } else {
                    295:            fputs("[4 2] 0 d\n", gpoutfile);
                    296:        }
                    297:        break;
                    298:
                    299:     case 2:
                    300:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    301:        if (ai_color) {
                    302:            fputs("0 1 1 0 K\n", gpoutfile);
                    303:        } else {
                    304:            fputs("[2 3] 0 d\n", gpoutfile);
                    305:        }
                    306:        break;
                    307:
                    308:     case 3:
                    309:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    310:        if (ai_color) {
                    311:            fputs("0 1 0 0 K\n", gpoutfile);
                    312:        } else {
                    313:            fputs("[1 1.5] 0 d\n", gpoutfile);
                    314:        }
                    315:        break;
                    316:
                    317:     case 4:
                    318:        fprintf(gpoutfile, "%f w\n", AI_LW / AI_SC);
                    319:        if (ai_color) {
                    320:            fputs("1 0 0 0 K\n", gpoutfile);
                    321:        } else {
                    322:            fputs("[5 2 1 2] 0 d\n", gpoutfile);
                    323:        }
                    324:        break;
                    325:
                    326:     case 5:
                    327:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    328:        if (ai_color) {
                    329:            fputs("0 0 1 0 K\n", gpoutfile);
                    330:        } else {
                    331:            fputs("[4 3 1 3] 0 d\n", gpoutfile);
                    332:        }
                    333:        break;
                    334:
                    335:     case 6:
                    336:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    337:        if (ai_color) {
                    338:            fputs("0 0 0 1 K\n", gpoutfile);
                    339:        } else {
                    340:            fputs("[2 2 2 4] 0 d\n", gpoutfile);
                    341:        }
                    342:        break;
                    343:
                    344:     case 7:
                    345:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    346:        if (ai_color) {
                    347:            fputs("0 0.7 1 0 K\n", gpoutfile);
                    348:        } else {
                    349:            fputs("[2 2 2 2 2 4] 0 d\n", gpoutfile);
                    350:        }
                    351:        break;
                    352:
                    353:     case 8:
                    354:        fprintf(gpoutfile, "%.2f w\n", AI_LW / AI_SC);
                    355:        if (ai_color) {
                    356:            fputs("0.5 0.5 0.5 0 K\n", gpoutfile);
                    357:        } else {
                    358:            fputs("[2 2 2 2 2 2 2 4] 0 d\n", gpoutfile);
                    359:        }
                    360:        break;
                    361:     }
                    362:
                    363:     ai_path_count = 0;
                    364: }
                    365:
                    366:
                    367: TERM_PUBLIC void AI_move(x, y)
                    368: unsigned int x, y;
                    369: {
                    370:     if (ai_stroke)
                    371:        fputs("S\n", gpoutfile);
                    372:     fprintf(gpoutfile, "%.2f %.2f m\n", x / AI_SC, y / AI_SC);
                    373:     ai_path_count += 1;
                    374:     ai_stroke = TRUE;
                    375: }
                    376:
                    377:
                    378: TERM_PUBLIC void AI_vector(x, y)
                    379: unsigned int x, y;
                    380: {
                    381:     fprintf(gpoutfile, "%.2f %.2f l\n", x / AI_SC, y / AI_SC);
                    382:     ai_path_count += 1;
                    383:     ai_stroke = TRUE;
                    384:     if (ai_path_count >= 400) {
                    385:        fprintf(gpoutfile, "S\n%.2f %.2f m\n", x / AI_SC, y / AI_SC);
                    386:        ai_path_count = 0;
                    387:     }
                    388: }
                    389:
                    390:
                    391: TERM_PUBLIC void AI_put_text(x, y, str)
                    392: unsigned int x, y;
                    393: char *str;
                    394: {
                    395:     char ch;
                    396:     if (ai_stroke) {
                    397:        fputs("S\n", gpoutfile);
                    398:        ai_stroke = FALSE;
                    399:     }
                    400:     switch (ai_justify) {
                    401:     case LEFT:
                    402:        fprintf(gpoutfile, "/_%s %d 0 0 0 z\n", ai_font, ai_fontsize);
                    403:        break;
                    404:     case CENTRE:
                    405:        fprintf(gpoutfile, "/_%s %d 0 0 1 z\n", ai_font, ai_fontsize);
                    406:        break;
                    407:     case RIGHT:
                    408:        fprintf(gpoutfile, "/_%s %d 0 0 2 z\n", ai_font, ai_fontsize);
                    409:        break;
                    410:     }
                    411:     if (ai_ang == 0) {
                    412:        fprintf(gpoutfile, "[ 1 0 0 1 %.2f %.2f] e\n",
                    413:                x / AI_SC, y / AI_SC - ai_fontsize / 3.0);
                    414:     } else {
                    415:        fprintf(gpoutfile, "[ 0 1 -1 0 %.2f %.2f] e\n",
                    416:                x / AI_SC - ai_fontsize / 3.0, y / AI_SC);
                    417:     }
                    418:
                    419:     putc('(', gpoutfile);
                    420:     ch = *str++;
                    421:     while (ch != '\0') {
                    422:        if ((ch == '(') || (ch == ')') || (ch == '\\'))
                    423:            putc('\\', gpoutfile);
                    424:        putc(ch, gpoutfile);
                    425:        ch = *str++;
                    426:     }
                    427:     fputs(") t\nT\n", gpoutfile);
                    428:     ai_path_count = 0;
                    429: }
                    430:
                    431: TERM_PUBLIC int AI_text_angle(ang)
                    432: int ang;
                    433: {
                    434:     ai_ang = ang;
                    435:     return TRUE;
                    436: }
                    437:
                    438: TERM_PUBLIC int AI_justify_text(mode)
                    439: enum JUSTIFY mode;
                    440: {
                    441:     ai_justify = mode;
                    442:     return TRUE;
                    443: }
                    444:
                    445: TERM_PUBLIC int AI_set_font(font) /* Entry font added by DJL */
                    446: char *font;
                    447: {
                    448:     char name[32];
                    449:     int size, sep;
                    450:
                    451:     if (font && *font) {
                    452:        sep = strcspn(font, ",");
                    453:        strncpy(name, font, sep);
                    454:        name[sep] = '\0';
                    455:        size = ai_fontsize;
                    456:        sscanf(&(font[sep + 1]), "%d", &size);
                    457:        if (*name)
                    458:            strcpy(ai_font, name);
                    459:        if (size)
                    460:            ai_fontsize = size;
                    461:     } else {
                    462:        ai_fontsize = ai_oldfontsize;
                    463:        strcpy(ai_font, ai_oldfont);
                    464:     }
                    465:     return TRUE;
                    466: }
                    467:
                    468:
                    469: TERM_PUBLIC void AI_suspend()
                    470: {
                    471: }
                    472:
                    473: TERM_PUBLIC void AI_resume()
                    474: {
                    475: }
                    476:
                    477:
                    478: #endif
                    479:
                    480:
                    481: #ifdef TERM_TABLE
                    482:
                    483: TERM_TABLE_START(aifm_driver)
                    484:     "aifm", "Adobe Illustrator 3.0 Format",
                    485:     AI_XMAX, AI_YMAX, AI_VCHAR, AI_HCHAR,
                    486:     AI_VTIC, AI_HTIC, AI_options, AI_init, AI_reset,
                    487:     AI_text, null_scale, AI_graphics, AI_move, AI_vector,
                    488:     AI_linetype, AI_put_text, AI_text_angle,
                    489:     AI_justify_text, do_point, do_arrow, AI_set_font,
                    490:     NULL, 0, AI_suspend, AI_resume
                    491: TERM_TABLE_END(aifm_driver)
                    492:
                    493: #undef LAST_TERM
                    494: #define LAST_TERM aifm_driver
                    495:
                    496: #endif /* TERM_TABLE */
                    497: #endif /* TERM_PROTO_ONLY */
                    498:
                    499: #ifdef TERM_HELP
                    500: START_HELP(aifm)
                    501: "1 aifm",
                    502: "?commands set terminal aifm",
                    503: "?set terminal aifm",
                    504: "?set term aifm",
                    505: "?terminal aifm",
                    506: "?term aifm",
                    507: "?aifm",
                    508: " Several options may be set in `aifm`---the Adobe Illustrator 3.0+ driver.",
                    509: "",
                    510: " Syntax:",
                    511: "       set terminal aifm {<color>} {\"<fontname>\"} {<fontsize>}",
                    512: "",
                    513: " <color> is either `color` or `monochrome`; \"<fontname>\" is the name of a",
                    514: " valid PostScript font; <fontsize> is the size of the font in PostScript",
                    515: " points, before scaling by the `set size` command.  Selecting `default` sets",
                    516: " all options to their default values: `monochrome`, \"Helvetica\", and 14pt.",
                    517: "",
                    518: " Since AI does not really support multiple pages, multiple graphs will be",
                    519: " drawn directly on top of one another.  However, each graph will be grouped",
                    520: " individually, making it easy to separate them inside AI (just pick them up",
                    521: " and move them).",
                    522: "",
                    523: " Examples:",
                    524: "       set term aifm",
                    525: "       set term aifm 22",
                    526: "       set size 0.7,1.4; set term aifm color \"Times-Roman\" 14"
                    527: END_HELP(ai)
                    528: #endif /* TERM_HELP */

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