]> granicus.if.org Git - graphviz/commitdiff
various -Tfig:core fixes
authorellson <devnull@localhost>
Wed, 26 Jul 2006 22:05:49 +0000 (22:05 +0000)
committerellson <devnull@localhost>
Wed, 26 Jul 2006 22:05:49 +0000 (22:05 +0000)
  - support standard postscript fonts
remove -Tfig:cg  (i.e. remove figgen.c)

lib/common/Makefile.am
lib/common/figgen.c [deleted file]
plugin/core/gvrender_core_fig.c

index f0b5c1dae52d544be63dff87947f47a62b14807d..c46bbeee513ad4787848f2e3f843c00464255ed3 100644 (file)
@@ -17,8 +17,7 @@ noinst_HEADERS = render.h utils.h memory.h \
 noinst_LTLIBRARIES = libcommon_C.la
 
 if WITH_CODEGENS
-CODEGENS = $(GD_CODEGENS) diagen.c figgen.c hpglgen.c mifgen.c mpgen.c \
-       picgen.c vtxgen.c xdgen.c
+CODEGENS = $(GD_CODEGENS) diagen.c hpglgen.c mifgen.c mpgen.c picgen.c vtxgen.c xdgen.c
 endif
 
 
diff --git a/lib/common/figgen.c b/lib/common/figgen.c
deleted file mode 100644 (file)
index b0e3eba..0000000
+++ /dev/null
@@ -1,655 +0,0 @@
-/* $Id$ $Revision$ */
-/* vim:set shiftwidth=4 ts=8: */
-
-/**********************************************************
-*      This software is part of the graphviz package      *
-*                http://www.graphviz.org/                 *
-*                                                         *
-*            Copyright (c) 1994-2004 AT&T Corp.           *
-*                and is licensed under the                *
-*            Common Public License, Version 1.0           *
-*                      by AT&T Corp.                      *
-*                                                         *
-*        Information and Software Systems Research        *
-*              AT&T Research, Florham Park NJ             *
-**********************************************************/
-
-#include <ctype.h>
-#include "render.h"
-
-/* FIG font modifiers */
-#define REGULAR 0
-#define BOLD   1
-#define ITALIC 2
-
-/* FIG patterns */
-#define P_SOLID        0
-#define P_NONE  15
-#define P_DOTTED 2
-#define P_DASHED 1
-
-/* FIG bold line constant */
-#define WIDTH_NORMAL 1
-#define WIDTH_BOLD 3
-
-/* Number of points to split splines into */
-#define BEZIERSUBDIVISION 6
-
-static int N_pages;
-/* static      point   Pages; */
-static pointf Dpi;
-static point Margin;
-static pointf CompScale;
-static int Rot;
-
-static point Viewport;
-static pointf GraphFocus;
-static double Zoom;
-static int Depth;
-
-typedef struct context_t {
-    unsigned char pencolor_ix, fillcolor_ix;
-    char *fontfam, fontopt, font_was_set;
-    char line_style, fill, penwidth, style_was_set;
-    double fontsz, style_val;
-} context_t;
-
-#define MAXNEST 4
-static context_t cstk[MAXNEST];
-static int SP;
-
-static int figColorResolve(int *new, int r, int g, int b)
-{
-#define maxColors 256
-    static int top = 0;
-    static short red[maxColors], green[maxColors], blue[maxColors];
-    int c;
-    int ct = -1;
-    long rd, gd, bd, dist;
-    long mindist = 3 * 255 * 255;      /* init to max poss dist */
-
-    *new = 0;                  /* in case it is not a new color */
-    for (c = 0; c < top; c++) {
-       rd = (long) (red[c] - r);
-       gd = (long) (green[c] - g);
-       bd = (long) (blue[c] - b);
-       dist = rd * rd + gd * gd + bd * bd;
-       if (dist < mindist) {
-           if (dist == 0)
-               return c;       /* Return exact match color */
-           mindist = dist;
-           ct = c;
-       }
-    }
-    /* no exact match.  We now know closest, but first try to allocate exact */
-    if (top++ == maxColors)
-       return ct;              /* Return closest available color */
-    red[c] = r;
-    green[c] = g;
-    blue[c] = b;
-    *new = 1;                  /* flag new color */
-    return c;                  /* Return newly allocated color */
-}
-
-static point figfpt(pointf p)
-{
-    point rv;
-
-    if (Rot == 0) {
-        rv.x = ROUND(  (p.x - GraphFocus.x) * CompScale.x + Viewport.x / 2. + Margin.x);
-        rv.y = ROUND( -(p.y - GraphFocus.y) * CompScale.y + Viewport.y / 2. + Margin.y);
-    } else {
-        rv.x = ROUND( -(p.y - GraphFocus.y) * CompScale.x + Viewport.x / 2. + Margin.x);
-        rv.y = ROUND( -(p.x - GraphFocus.x) * CompScale.y + Viewport.y / 2. + Margin.y);
-    }
-
-    return rv;
-}
-
-static point figpt(point p)
-{
-    pointf P;
-
-    P2PF(p,P);
-    return figfpt(P);
-}
-
-static void figptarray(point * A, int n, int close)
-{
-    int i;
-    point p;
-
-    for (i = 0; i < n; i++) {
-       p = figpt(A[i]);
-       fprintf(Output_file, " %d %d", p.x, p.y);
-    }
-    if (close) {
-       p = figpt(A[0]);
-       fprintf(Output_file, " %d %d", p.x, p.y);
-    }
-    fprintf(Output_file, "\n");
-}
-
-static void fig_comment(char *str)
-{
-    fprintf(Output_file, "# %s\n", str);
-}
-
-static void
-fig_begin_job(FILE * ofp, graph_t * g, char **lib, char *user,
-             char *info[], point pages)
-{
-    /* Pages = pages; */
-    N_pages = pages.x * pages.y;
-    fprintf(Output_file, "#FIG 3.2\n");
-    fprintf(Output_file, "# Generated by %s version %s (%s)\n", info[0],
-           info[1], info[2]);
-    fprintf(Output_file, "# For: %s\n", user);
-    fprintf(Output_file, "# Title: %s\n", g->name);
-    fprintf(Output_file, "# Pages: %d\n", N_pages);
-    fprintf(Output_file, "Portrait\n");        /* orientation */
-    fprintf(Output_file, "Center\n");  /* justification */
-    fprintf(Output_file, "Inches\n");  /* units */
-    fprintf(Output_file, "Letter\n");  /* papersize */
-    fprintf(Output_file, "100.00\n");  /* magnification % */
-    fprintf(Output_file, "Single\n");  /* multiple-page */
-    fprintf(Output_file, "-2\n");      /* transparent color (none) */
-    fprintf(Output_file, "1200 ");     /* resolution */
-    fprintf(Output_file, "2\n");       /* coordinate system (upper left) */
-}
-
-static void fig_end_job(void)
-{
-    fprintf(Output_file, "# end of FIG file\n");
-}
-
-static void fig_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb)
-{
-    Dpi = gvc->job->dpi;
-    Margin.x = ROUND(gvc->job->margin.x * Dpi.x / POINTS_PER_INCH);
-    Margin.y = ROUND(gvc->job->margin.y * Dpi.y / POINTS_PER_INCH);
-    Viewport.x = gvc->job->width;
-    Viewport.y = gvc->job->height;
-    Zoom = gvc->job->zoom;
-    GraphFocus = gvc->job->focus;
-    CompScale.x = Zoom *  Dpi.x / POINTS_PER_INCH;
-    CompScale.y = Zoom *  Dpi.y / POINTS_PER_INCH;
-
-    SP = 0;
-    cstk[0].pencolor_ix = 0;   /* FIG pencolor index */
-    cstk[0].fillcolor_ix = 0;  /* FIG fillcolor index */
-    cstk[0].fontfam = DEFAULT_FONTNAME;        /* font family name */
-    cstk[0].fontopt = REGULAR; /* modifier: REGULAR, BOLD or ITALIC */
-    cstk[0].line_style = P_SOLID;      /* pen pattern style, default is solid */
-    cstk[0].style_val = 0.0;   /* style_val, used for dashed style */
-    cstk[0].fill = P_NONE;
-    cstk[0].penwidth = WIDTH_NORMAL;
-}
-
-static void
-fig_begin_page(graph_t * g, point page, double scale, int rot, point offset)
-{
-    Rot = rot;
-    Depth = 2;
-}
-
-static void
-fig_begin_node(node_t *n)
-{
-    Depth = 1;
-}
-
-static void
-fig_end_node(void)
-{
-    Depth = 2;
-}
-
-static void
-fig_begin_edge(edge_t *e)
-{
-    Depth = 0;
-}
-
-static void
-fig_end_edge(void)
-{
-    Depth = 2;
-}
-
-static void fig_begin_context(void)
-{
-    assert(SP + 1 < MAXNEST);
-    cstk[SP + 1] = cstk[SP];
-    SP++;
-}
-
-static void fig_end_context(void)
-{
-    int psp = SP - 1;
-    assert(SP > 0);
-    /* if (cstk[SP].font_was_set) fig_font(&(cstk[psp])); */
-    /* if (cstk[SP].style_was_set) fig_style(&(cstk[psp])); */
-    /*free(cstk[psp].fontfam); */
-    SP = psp;
-}
-
-static void fig_set_font(char *name, double size)
-{
-    char *p, *q;
-    context_t *cp;
-
-    cp = &(cstk[SP]);
-    cp->font_was_set = TRUE;
-    cp->fontsz = size;
-    p = strdup(name);
-    if ((q = strchr(p, '-'))) {
-       *q++ = 0;
-       if (strcasecmp(q, "italic") == 0)
-           cp->fontopt = ITALIC;
-       else if (strcasecmp(q, "bold") == 0)
-           cp->fontopt = BOLD;
-    }
-    cp->fontfam = p;
-/*     fig_font(&cstk[SP]); */
-}
-
-static void fig_color(int i, int r, int g, int b)
-{
-    int object_code = 0;       /* always 0 for color */
-
-    fprintf(Output_file, "%d %d #%02x%02x%02x\n", object_code, i, r, g, b);
-}
-
-static unsigned char fig_resolve_color(char *name)
-{
-    unsigned char i;
-    int new;
-    char *tok;
-    gvcolor_t color;
-
-    static char *figcolor[] = { "black", "blue", "green", "cyan",
-       "red", "magenta", "yellow", "white", (char *) NULL
-    };
-
-    tok = canontoken(name);
-    for (i = 0; figcolor[i]; i++) {
-       if (streq(figcolor[i], tok))
-           return i;
-    }
-    colorxlate(name, &color, RGBA_BYTE);
-    i = 32 + figColorResolve(&new, color.u.rgba[0], color.u.rgba[1],
-                            color.u.rgba[2]);
-    if (new)
-       fig_color(i, color.u.rgba[0], color.u.rgba[1], color.u.rgba[2]);
-    return i;
-}
-
-static void fig_set_pencolor(char *name)
-{
-    cstk[SP].pencolor_ix = fig_resolve_color(name);
-}
-
-static void fig_set_fillcolor(char *name)
-{
-    cstk[SP].fillcolor_ix = fig_resolve_color(name);
-}
-
-static void fig_set_style(char **s)
-{
-    char *line, *p;
-    context_t *cp;
-
-    cp = &(cstk[SP]);
-    while ((p = line = *s++)) {
-       if (streq(line, "solid")) {
-           cp->line_style = P_SOLID;
-           cp->style_val = 0.0;
-       } else if (streq(line, "dashed")) {
-           cp->line_style = P_DASHED;
-           cp->style_val = 4.0;
-       } else if (streq(line, "dotted")) {
-           cp->line_style = P_DOTTED;
-           cp->style_val = 3.0;
-       } else if (streq(line, "invis"))
-           cp->line_style = P_NONE;
-       else if (streq(line, "bold"))
-           cp->penwidth = WIDTH_BOLD;
-       else if (streq(line, "setlinewidth")) {
-           while (*p)
-               p++;
-           p++;
-           cp->penwidth = atol(p);
-       } else if (streq(line, "filled"))
-           cp->fill = P_SOLID;
-       else if (streq(line, "unfilled"))
-           cp->fill = P_NONE;
-       else {
-           agerr(AGWARN,
-                 "fig_set_style: unsupported style %s - ignoring\n",
-                 line);
-       }
-       cp->style_was_set = TRUE;
-    }
-/*     if (cp->style_was_set) fig_style(cp); */
-}
-
-static char *fig_string(char *s)
-{
-    static char *buf = NULL;
-    static int bufsize = 0;
-    int pos = 0;
-    char *p;
-    unsigned char c;
-
-    if (!buf) {
-       bufsize = 64;
-       buf = N_GNEW(bufsize, char);
-    }
-
-    p = buf;
-    while ((c = *s++)) {
-       if (pos > (bufsize - 8)) {
-           bufsize *= 2;
-           buf = grealloc(buf, bufsize);
-           p = buf + pos;
-       }
-       if (isascii(c)) {
-           if (c == '\\') {
-               *p++ = '\\';
-               pos++;
-           }
-           *p++ = c;
-           pos++;
-       } else {
-           *p++ = '\\';
-           sprintf(p, "%03o", c);
-           p += 3;
-           pos += 4;
-       }
-    }
-    *p = '\0';
-    return buf;
-}
-
-static void fig_textpara(point p, textpara_t * para)
-{
-    int object_code = 4;       /* always 4 for text */
-    int sub_type = 0;          /* text justification */
-    int color = cstk[SP].pencolor_ix;
-    int depth = Depth;
-    int pen_style = 0;         /* not used */
-    int font = 0;
-    double font_size = para->fontsize * Zoom;
-    double angle = Rot ? (PI / 2.0) : 0.0;
-    int font_flags = 2;
-    double height = 0.0;
-    double length = 0.0;
-    point mp;
-
-    switch (para->just) {
-    case 'l':
-       sub_type = 0;
-       break;
-    case 'r':
-       sub_type = 2;
-       break;
-    default:
-    case 'n':
-       sub_type = 1;
-       break;
-    }
-    mp.x = p.x;
-    mp.y = p.y;
-    mp = figpt(mp);
-
-    fprintf(Output_file,
-           "%d %d %d %d %d %d %.1f %.4f %d %.1f %.1f %d %d %s\\001\n",
-           object_code, sub_type, color, depth, pen_style, font,
-           font_size, angle, font_flags, height, length, mp.x, mp.y,
-           fig_string(para->str));
-}
-
-static void fig_bezier(point * A, int n, int arrow_at_start,
-                      int arrow_at_end, int filled)
-{
-    int object_code = 3;       /* always 3 for spline */
-    int sub_type;
-    int line_style = cstk[SP].line_style;      /* solid, dotted, dashed */
-    int thickness = cstk[SP].penwidth;
-    int pen_color = cstk[SP].pencolor_ix;
-    int fill_color;
-    int depth = Depth;
-    int pen_style = 0;         /* not used */
-    int area_fill;
-    double style_val = cstk[SP].style_val;
-    int cap_style = 0;
-    int forward_arrow = 0;
-    int backward_arrow = 0;
-    int npoints = n;
-    int i;
-
-    pointf p0, V[4];
-    point p1;
-    int j, step;
-    int count = 0;
-    int size;
-
-    char *buffer;
-    char *buf;
-    buffer =
-       malloc((npoints + 1) * (BEZIERSUBDIVISION +
-                               1) * 20 * sizeof(char));
-    buf = buffer;
-
-    if (filled) {
-       sub_type = 5;     /* closed X-spline */
-       area_fill = 20;   /* fully saturated color */
-       fill_color = cstk[SP].fillcolor_ix;
-    }
-    else {
-       sub_type = 4;     /* opened X-spline */
-       area_fill = -1;
-       fill_color = 0;
-    }
-    V[3].x = A[0].x;
-    V[3].y = A[0].y;
-    /* Write first point in line */
-    count++;
-    p0.x = A[0].x;
-    p0.y = A[0].y;
-    p1 = figfpt(p0);
-    size = sprintf(buf, " %d %d", p1.x, p1.y);
-    buf += size;
-    /* write subsequent points */
-    for (i = 0; i + 3 < n; i += 3) {
-       V[0] = V[3];
-       for (j = 1; j <= 3; j++) {
-           V[j].x = A[i + j].x;
-           V[j].y = A[i + j].y;
-       }
-       for (step = 1; step <= BEZIERSUBDIVISION; step++) {
-           count++;
-           p1 = figfpt(Bezier
-                       (V, 3, (double) step / BEZIERSUBDIVISION, NULL,
-                        NULL));
-           size = sprintf(buf, " %d %d", p1.x, p1.y);
-           buf += size;
-       }
-    }
-
-    fprintf(Output_file, "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d\n",
-           object_code,
-           sub_type,
-           line_style,
-           thickness,
-           pen_color,
-           fill_color,
-           depth,
-           pen_style,
-           area_fill,
-           style_val, cap_style, forward_arrow, backward_arrow, count);
-
-    fprintf(Output_file, " %s\n", buffer);     /* print points */
-    free(buffer);
-    for (i = 0; i < count; i++) {
-       fprintf(Output_file, " %d", i % (count - 1) ? 1 : 0);   /* -1 on all */
-    }
-    fprintf(Output_file, "\n");
-}
-
-static void fig_polygon(point * A, int n, int filled)
-{
-    int object_code = 2;       /* always 2 for polyline */
-    int sub_type = 3;          /* always 3 for polygon */
-    int line_style = cstk[SP].line_style;      /* solid, dotted, dashed */
-    int thickness = cstk[SP].penwidth;
-    int pen_color = cstk[SP].pencolor_ix;
-    int fill_color = cstk[SP].fillcolor_ix;
-    int depth = Depth;
-    int pen_style = 0;         /* not used */
-    int area_fill = filled ? 20 : -1;
-    double style_val = cstk[SP].style_val;
-    int join_style = 0;
-    int cap_style = 0;
-    int radius = 0;
-    int forward_arrow = 0;
-    int backward_arrow = 0;
-    int npoints = n + 1;
-
-    fprintf(Output_file,
-           "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
-           object_code, sub_type, line_style, thickness, pen_color,
-           fill_color, depth, pen_style, area_fill, style_val, join_style,
-           cap_style, radius, forward_arrow, backward_arrow, npoints);
-    figptarray(A, n, 1);       /* closed shape */
-}
-
-static void fig_ellipse(point p, int rx, int ry, int filled)
-{
-    int object_code = 1;       /* always 1 for ellipse */
-    int sub_type = 1;          /* ellipse defined by radii */
-    int line_style = cstk[SP].line_style;      /* solid, dotted, dashed */
-    int thickness = cstk[SP].penwidth;
-    int pen_color = cstk[SP].pencolor_ix;
-    int fill_color = cstk[SP].fillcolor_ix;
-    int depth = Depth;
-    int pen_style = 0;         /* not used */
-    int area_fill = filled ? 20 : -1;
-    double style_val = cstk[SP].style_val;
-    int direction = 0;
-    double angle = 0.0;
-    int center_x, center_y, radius_x, radius_y;
-    int start_x, start_y, end_x, end_y;
-
-    point p2;
-
-    p2.x = p.x + rx;
-    p2.y = p.y + ry;
-
-    p = figpt(p);
-    p2 = figpt(p2);
-
-#if 0
-    fprintf(stderr, "p %d %d\n", p.x, p.y);
-#endif
-    start_x = center_x = p.x;
-    start_y = center_y = p.y;
-    radius_x = p2.x - p.x;
-    radius_y = p2.y - p.y;
-    end_x = p2.x;
-    end_y = p2.y;
-
-    fprintf(Output_file,
-           "%d %d %d %d %d %d %d %d %d %.3f %d %.4f %d %d %d %d %d %d %d %d\n",
-           object_code, sub_type, line_style, thickness, pen_color,
-           fill_color, depth, pen_style, area_fill, style_val, direction,
-           angle, center_x, center_y, radius_x, radius_y, start_x,
-           start_y, end_x, end_y);
-}
-
-static void fig_polyline(point * A, int n)
-{
-    int object_code = 2;       /* always 2 for polyline */
-    int sub_type = 1;          /* always 1 for polyline */
-    int line_style = cstk[SP].line_style;      /* solid, dotted, dashed */
-    int thickness = cstk[SP].penwidth;
-    int pen_color = cstk[SP].pencolor_ix;
-    int fill_color = 0;
-    int depth = Depth;
-    int pen_style = 0;         /* not used */
-    int area_fill = 0;
-    double style_val = cstk[SP].style_val;
-    int join_style = 0;
-    int cap_style = 0;
-    int radius = 0;
-    int forward_arrow = 0;
-    int backward_arrow = 0;
-    int npoints = n;
-
-    fprintf(Output_file,
-           "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
-           object_code, sub_type, line_style, thickness, pen_color,
-           fill_color, depth, pen_style, area_fill, style_val, join_style,
-           cap_style, radius, forward_arrow, backward_arrow, npoints);
-    figptarray(A, n, 0);       /* open shape */
-}
-
-static void fig_usershape(usershape_t *us, boxf b, point *A, int n, bool filled)
-{
-    int object_code = 2;       /* always 2 for polyline */
-    int sub_type = 5;          /* always 5 for image */
-    int line_style = cstk[SP].line_style;      /* solid, dotted, dashed */
-    int thickness = cstk[SP].penwidth;
-    int pen_color = cstk[SP].pencolor_ix;
-    int fill_color = -1;
-    int depth = Depth;
-    int pen_style = -1;                /* not used */
-    int area_fill = 0;
-    double style_val = cstk[SP].style_val;
-    int join_style = 0;
-    int cap_style = 0;
-    int radius = 0;
-    int forward_arrow = 0;
-    int backward_arrow = 0;
-    int npoints = n + 1;
-    int flipped = 0;
-    char *imagefilename = us->name;
-    point a[4];
-
-    a[0] = A[1];  /* image rotation is determined by the bounding polygon */
-    a[1] = A[2];
-    a[2] = A[3];
-    a[3] = A[0];
-
-    fprintf(Output_file,
-           "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n %d %s\n",
-           object_code, sub_type, line_style, thickness, pen_color,
-           fill_color, depth, pen_style, area_fill, style_val, join_style,
-           cap_style, radius, forward_arrow, backward_arrow, npoints, 
-           flipped, imagefilename);
-
-    figptarray(a, 4, 1);       /* closed shape */
-}
-
-codegen_t FIG_CodeGen = {
-    0, /* fig_reset */
-    fig_begin_job, fig_end_job,
-    fig_begin_graph, 0,                /* fig_end_graph */
-    fig_begin_page, 0,         /* fig_end_page */
-    0, /* fig_begin_layer */ 0, /* fig_end_layer */
-    0, /* fig_begin_cluster */ 0, /* fig_end_cluster */
-    0, /* fig_begin_nodes */  0, /* fig_end_nodes */
-    0, /* fig_begin_edges */  0, /* fig_end_edges */
-    fig_begin_node, fig_end_node,
-    fig_begin_edge, fig_end_edge,
-    fig_begin_context, fig_end_context,
-    0, /* fig_begin_anchor */ 0,       /* fig_end_anchor */
-    fig_set_font, fig_textpara,
-    fig_set_pencolor, fig_set_fillcolor, fig_set_style,
-    fig_ellipse, fig_polygon,
-    fig_bezier, fig_polyline,
-    0,                         /* bezier_has_arrows */
-    fig_comment,
-    fig_usershape
-};
index 1cf707872d03dd08b5700dae8a0d8dd08eb822dc..af8c42dee71cc88b7a8e5ab64a8799dd921015f4 100644 (file)
@@ -77,11 +77,16 @@ void figgen_printf(GVJ_t * job, const char *format, ...)
 static void figptarray(GVJ_t *job, pointf * A, int n, int close)
 {
     int i;
+    point p;
 
-    for (i = 0; i < n; i++)
-        figgen_printf(job, " %d %d", A[i].x, A[i].y);
-    if (close)
-        figgen_printf(job, " %d %d", A[i].x, A[i].y);
+    for (i = 0; i < n; i++) {
+       PF2P(A[i],p);
+        figgen_printf(job, " %d %d", p.x, p.y);
+    }
+    if (close) {
+       PF2P(A[0],p);
+        figgen_printf(job, " %d %d", p.x, p.y);
+    }
     figgen_fputs(job, "\n");
 }
 
