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

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

1.1     ! ohara       1: /*Hello, Emacs! this is -*-C-*- ! */
        !             2: /*------------------------------------------------------------------------------------------------------------------------------------
        !             3:        GNUPLOT - svg.trm
        !             4:
        !             5:        This file is included by ../term.c.
        !             6:
        !             7:        This terminal driver supports:
        !             8:                W3C Scalable Vector Graphics
        !             9:
        !            10:        AUTHOR
        !            11:
        !            12:                Amedeo Farello
        !            13:                afarello@libero.it
        !            14:
        !            15:        HEAVILY MODIFIED by
        !            16:
        !            17:                Hans-Bernhard Br"oker
        !            18:                broeker@physik.rwth-aachen.de
        !            19:
        !            20: ------------------------------------------------------------------------------------------------------------------------------------*/
        !            21: #include "driver.h"
        !            22:
        !            23: #ifdef TERM_REGISTER
        !            24: register_term (svg)
        !            25: #endif
        !            26:
        !            27: #ifdef TERM_PROTO
        !            28: TERM_PUBLIC void SVG_options __PROTO ((void));
        !            29: TERM_PUBLIC void SVG_init __PROTO ((void));
        !            30: TERM_PUBLIC void SVG_graphics __PROTO ((void));
        !            31: TERM_PUBLIC void SVG_text __PROTO ((void));
        !            32: TERM_PUBLIC void SVG_linetype __PROTO ((int linetype));
        !            33: TERM_PUBLIC void SVG_move __PROTO ((unsigned int x, unsigned int y));
        !            34: TERM_PUBLIC void SVG_vector __PROTO ((unsigned int x, unsigned int y));
        !            35: TERM_PUBLIC void SVG_put_text __PROTO ((unsigned int x, unsigned int y, char *str));
        !            36: TERM_PUBLIC void SVG_reset __PROTO ((void));
        !            37: TERM_PUBLIC int SVG_justify_text __PROTO ((enum JUSTIFY mode));
        !            38: TERM_PUBLIC int SVG_text_angle __PROTO ((int ang));
        !            39: TERM_PUBLIC void SVG_point __PROTO ((unsigned int x, unsigned int y, int pointstyle));
        !            40: TERM_PUBLIC int SVG_set_font __PROTO ((char *font));
        !            41: /* TERM_PUBLIC void SVG_pointsize __PROTO((double pointsize)); */
        !            42: /* TERM_PUBLIC void SVG_fillbox __PROTO((int style, unsigned int x1, unsigned int y1, unsigned int width, unsigned int height)); */
        !            43: TERM_PUBLIC void SVG_linewidth __PROTO ((double linewidth));
        !            44:
        !            45: #define SVG_XMAX       600
        !            46: #define SVG_YMAX       480
        !            47:
        !            48: #endif /* TERM_PROTO */
        !            49:
        !            50: #ifndef TERM_PROTO_ONLY
        !            51: #ifdef TERM_BODY
        !            52:
        !            53: struct SVG_PEN
        !            54: {
        !            55:     double width;
        !            56:     char color[8];
        !            57: };
        !            58:
        !            59: unsigned int SVG_xSize = SVG_XMAX;     /* plot horizontal size */
        !            60: unsigned int SVG_ySize = SVG_YMAX;     /* plot vertical size*/
        !            61:
        !            62: unsigned int SVG_xLast = UINT_MAX;     /* current pen horizontal position*/
        !            63: unsigned int SVG_yLast = UINT_MAX;     /* current pen vertical position*/
        !            64:
        !            65: int SVG_LineType = -3; /* current line type*/
        !            66: double SVG_LineWidth = 1.0;    /* current line width*/
        !            67: int SVG_TextAngle = 0; /* current text orientation*/
        !            68: enum JUSTIFY SVG_TextJust = LEFT;      /* current text justification*/
        !            69:
        !            70: char SVG_fontNameDef[MAX_ID_LEN + 1] = "Arial";        /* default text font family*/
        !            71: double SVG_fontSizeDef = 12;   /* default text size*/
        !            72: char SVG_fontNameCur[MAX_ID_LEN + 1] = "Arial";        /* current text font family*/
        !            73: double SVG_fontSizeCur = 12;   /* current text size*/
        !            74: TBOOLEAN SVG_groupIsOpen = FALSE; /* open group flag*/
        !            75: TBOOLEAN SVG_pathIsOpen = FALSE; /* open path flag*/
        !            76: unsigned int SVG_path_count = 0;       /* size of current path*/
        !            77: struct SVG_PEN SVG_pens[16];   /* pen descriptors*/
        !            78:
        !            79: int SVG_fontAscent = 0;        /* estimated current font ascent*/
        !            80: int SVG_fontDescent = 0;       /* estimated current font descent*/
        !            81: int SVG_fontLeading = 0;       /* estimated current font leading*/
        !            82: int SVG_fontAvWidth = 0;       /* estimated current font char average width*/
        !            83:
        !            84: static short SVG_Pen_RealID __PROTO ((int));
        !            85: static void SVG_PathOpen __PROTO ((void));
        !            86: static void SVG_PathClose __PROTO ((void));
        !            87: static void SVG_PathLimit __PROTO ((void));
        !            88: static void SVG_GroupOpen __PROTO ((void));
        !            89: static void SVG_GroupClose __PROTO ((void));
        !            90: static void SVG_SetFont __PROTO ((char *name, double size));
        !            91: /*------------------------------------------------------------------------------------------------------------------------------------
        !            92:        SVG_Pen_RealID
        !            93: ------------------------------------------------------------------------------------------------------------------------------------*/
        !            94: static short
        !            95: SVG_Pen_RealID (inPenCode)
        !            96:     int inPenCode;
        !            97: {
        !            98:     if (inPenCode >= 13)
        !            99:        inPenCode %= 13;        /* normalize pen code*/
        !           100:     if (inPenCode < -2)
        !           101:        inPenCode = -2;
        !           102:
        !           103:     return (inPenCode + 2);
        !           104: }
        !           105:
        !           106: /*------------------------------------------------------------------------------------------------------------------------------------
        !           107:        SVG_GroupOpen
        !           108: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           109: static void
        !           110: SVG_GroupOpen ()
        !           111: {
        !           112:     if (!SVG_groupIsOpen)     {
        !           113:        fprintf (gpoutfile,
        !           114:                 "<g style=\"fill:none; stroke:%s; stroke-width:%.2f\">\n",
        !           115:                 SVG_pens[SVG_Pen_RealID (SVG_LineType)].color,
        !           116:                 SVG_pens[SVG_Pen_RealID (SVG_LineType)].width);
        !           117:
        !           118:        SVG_groupIsOpen = TRUE;
        !           119:     }
        !           120: }
        !           121:
        !           122: /*------------------------------------------------------------------------------------------------------------------------------------
        !           123:        SVG_GroupClose
        !           124: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           125: static void
        !           126: SVG_GroupClose ()
        !           127: {
        !           128:     if (SVG_groupIsOpen)
        !           129:       {
        !           130:          fprintf (gpoutfile, "</g>\n");
        !           131:          SVG_groupIsOpen = FALSE;
        !           132:       }
        !           133: }
        !           134:
        !           135: /*------------------------------------------------------------------------------------------------------------------------------------
        !           136:        SVG_PathOpen
        !           137: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           138: static void
        !           139: SVG_PathOpen ()
        !           140: {
        !           141:     if (!SVG_pathIsOpen) {
        !           142:        fprintf (gpoutfile, "\t<path d=\"");
        !           143:        SVG_pathIsOpen = TRUE;
        !           144:     }
        !           145: }
        !           146:
        !           147: /*------------------------------------------------------------------------------------------------------------------------------------
        !           148:        SVG_PathClose
        !           149: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           150: static void
        !           151: SVG_PathClose ()
        !           152: {
        !           153:     if (SVG_pathIsOpen) {
        !           154:        fprintf (gpoutfile, "\"></path>\n");
        !           155:        SVG_path_count = 0;
        !           156:        SVG_pathIsOpen = FALSE;
        !           157:     }
        !           158: }
        !           159:
        !           160: /*------------------------------------------------------------------------------------------------------------------------------------
        !           161:        SVG_PathLimit
        !           162: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           163: static void
        !           164: SVG_PathLimit ()
        !           165: {
        !           166:     if (SVG_path_count >= 10) {        /* avoid excessive line length*/
        !           167:        fprintf (gpoutfile, "\n\t\t");
        !           168:        SVG_path_count = 0;
        !           169:     }
        !           170: }
        !           171:
        !           172: /*------------------------------------------------------------------------------------------------------------------------------------
        !           173:        SVG_SetFont
        !           174: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           175: static void
        !           176: SVG_SetFont (char *name, double size)
        !           177: {
        !           178:     strcpy (SVG_fontNameCur, name);
        !           179:     SVG_fontSizeCur = size;
        !           180:
        !           181: /* since we cannot interrogate SVG about text properties and according
        !           182:  * to SVG 1.0 W3C Candidate Recommendation 2 August 2000 the
        !           183:  * "line-height" of the 'text' element is defined to be equal to the
        !           184:  * 'font-size' (!), we have to to define font properties in a less
        !           185:  * than optimal way */
        !           186:
        !           187:     SVG_fontAscent = (int) (SVG_fontSizeCur * 1.00);   /* estimated current font ascent*/
        !           188:     SVG_fontDescent = (int) (SVG_fontSizeCur * 0.25);  /* estimated current font descent*/
        !           189:     SVG_fontLeading = (int) (SVG_fontSizeCur * 0.25);  /* estimated current font leading*/
        !           190:     SVG_fontAvWidth = (int) (SVG_fontSizeCur * 0.70);  /* estimated current font char average width*/
        !           191: }
        !           192:
        !           193: /*------------------------------------------------------------------------------------------------------------------------------------
        !           194:        SVG_options
        !           195: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           196: TERM_PUBLIC void
        !           197: SVG_options ()
        !           198: {
        !           199:     struct value a;
        !           200:
        !           201:     if (!END_OF_COMMAND) {     /* get terminal size*/
        !           202:        if (almost_equals (c_token, "s$ize")) {
        !           203:            c_token++;
        !           204:
        !           205:            if (END_OF_COMMAND)
        !           206:                int_error("expecting x size", c_token);
        !           207:            SVG_xSize = (unsigned int) real (const_express (&a));
        !           208:            if (SVG_xSize < 2 || SVG_xSize > 8192)
        !           209:                int_error("x size out of range", c_token);
        !           210:
        !           211:            if (END_OF_COMMAND)
        !           212:                int_error("expecting y size", c_token);
        !           213:            SVG_ySize = (unsigned int) real (const_express (&a));
        !           214:            if (SVG_ySize < 2 || SVG_ySize > 8192)
        !           215:                int_error("y size out of range", c_token);
        !           216:        }
        !           217:     }
        !           218:
        !           219:     if (!END_OF_COMMAND) {     /* get default font family name*/
        !           220:        if (almost_equals (c_token, "fn$ame"))  {
        !           221:            c_token++;
        !           222:
        !           223:            if (!END_OF_COMMAND && isstring (c_token)) {
        !           224:                quote_str (SVG_fontNameDef, c_token, MAX_ID_LEN);
        !           225:                c_token++;
        !           226:            } else
        !           227:                int_error("fname: expecting font name", c_token);
        !           228:        }
        !           229:     }
        !           230:
        !           231:     if (!END_OF_COMMAND) {     /* get default font size*/
        !           232:        if (almost_equals (c_token, "fs$ize")) {
        !           233:            c_token++;
        !           234:
        !           235:            if (END_OF_COMMAND)
        !           236:                int_error("fsize: expecting font size", c_token);
        !           237:            SVG_fontSizeDef = real (const_express (&a));
        !           238:        }
        !           239:     }
        !           240:
        !           241:     if (!END_OF_COMMAND)
        !           242:         int_error("unexpected text at end of command", c_token);
        !           243:
        !           244:     /* Save options back into options string in normalized format */
        !           245:     sprintf(term_options, "size %d %d fname '%s'  fsize %g",
        !           246:            SVG_xSize, SVG_ySize, SVG_fontNameDef, SVG_fontSizeDef);
        !           247: }
        !           248:
        !           249: /*------------------------------------------------------------------------------------------------------------------------------------
        !           250:        SVG_init
        !           251: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           252: TERM_PUBLIC void
        !           253: SVG_init ()
        !           254: {
        !           255:     /* setup pens*/
        !           256:     SVG_pens[0].width = SVG_LineWidth;
        !           257:     sprintf (SVG_pens[0].color, "black");      /* black*/
        !           258:     SVG_pens[1].width = SVG_LineWidth;
        !           259:     sprintf (SVG_pens[1].color, "gray");       /* medium gray*/
        !           260:     SVG_pens[2].width = SVG_LineWidth;
        !           261:     sprintf (SVG_pens[2].color, "red");
        !           262:     SVG_pens[3].width = SVG_LineWidth;
        !           263:     /* sprintf (SVG_pens[3].color, "#%2.2X%2.2X%2.2X", 0, 209, 0); */  /* green*/
        !           264:     sprintf (SVG_pens[3].color, "green");
        !           265:     SVG_pens[4].width = SVG_LineWidth;
        !           266:     /* sprintf (SVG_pens[4].color, "#%2.2X%2.2X%2.2X", 74, 77, 201); */        /* blue*/
        !           267:     sprintf (SVG_pens[4].color, "blue");       /* blue*/
        !           268:     SVG_pens[5].width = SVG_LineWidth;
        !           269:     /* sprintf (SVG_pens[5].color, "#%2.2X%2.2X%2.2X", 173, 0, 0); */  /* brick*/
        !           270:     sprintf (SVG_pens[5].color, "cyan");
        !           271:     SVG_pens[6].width = SVG_LineWidth;
        !           272:     sprintf (SVG_pens[6].color, "#%2.2X%2.2X%2.2X", 21, 117, 69);      /* pine green*/
        !           273:     SVG_pens[7].width = SVG_LineWidth;
        !           274:     sprintf (SVG_pens[7].color, "#%2.2X%2.2X%2.2X", 0, 0, 148);        /* navy*/
        !           275:     SVG_pens[8].width = SVG_LineWidth;
        !           276:     sprintf (SVG_pens[8].color, "#%2.2X%2.2X%2.2X", 255, 153, 0);      /* orange*/
        !           277:     SVG_pens[9].width = SVG_LineWidth;
        !           278:     sprintf (SVG_pens[9].color, "#%2.2X%2.2X%2.2X", 0, 153, 161);      /* green blue*/
        !           279:     SVG_pens[10].width = SVG_LineWidth;
        !           280:     sprintf (SVG_pens[10].color, "#%2.2X%2.2X%2.2X", 214, 214, 69);    /* olive*/
        !           281:     SVG_pens[11].width = SVG_LineWidth;
        !           282:     sprintf (SVG_pens[11].color, "#%2.2X%2.2X%2.2X", 163, 145, 255);   /* cornflower*/
        !           283:     SVG_pens[12].width = SVG_LineWidth;
        !           284:     sprintf (SVG_pens[12].color, "#%2.2X%2.2X%2.2X", 255, 204, 0);     /* gold*/
        !           285:     SVG_pens[13].width = SVG_LineWidth;
        !           286:     sprintf (SVG_pens[13].color, "#%2.2X%2.2X%2.2X", 214, 0, 120);     /* mulberry*/
        !           287:     SVG_pens[14].width = SVG_LineWidth;
        !           288:     sprintf (SVG_pens[14].color, "#%2.2X%2.2X%2.2X", 171, 214, 0);     /* green yellow*/
        !           289:     SVG_pens[15].width = SVG_LineWidth;
        !           290:     sprintf (SVG_pens[15].color, "#%2.2X%2.2X%2.2X", 222, 0, 186);     /* red violet*/
        !           291:
        !           292:     SVG_LineType = -3;
        !           293:
        !           294: /* set xmax, ymax*/
        !           295:
        !           296:     term->xmax = SVG_xSize;
        !           297:     term->ymax = SVG_ySize;
        !           298:
        !           299: /* set current font*/
        !           300:
        !           301:     SVG_SetFont (SVG_fontNameDef, SVG_fontSizeDef);
        !           302:
        !           303: /* set h_char, v_char*/
        !           304:
        !           305:     term->h_char = SVG_fontAvWidth;
        !           306:     term->v_char = (SVG_fontAscent + SVG_fontDescent + SVG_fontLeading);
        !           307:
        !           308: /* set h_tic, v_tic*/
        !           309:
        !           310:     term->h_tic = term->v_char / 2;
        !           311:     term->v_tic = term->v_char / 2;
        !           312:
        !           313: /* write file header*/
        !           314:
        !           315:     fprintf (gpoutfile,
        !           316:             "<?xml version=\"1.0\" standalone=\"no\"?>\n"
        !           317:             "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20001102//EN\" \"svg-20001102.dtd\">\n"
        !           318:             "<svg width=\"%u\" height=\"%u\" viewBox=\"0 0 %u %u\">\n\n"
        !           319:             "<desc>Produced by GNUPLOT %s patchlevel %s</desc>\n\n",
        !           320:             term->xmax, term->ymax, term->xmax, term->ymax,
        !           321:             gnuplot_version, gnuplot_patchlevel);
        !           322:
        !           323:     /* definitions of point symbols */
        !           324:     /* FIXME: SVG scales linewidth along with the marker itself, and
        !           325:      * there seems to be no way to avoid that without copying the
        !           326:      * marker definition into the file, rather than referencing a
        !           327:      * defined one :-( That would make for much larger files */
        !           328:
        !           329:
        !           330:     fprintf (gpoutfile,
        !           331:             "<defs>\n"
        !           332:             /* dot: */
        !           333:             "\t<circle id=\"gpDot\" r=\"1\"></circle>\n"
        !           334:             /* diamond: */
        !           335:             "\t<path id=\"gpPt0\" style=\"stroke-width:%.3f\" d=\"M-1,0 L0,-1 L1,0 L0 1 z\"></path>\n"
        !           336:             /* cross: */
        !           337:             "\t<path id=\"gpPt1\" style=\"stroke-width:%.3f\" d=\"M-1,0 h2 M0,-1 v2\"></path>\n"
        !           338:             /* square: */
        !           339:             "\t<path id=\"gpPt2\" style=\"stroke-width:%.3f\" d=\"M-1,-1 h2 v2 h-2 z\"></path>\n"
        !           340:             /* triangle: */
        !           341:             "\t<path id=\"gpPt3\" style=\"stroke-width:%.3f\" d=\"M0,1.33 L-1.33,-0.67 L1.33,-0.67 z\"></path>\n"
        !           342:             /* 6-pointed star: */
        !           343:             "\t<path id=\"gpPt4\" style=\"stroke-width:%.3f\" d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\"></path>\n"
        !           344:             "</defs>\n"
        !           345:             , 2.0 / term->h_tic
        !           346:             , 2.0 / term->h_tic
        !           347:             , 2.0 / term->h_tic
        !           348:             , 2.0 / term->h_tic
        !           349:             , 2.0 / term->h_tic
        !           350:        );
        !           351: }
        !           352:
        !           353: /*------------------------------------------------------------------------------------------------------------------------------------
        !           354:        SVG_graphics
        !           355: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           356: TERM_PUBLIC void
        !           357: SVG_graphics ()
        !           358: {
        !           359:     /* fprintf (gpoutfile, "<svg>\n"); --- disabled HBB 20001116*/
        !           360:
        !           361:     SVG_groupIsOpen = FALSE;
        !           362:     SVG_pathIsOpen = FALSE;
        !           363:
        !           364: /* reset position*/
        !           365:
        !           366:     SVG_xLast = SVG_yLast = UINT_MAX;
        !           367: }
        !           368:
        !           369: /*------------------------------------------------------------------------------------------------------------------------------------
        !           370:        SVG_text
        !           371: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           372: TERM_PUBLIC void
        !           373: SVG_text ()
        !           374: {
        !           375:     SVG_PathClose ();
        !           376:     SVG_GroupClose ();
        !           377:
        !           378:     /* fprintf (gpoutfile, "</svg>\n\n"); --- disabled HBB 20001116 */
        !           379: }
        !           380:
        !           381: /*------------------------------------------------------------------------------------------------------------------------------------
        !           382:        SVG_reset
        !           383: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           384: TERM_PUBLIC void
        !           385: SVG_reset ()
        !           386: {
        !           387:     fprintf (gpoutfile, "</svg>\n\n");
        !           388: }
        !           389:
        !           390: /*------------------------------------------------------------------------------------------------------------------------------------
        !           391:        SVG_linetype
        !           392: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           393: TERM_PUBLIC void
        !           394: SVG_linetype (int linetype)
        !           395: {
        !           396:     if (linetype != SVG_LineType) {
        !           397:        SVG_PathClose ();
        !           398:        SVG_GroupClose ();
        !           399:        SVG_LineType = linetype;
        !           400:        SVG_GroupOpen ();
        !           401:     }
        !           402: }
        !           403:
        !           404: /*------------------------------------------------------------------------------------------------------------------------------------
        !           405:        SVG_linewidth - verificare
        !           406: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           407: TERM_PUBLIC void
        !           408: SVG_linewidth (double linewidth)
        !           409: {
        !           410:     if (linewidth != SVG_LineWidth) {
        !           411:        short k;
        !           412:
        !           413:        SVG_LineWidth = linewidth;
        !           414:
        !           415:        for (k = 0; k < 16; k++)
        !           416:            SVG_pens[k].width = SVG_LineWidth;
        !           417:     }
        !           418: }
        !           419:
        !           420: /*------------------------------------------------------------------------------------------------------------------------------------
        !           421:        SVG_move
        !           422: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           423: TERM_PUBLIC void
        !           424: SVG_move (unsigned int x, unsigned int y)
        !           425: {
        !           426:     if (x != SVG_xLast || y != SVG_yLast)  {
        !           427:        SVG_PathOpen ();
        !           428:
        !           429:        fprintf (gpoutfile, "M%u,%u ", x, term->ymax - y);
        !           430:        SVG_path_count++;
        !           431:
        !           432:        SVG_PathLimit ();
        !           433:
        !           434:        SVG_xLast = x;
        !           435:        SVG_yLast = y;
        !           436:     }
        !           437: }
        !           438:
        !           439: /*------------------------------------------------------------------------------------------------------------------------------------
        !           440:        SVG_vector
        !           441: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           442: TERM_PUBLIC void
        !           443: SVG_vector (unsigned int x, unsigned int y)
        !           444: {
        !           445:     if (x != SVG_xLast || y != SVG_yLast) {
        !           446:        SVG_PathOpen ();
        !           447:
        !           448:        fprintf (gpoutfile, "L%u,%u ", x, term->ymax - y);
        !           449:        SVG_path_count++;
        !           450:
        !           451:        SVG_PathLimit ();
        !           452:
        !           453:        SVG_xLast = x;
        !           454:        SVG_yLast = y;
        !           455:     }
        !           456: }
        !           457:
        !           458: /*------------------------------------------------------------------------------------------------------------------------------------
        !           459:        SVG_point
        !           460: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           461: TERM_PUBLIC void
        !           462: SVG_point (unsigned int x, unsigned int y, int number)
        !           463: {
        !           464:     SVG_PathClose ();
        !           465:
        !           466:     if (number < 0) {          /* do dot */
        !           467:        fprintf (gpoutfile,
        !           468:                 "\t<use xlink:href=\"#gpDot\" x=\"%u\" y=\"%u\"></use>\n",
        !           469:                 x, term->ymax - y);
        !           470:
        !           471:     } else {                   /* draw a point symbol */
        !           472:        fprintf (
        !           473:            gpoutfile,
        !           474:            "\t<use xlink:href=\"#gpPt%1u\" transform=\"translate(%u,%u) scale(%.2f)\"></use>\n"
        !           475:            , number % 5, x, term->ymax - y
        !           476:            , term_pointsize * term->h_tic / 2
        !           477:            );
        !           478:     }
        !           479:     SVG_xLast = x;
        !           480:     SVG_yLast = y;
        !           481: }
        !           482:
        !           483: /*------------------------------------------------------------------------------------------------------------------------------------
        !           484:        SVG_justify_text
        !           485: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           486: TERM_PUBLIC int
        !           487: SVG_justify_text (enum JUSTIFY mode)
        !           488: {
        !           489:     SVG_TextJust = mode;
        !           490:     return (TRUE);
        !           491: }
        !           492:
        !           493: /*------------------------------------------------------------------------------------------------------------------------------------
        !           494:        SVG_text_angle
        !           495: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           496: TERM_PUBLIC int
        !           497: SVG_text_angle (int ang)
        !           498: {
        !           499:     if (ang == 0 || ang == 1) {
        !           500:        SVG_TextAngle = ang;
        !           501:        return (TRUE);
        !           502:     }
        !           503:
        !           504:     return (FALSE);
        !           505: }
        !           506:
        !           507: /*------------------------------------------------------------------------------------------------------------------------------------
        !           508:        SVG_put_text
        !           509: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           510: TERM_PUBLIC void
        !           511: SVG_put_text (unsigned int x, unsigned int y, char *str)
        !           512: {
        !           513:     char *alignment;
        !           514:     int h = x, v = y;
        !           515:
        !           516:     SVG_PathClose ();
        !           517:
        !           518: /* horizontal justification*/
        !           519:
        !           520:     switch (SVG_TextJust) {
        !           521:     case LEFT:
        !           522:        alignment = "start";
        !           523:        break;
        !           524:     case CENTRE:
        !           525:        alignment = "middle";
        !           526:        break;
        !           527:     case RIGHT:
        !           528:     default:   /* can't happen, just to make gcc happy */
        !           529:        alignment = "end";
        !           530:        break;
        !           531:     }
        !           532:
        !           533: /* vertical justification*/
        !           534:
        !           535:     switch (SVG_TextAngle) {
        !           536:     case 1:
        !           537:        h += (SVG_fontAscent - SVG_fontDescent) / 2;
        !           538:        break;          /* vertical text*/
        !           539:     default:
        !           540:        v -= (SVG_fontAscent - SVG_fontDescent) / 2;
        !           541:        break;          /* orizontal text*/
        !           542:     }
        !           543:
        !           544: /* define text position and attributes*/
        !           545:
        !           546:     fprintf (gpoutfile, "\t<g transform=\"translate(%d,%d)%s\" \
        !           547: style=\"stroke:none; fill:%s; font-family:%s; font-size:%.2f; text-anchor:%s\">\n",
        !           548:             h, term->ymax - v,
        !           549:             SVG_TextAngle ? " rotate(-90)" : "",
        !           550:             SVG_pens[SVG_Pen_RealID (SVG_LineType)].color,
        !           551:             SVG_fontNameCur, SVG_fontSizeCur, alignment);
        !           552:
        !           553: /* output text*/
        !           554:
        !           555:     fprintf (gpoutfile, "\t\t<text>%s</text>\n\t</g>\n", str);
        !           556: }
        !           557:
        !           558: /*------------------------------------------------------------------------------------------------------------------------------------
        !           559:        SVG_set_font
        !           560: ------------------------------------------------------------------------------------------------------------------------------------*/
        !           561: TERM_PUBLIC int
        !           562: SVG_set_font (char *font)
        !           563: {
        !           564:     if (strlen (font) > 0) {   /* if available, parse the font specification ("fontname,fontsize")*/
        !           565:        short index;
        !           566:        char *token,
        !           567:            seps[] = ",", *buffer = (char *) malloc (strlen (font) + 1);
        !           568:
        !           569:        if (buffer == NULL)
        !           570:            return (FALSE);
        !           571:        strcpy (buffer, font);
        !           572:
        !           573:        for (token = strtok (buffer, seps), index = 1;
        !           574:             token != NULL; token = strtok (NULL, seps), index++
        !           575:            ) {
        !           576:            switch (index) {
        !           577:            case 1:
        !           578:                strcpy (SVG_fontNameCur, token);
        !           579:                break;  /* font name*/
        !           580:            case 2:
        !           581:                SVG_fontSizeCur = atoi (token);
        !           582:                break;  /* font size*/
        !           583:            default:
        !           584:                break;
        !           585:            }
        !           586:        }
        !           587:
        !           588:        free (buffer);
        !           589:     } else {                   /* otherwise simply reset the default font*/
        !           590:        strcpy (SVG_fontNameCur, SVG_fontNameDef);
        !           591:        SVG_fontSizeCur = SVG_fontSizeDef;
        !           592:     }
        !           593:
        !           594:     return (TRUE);
        !           595: }
        !           596:
        !           597: #endif /* TERM_BODY */
        !           598:
        !           599: #ifdef TERM_TABLE
        !           600: TERM_TABLE_START (svg_driver)
        !           601:     "svg", "W3C Scalable Vector Graphics driver",
        !           602:     0 /* xmax */ , 0 /* ymax */ , 0 /* vchar */ , 0 /* hchar */ ,
        !           603:     0 /* vtic */ , 0 /* htic */ ,
        !           604:     SVG_options, SVG_init, SVG_reset, SVG_text, null_scale, SVG_graphics,
        !           605:     SVG_move, SVG_vector, SVG_linetype, SVG_put_text, SVG_text_angle,
        !           606:     SVG_justify_text, SVG_point, do_arrow, SVG_set_font, do_pointsize,
        !           607:     TERM_CAN_MULTIPLOT,
        !           608:     0 /* suspend */, 0 /* resume */ , 0 /* fillbox */ , SVG_linewidth
        !           609: TERM_TABLE_END (svg_driver)
        !           610: #undef LAST_TERM
        !           611: #define LAST_TERM svg_driver
        !           612: #endif /* TERM_TABLE */
        !           613:
        !           614: #endif /* TERM_PROTO_ONLY */
        !           615:
        !           616: #ifdef TERM_HELP
        !           617:     START_HELP (svg)
        !           618:     "1 svg",
        !           619:     "?commands set terminal svg",
        !           620:     "?set terminal svg",
        !           621:     "?set term svg",
        !           622:     "?terminal svg",
        !           623:     "?term svg",
        !           624:     "?svg",
        !           625:     " This terminal produces files in the W3C Scalable Vector Graphics format.",
        !           626:     "",
        !           627:     " Syntax:",
        !           628:     "       set terminal svg {size <x> <y>}",
        !           629:     "                        {fname \"<font>\"} {fsize <fontsize>}",
        !           630:     "",
        !           631:     " where <x> and <y> are the size of the SVG plot to generate,",
        !           632:     " <font> is the name of the default font to use (default Arial) and",
        !           633:     " <fontsize> is the font size (in points, default 12)"
        !           634:     END_HELP (svg)
        !           635: #endif

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