@@ -168,22 +173,25 @@ static void figgen_resolve_color(GVJ_t *job, gvcolor_t * color)
 
     switch (color->type) {
        case COLOR_STRING:
-           for (i = 0; figcolor[i]; i++)
-               if (streq(figcolor[i], color->u.string))
-                       color->u.index = i;
+           for (i = 0; figcolor[i]; i++) {
+               if (streq(figcolor[i], color->u.string)) {
+                   color->u.index = i;
+                   break;
+               }
+           }
            break;
        case RGBA_BYTE:
-           color->u.index = 32 + figColorResolve(&new,
+           i = 32 + figColorResolve(&new,
                        color->u.rgba[0],
                        color->u.rgba[1],
                        color->u.rgba[2]);
            if (new)
                figgen_printf(job, "%d %d #%02x%02x%02x\n",
-                       object_code,
-                       color->u.index,
+                       object_code, i,
                        color->u.rgba[0],
                        color->u.rgba[1],
                        color->u.rgba[2]);
+           color->u.index = i;
            break;
        default:
            assert(0);  /* internal error */
@@ -206,37 +214,26 @@ static void figgen_line_style(gvstyle_t *style, int *line_style, double *style_v
        case PEN_SOLID:
        default:
            *line_style = 0;
-           *style_val = 10.;
+           *style_val = 0.;
            break;
     }
 }
 
-static void figgen_begin_job(GVJ_t * job)
-{
-    figgen_fputs(job, "#FIG 3.2\n");
-    figgen_printf(job, "# Generated by %s version %s (%s)\n",
-       job->common->info[0], job->common->info[1], job->common->info[2]);
-    figgen_printf(job, "# For: %s\n", job->common->user);
-}
-
-static void figgen_end_job(GVJ_t * job)
+static void figgen_comment(GVJ_t *job, char *str)
 {
-    figgen_fputs(job, "# end of FIG file\n");
+    figgen_printf(job, "# %s\n", str);
 }
 
-
 static void figgen_begin_graph(GVJ_t * job)
 {
     obj_state_t *obj = job->obj;
 
+    figgen_fputs(job, "#FIG 3.2\n");
+    figgen_printf(job, "# Generated by %s version %s (%s)\n",
+       job->common->info[0], job->common->info[1], job->common->info[2]);
+    figgen_printf(job, "# For: %s\n", job->common->user);
     figgen_printf(job, "# Title: %s\n", obj->g->name);
     figgen_printf(job, "# Pages: %d\n", job->pagesArraySize.x * job->pagesArraySize.y);
-}
-
-static void figgen_begin_page(GVJ_t * job)
-{
-    Depth = 2;
-
     figgen_fputs(job, "Portrait\n"); /* orientation */
     figgen_fputs(job, "Center\n");   /* justification */
     figgen_fputs(job, "Inches\n");   /* units */
@@ -244,8 +241,18 @@ static void figgen_begin_page(GVJ_t * job)
     figgen_fputs(job, "100.00\n");   /* magnification % */
     figgen_fputs(job, "Single\n");   /* multiple-page */
     figgen_fputs(job, "-2\n");       /* transparent color (none) */
-    figgen_fputs(job, "1200 ");      /* resolution */
-    figgen_fputs(job, "2\n");        /* coordinate system (upper left) */
+    figgen_printf(job, "%d", ROUND(job->dpi.x)); /* resolution */
+    figgen_fputs(job, " 2\n");        /* coordinate system (upper left) */
+}
+
+static void figgen_end_graph(GVJ_t * job)
+{
+    figgen_fputs(job, "# end of FIG file\n");
+}
+
+static void figgen_begin_page(GVJ_t * job)
+{
+    Depth = 2;
 }
 
 static void figgen_begin_node(GVJ_t * job)
@@ -258,8 +265,7 @@ static void figgen_end_node(GVJ_t * job)
     Depth = 2;
 }
 
-static void
-figgen_begin_edge(GVJ_t * job)
+static void figgen_begin_edge(GVJ_t * job)
 {
     Depth = 0;
 }
@@ -278,13 +284,16 @@ static void figgen_textpara(GVJ_t * job, pointf p, textpara_t * para)
     int color = style->pencolor.u.index;
     int depth = Depth;
     int pen_style = 0;          /* not used */
-    int font = 0;
+    int font = -1;             /* init to xfig's default font */
     double font_size = para->fontsize * job->zoom;
     double angle = job->rotation ? (PI / 2.0) : 0.0;
-    int font_flags = 2;
+    int font_flags = 4;                /* PostScript font */
     double height = 0.0;
     double length = 0.0;
 
+    if (para->postscript_alias) /* if it is a standard postscript font */
+       font = para->postscript_alias->xfig_code; 
+
     switch (para->just) {
     case 'l':
         sub_type = 0;
@@ -299,57 +308,10 @@ static void figgen_textpara(GVJ_t * job, pointf p, textpara_t * para)
     }
 
     figgen_printf(job,
-            "%d %d %d %d %d %d %.1f %.4f %d %.1f %.1f %g %g %s\\001\n",
+            "%d %d %d %d %d %d %.1f %.4f %d %.1f %.1f %d %d %s\\001\n",
             object_code, sub_type, color, depth, pen_style, font,
-            font_size, angle, font_flags, height, length, p.x, p.y,
+            font_size, angle, font_flags, height, length, ROUND(p.x), ROUND(p.y),
             fig_string(para->str));
-
-#if 0
-    figgen_fputs(job, "<text");
-    switch (para->just) {
-    case 'l':
-       figgen_fputs(job, " text-anchor=\"start\"");
-       break;
-    case 'r':
-       figgen_fputs(job, " text-anchor=\"end\"");
-       break;
-    default:
-    case 'n':
-       figgen_fputs(job, " text-anchor=\"middle\"");
-       break;
-    }
-    figgen_printf(job, " x=\"%g\" y=\"%g\"", p.x, -p.y);
-    figgen_fputs(job, " style=\"");
-    if (para->postscript_alias) {
-        figgen_printf(job, "font-family:%s;", para->postscript_alias->family);
-        if (para->postscript_alias->weight)
-           figgen_printf(job, "font-weight:%s;", para->postscript_alias->weight);
-        if (para->postscript_alias->stretch)
-           figgen_printf(job, "font-stretch:%s;", para->postscript_alias->stretch);
-        if (para->postscript_alias->style)
-           figgen_printf(job, "font-style:%s;", para->postscript_alias->style);
-    }
-    else {
-        figgen_printf(job, "font:%s;", para->fontname);
-    }
-    figgen_printf(job, "font-size:%.2f;", para->fontsize);
-    switch (penstyle->pencolor.type) {
-    case COLOR_STRING:
-       if (strcasecmp(penstyle->pencolor.u.string, "black"))
-           figgen_printf(job, "fill:%s;", penstyle->pencolor.u.string);
-       break;
-    case RGBA_BYTE:
-       figgen_printf(job, "fill:#%02x%02x%02x;",
-               penstyle->pencolor.u.rgba[0],
-               penstyle->pencolor.u.rgba[1], penstyle->pencolor.u.rgba[2]);
-       break;
-    default:
-       assert(0);              /* internal error */
-    }
-    figgen_fputs(job, "\">");
-    figgen_fputs(job, xml_string(para->str));
-    figgen_fputs(job, "</text>\n");
-#endif
 }
 
 static void figgen_ellipse(GVJ_t * job, pointf * A, int filled)
@@ -373,12 +335,12 @@ static void figgen_ellipse(GVJ_t * job, pointf * A, int filled)
 
     figgen_line_style(style, &line_style, &style_val);
 
-    start_x = center_x = A[0].x;
-    start_y = center_y = -A[0].y;
-    radius_x = A[1].x - A[0].x;
-    radius_y = A[1].y - A[0].y;
-    end_x = A[1].x;
-    end_y = -A[1].y;
+    start_x = center_x = ROUND(A[0].x);
+    start_y = center_y = ROUND(A[0].y);
+    radius_x = ROUND(A[1].x - A[0].x);
+    radius_y = ROUND(A[1].y - A[0].y);
+    end_x = ROUND(A[1].x);
+    end_y = ROUND(A[1].y);
 
     figgen_printf(job,
             "%d %d %d %d %d %d %d %d %d %.3f %d %.4f %d %d %d %d %d %d %d %d\n",
@@ -410,7 +372,8 @@ figgen_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
     int npoints = n;
     int i;
 
-    pointf p, V[4];
+    pointf pf, V[4];
+    point p;
     int j, step;
     int count = 0;
     int size;
@@ -438,7 +401,8 @@ figgen_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
     V[3].y = A[0].y;
     /* Write first point in line */
     count++;
-    size = sprintf(buf, " %g %g", A[0].x, A[0].y);
+    PF2P(A[0], p);
+    size = sprintf(buf, " %d %d", p.x, p.y);
     buf += size;
     /* write subsequent points */
     for (i = 0; i + 3 < n; i += 3) {
@@ -449,8 +413,9 @@ figgen_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
         }
         for (step = 1; step <= BEZIERSUBDIVISION; step++) {
             count++;
-            p = Bezier (V, 3, (double) step / BEZIERSUBDIVISION, NULL, NULL);
-            size = sprintf(buf, " %g %g", p.x, p.y);
+            pf = Bezier (V, 3, (double) step / BEZIERSUBDIVISION, NULL, NULL);
+           PF2P(pf, p);
+            size = sprintf(buf, " %d %d", p.x, p.y);
             buf += size;
         }
     }
@@ -538,10 +503,10 @@ static void figgen_polyline(GVJ_t * job, pointf * A, int n)
 }
 
 gvrender_engine_t figgen_engine = {
-    figgen_begin_job,
-    figgen_end_job,
+    0,                         /* figgen_begin_job */
+    0,                         /* figgen_end_job */
     figgen_begin_graph,
-    0,                         /* figgen_end_graph */
+    figgen_end_graph,
     0,                         /* figgen_begin_layer */
     0,                         /* figgen_end_layer */
     figgen_begin_page,
@@ -564,7 +529,7 @@ gvrender_engine_t figgen_engine = {
     figgen_polygon,
     figgen_bezier,
     figgen_polyline,
-    0,                         /* figgen_comment */
+    figgen_comment
 };
 
 
@@ -575,11 +540,10 @@ static char *figgen_knowncolors[] = {
 
 
 gvrender_features_t figgen_features = {
-    GVRENDER_DOES_TRUECOLOR
-       | GVRENDER_Y_GOES_DOWN
-        | GVRENDER_DOES_TRANSFORM, /* flags */
+    EMIT_COLORS
+       | GVRENDER_Y_GOES_DOWN, /* flags */
     DEFAULT_EMBED_MARGIN,      /* default margin - points */
-    {96.,96.},                 /* default dpi */
+    {1200.,1200.},             /* default dpi */
     figgen_knowncolors,                /* knowncolors */
     sizeof(figgen_knowncolors) / sizeof(char *), /* sizeof knowncolors */
     RGBA_BYTE,                 /* color_type */
@@ -588,6 +552,6 @@ gvrender_features_t figgen_features = {
 };
 
 gvplugin_installed_t gvrender_core_fig_types[] = {
-    {FORMAT_FIG, "fig", -1, &figgen_engine, &figgen_features},
+    {FORMAT_FIG, "fig", 1, &figgen_engine, &figgen_features},
     {0, NULL, 0, NULL, NULL}
 };