]> granicus.if.org Git - graphviz/commitdiff
-more work on the new postscipt renderer
authorellson <devnull@localhost>
Tue, 6 Jun 2006 01:38:40 +0000 (01:38 +0000)
committerellson <devnull@localhost>
Tue, 6 Jun 2006 01:38:40 +0000 (01:38 +0000)
-simplify textsize() interface and carry fontname and size in textpara_t

14 files changed:
graphs/directed/Makefile.am
lib/common/fontmetrics.c
lib/common/htmltable.c
lib/common/labels.c
lib/common/render.h
lib/common/textpara.h
lib/common/types.h
lib/gvc/gvcjob.h
lib/gvc/gvcproc.h
lib/gvc/gvplugin_textlayout.h
lib/gvc/gvrender.c
lib/gvc/gvtextlayout.c
plugin/gd/gvrender_gd.c
plugin/gd/gvtextlayout_gd.c

index 581dbd0fdaa54082f79b2d881ca0223a4ec57039..748a4a54f1ef19ca636ce26a28bab75114365188 100644 (file)
@@ -142,6 +142,10 @@ ps:
        for i in $(GRAPHS); do echo "dot $$i"; \
                $(top_builddir)/cmd/dot/dot -Tps -o$$i.ps $(top_srcdir)/graphs/directed/$$i; done
 
+ps_gd:
+       for i in $(GRAPHS); do echo "dot $$i"; \
+               $(top_builddir)/cmd/dot/dot -Tps:gd -o$$i.ps $(top_srcdir)/graphs/directed/$$i; done
+
 ps_cairo:
        for i in $(GRAPHS); do echo "dot $$i"; \
                $(top_builddir)/cmd/dot/dot -Tps:cairo -o$$i.ps $(top_srcdir)/graphs/directed/$$i; done
index 371703274b47ca3d639678c40da21567f60df5df..1f9b35f1e631ceebd3424465ebdc2b2ba0c0c10a 100644 (file)
@@ -131,22 +131,22 @@ extern codegen_t GD_CodeGen;
  * fontsize to get appropriate value.
  */
 static void
-estimate_textsize(graph_t *g, textpara_t * para, char *fontname, double fontsz, char **fontpath)
+estimate_textlayout(graph_t *g, textpara_t * para, char **fontpath)
 {
     double *Fontwidth;
     char c, *p;
 
     para->width = 0.0;
-    para->height = fontsz;
+    para->height = para->fontsize;
     para->xshow = NULL;
-    para->layout = fontname;
+    para->layout = para->fontname;
     para->free_layout = NULL;
 
-    if (!strncasecmp(fontname, "cour", 4)) {
+    if (!strncasecmp(para->fontname, "cour", 4)) {
        *fontpath = "[internal courier]";
        Fontwidth = courFontWidth;
-    } else if (!strncasecmp(fontname, "arial", 5)
-              || !strncasecmp(fontname, "helvetica", 9)) {
+    } else if (!strncasecmp(para->fontname, "arial", 5)
+              || !strncasecmp(para->fontname, "helvetica", 9)) {
        *fontpath = "[internal arial]";
        Fontwidth = arialFontWidth;
     } else {
@@ -156,7 +156,7 @@ estimate_textsize(graph_t *g, textpara_t * para, char *fontname, double fontsz,
     if ((p = para->str)) {
        while ((c = *p++))
            para->width += Fontwidth[(unsigned char) c];
-       para->width *= fontsz;
+       para->width *= para->fontsize;
     }
 }
 
@@ -165,13 +165,16 @@ pointf textsize(graph_t *g, textpara_t * para, char *fontname, double fontsize)
     char *fontpath = NULL;
     pointf size;
 
-    if (! gvtextlayout(GD_gvc(g), para, fontname, fontsize, &fontpath))
-       estimate_textsize(g, para, fontname, fontsize, &fontpath);
+    para->fontname = fontname;
+    para->fontsize = fontsize;
+
+    if (! gvtextlayout(GD_gvc(g), para, &fontpath))
+       estimate_textlayout(g, para, &fontpath);
 
     if (Verbose) {
-       if (emit_once(fontname)) {
-           fprintf(stderr, "%s: fontname=%s fontpath=%s\n", GD_gvc(g)->common.cmdname,
-                   fontname, fontpath);
+       if (emit_once(para->fontname)) {
+           fprintf(stderr, "%s: fontname=%s fontpath=%s\n",
+                   GD_gvc(g)->common.cmdname, para->fontname, fontpath);
        }
     }
     size.x = para->width;
index 3445394871318cbf71473c4465c3c25d5e9dcf9b..e5fc3f112d431a58d16e7eb796d52b02de828c95 100644 (file)
@@ -200,6 +200,8 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p,
            gvrender_set_font(job, fname_, fsize_);
 
            tl.str = ti->str;
+           tl.fontname = fname_;
+           tl.fontsize = fsize_;
            tl.xshow = ti->xshow;
            tl.layout = ti->layout;
            tl.width = paras[i].size;
index 7e8a251988fce47a793e441d6f815d672a013c37..658ed2cf7b628716cb72fc2dd38ab9f8ebbb445b 100644 (file)
 static void storeline(graph_t *g, textlabel_t *lp, char *line, char terminator)
 {
     pointf size;
+    textpara_t *para;
 
     lp->u.txt.para =
        ALLOC(lp->u.txt.nparas + 2, lp->u.txt.para, textpara_t);
-    lp->u.txt.para[lp->u.txt.nparas].str = line;
-    size = textsize(g, &(lp->u.txt.para[lp->u.txt.nparas]),
-           lp->fontname, lp->fontsize);
-    lp->u.txt.para[lp->u.txt.nparas].just = terminator;
+    para = &(lp->u.txt.para[lp->u.txt.nparas]);
+    para->str = line;
+    para->just = terminator;
+    size = textsize(g, para, lp->fontname, lp->fontsize);
     lp->u.txt.nparas++;
     /* total width = max line width */
     if (lp->dimen.x < size.x)
index ea034b76f2ad2501a1fe691bc9023a6452e8e564..0f1e0e7cbbd6124c20cf8b6a9a57d75a9d602f80 100644 (file)
@@ -120,8 +120,6 @@ extern "C" {
     extern void free_line(textpara_t *);
     extern void free_label(textlabel_t *);
     extern char *gd_alternate_fontlist(char *font);
-    extern char *gd_textsize(textpara_t * textpara, char *fontname,
-                            double fontsz, char **fontpath);
     extern void getdouble(graph_t * g, char *name, double *result);
     extern splines *getsplinepoints(edge_t * e);
     extern void global_def(char *,
@@ -158,8 +156,7 @@ extern "C" {
     extern void shape_clip(node_t * n, point curve[4]);
     extern void size_label (graph_t* g, textlabel_t* rv);
     extern void start_timer(void);
-    extern pointf textsize(graph_t *g, textpara_t * para,
-                           char *fontname, double fontsz);
+    extern pointf textsize(graph_t *g, textpara_t * para, char *fontname, double fontsize);
     extern void translate_bb(Agraph_t *, int);
     extern void write_attributed_dot(graph_t *g, FILE *f);
     extern void write_canonical_dot(graph_t *g, FILE *f);
index 7873fdeaf3ef6b05949fe02da1b580024314ac80..c8828b85c42d317de3794614a7f4d7933689f778 100644 (file)
@@ -23,10 +23,11 @@ extern "C" {
 
     typedef struct textpara_t {
        char *str;      /* stored in utf-8 */
+       char *fontname; 
        char *xshow;
        void *layout;
        void (*free_layout) (void *layout);   /* FIXME - this is ugly */
-       double width, height;
+       double fontsize, width, height;
        char just;
     } textpara_t;
 
index 2e8d07f1b9024bb4a558f8eb720868d1aed056fb..1c8235df74f6ff4d129c12555f754d03ffac9382 100644 (file)
@@ -211,7 +211,7 @@ extern "C" {
        void (*begin_anchor) (char *href, char *tooltip, char *target);
        void (*end_anchor) (void);
        void (*set_font) (char *fontname, double fontsize);
-       void (*textpara) (point p, textpara_t * str);
+       void (*textpara) (point p, textpara_t * para);
        void (*set_pencolor) (char *name);
        void (*set_fillcolor) (char *name);
        void (*set_style) (char **s);
index 5d6b67c897e2fb6be23f7634d2fcd3931b9f6e47..b7ccda083c6c014fff02353c1d5219cb8f5925a2 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
     typedef enum { GVATTR_STRING, GVATTR_BOOL, GVATTR_COLOR } gvattr_t;
 
     typedef struct {
+       char **rawstyle;
        char *fontfam, fontopt;
        gvcolor_t pencolor, fillcolor;
        pen_type pen;
@@ -157,6 +158,7 @@ extern "C" {
        bool external_surface; /* surface belongs to caller */
 
        gvstyle_t *style;       /* active style from gvc->styles[] */
+       char *objname;          /* "graph", "node", or "edge" */
 
         int flags;             /* emit_graph flags */
 
index d969c50d2d7fa615ef0a7c77f33611cf357e6f75..610c104affad2474325f194bf845256cc4847660 100644 (file)
@@ -57,8 +57,7 @@ extern "C" {
 /* textlayout */
 
     extern int gvtextlayout_select(GVC_t * gvc);
-    extern bool gvtextlayout(GVC_t *gvc, textpara_t *para,
-                      char *fontname, double fontsize, char **fontpath);
+    extern bool gvtextlayout(GVC_t *gvc, textpara_t *para, char **fontpath);
 
 /* usershapes */
     extern point gvusershape_size(graph_t *g, char *name);
index b61c0d5c3ab448c8e98e5c71f81660e32553cfa5..b9a91b302a00f2bfbebf42e02d9944a42d2767cf 100644 (file)
@@ -26,7 +26,7 @@ extern "C" {
 #endif
 
     struct gvtextlayout_engine_s {
-       void (*textlayout) (textpara_t *para, char *fontname, double fontsize, char** fontpath);
+       void (*textlayout) (textpara_t *para, char** fontpath);
     };
 
 #ifdef __cplusplus
index fca287447efca95f8f462252cc7786a1aaf28cfa..29901031e7b73c2439bf700b9474f3b410fb11f7 100644 (file)
@@ -246,6 +246,7 @@ void gvrender_begin_graph(GVJ_t * job, graph_t * g)
     sy = job->height / (job->zoom * 2.);
 
     gvc->sg = g;  /* current subgraph/cluster */
+    job->objname = "graph";
     job->compscale.x = job->zoom * job->dpi.x / POINTS_PER_INCH;
     job->compscale.y = job->zoom * job->dpi.y / POINTS_PER_INCH;
     job->compscale.y *= (job->flags & GVRENDER_Y_GOES_DOWN) ? -1. : 1.;
@@ -417,6 +418,7 @@ void gvrender_begin_cluster(GVJ_t * job, graph_t * sg)
 #ifdef WITH_CODEGENS
     Obj = CLST;
 #endif
+    job->objname = "graph";
     if (gvre && gvre->begin_cluster)
        gvre->begin_cluster(job, sg->name, sg->meta_node->id);
 #ifdef WITH_CODEGENS
@@ -518,6 +520,7 @@ void gvrender_begin_node(GVJ_t * job, node_t * n)
 #ifdef WITH_CODEGENS
     Obj = NODE;
 #endif
+    job->objname = "node";
     job->gvc->n = n; /* set current node */
     if (gvre && gvre->begin_node)
        gvre->begin_node(job, n->name, n->id);
@@ -556,6 +559,7 @@ void gvrender_begin_edge(GVJ_t * job, edge_t * e)
 #ifdef WITH_CODEGENS
     Obj = EDGE;
 #endif
+    job->objname = "edge";
     job->gvc->e = e; /* set current edge */
     if (gvre && gvre->begin_edge)
        gvre->begin_edge(job, e->tail->name,
@@ -750,6 +754,7 @@ void gvrender_set_style(GVJ_t * job, char **s)
     char *line, *p;
     gvstyle_t *style = job->style;
 
+    style->rawstyle = s;
     if (gvre) {
        while ((p = line = *s++)) {
            if (streq(line, "solid"))
index 4dbb6191aec7d73e9f89c1e21966df2446031bf7..6678e64e8f06d36adcb3c760f5949595bbda177a 100644 (file)
@@ -42,12 +42,12 @@ int gvtextlayout_select(GVC_t * gvc)
     return NO_SUPPORT;
 }
 
-bool gvtextlayout(GVC_t *gvc, textpara_t *para, char *fontname, double fontsize, char **fontpath)
+bool gvtextlayout(GVC_t *gvc, textpara_t *para, char **fontpath)
 {
     gvtextlayout_engine_t *gvte = gvc->textlayout.engine;
 
     if (gvte && gvte->textlayout) {
-       gvte->textlayout(para, fontname, fontsize, fontpath);
+       gvte->textlayout(para, fontpath);
        return TRUE;
     }
     return FALSE;
index 15dbc83c72130ab81d4853df7fafdce7a9899a0d..bb602e386de020d6f16434744c05c81f23b04bf9 100644 (file)
@@ -315,13 +315,9 @@ extern gdFontPtr gdFontTiny, gdFontSmall, gdFontMediumBold, gdFontLarge, gdFontG
 
 static void gdgen_textpara(GVJ_t * job, pointf p, textpara_t * para)
 {
-    gvstyle_t *style = job->style;
     gdImagePtr im = (gdImagePtr) job->surface;
-    char *fontlist;
     pointf mp, ep;
-    char *str = para->str;
     double parawidth = para->width * job->compscale.x;
-    double fontsz = style->fontsz;
     gdFTStringExtra strex;
 #if defined(HAVE_LIBFREETYPE) && defined(HAVE_GD_FREETYPE)
     char *err;
@@ -334,13 +330,11 @@ static void gdgen_textpara(GVJ_t * job, pointf p, textpara_t * para)
     strex.flags = gdFTEX_RESOLUTION;
     strex.hdpi = strex.vdpi = POINTS_PER_INCH * job->compscale.x;
 
-    if (strstr(style->fontfam, "/"))
+    if (strstr(para->fontname, "/"))
        strex.flags |= gdFTEX_FONTPATHNAME;
     else
        strex.flags |= gdFTEX_FONTCONFIG;
 
-    fontlist = (char*)(para->layout);
-
     switch (para->just) {
     case 'l':
        mp.x = 0.0;
@@ -366,59 +360,59 @@ static void gdgen_textpara(GVJ_t * job, pointf p, textpara_t * para)
        ep.y = mp.y = p.y;
     }
 
-    if (fontsz <= FONTSIZE_MUCH_TOO_SMALL) {
+    if (para->fontsize <= FONTSIZE_MUCH_TOO_SMALL) {
        /* ignore entirely */
-    } else if (fontsz <= FONTSIZE_TOO_SMALL) {
+    } else if (para->fontsize <= FONTSIZE_TOO_SMALL) {
        /* draw para in place of text */
        gdImageLine(im, ROUND(mp.x), ROUND(mp.y),
                    ROUND(ep.x), ROUND(ep.y),
-                   style->pencolor.u.index);
+                   job->style->pencolor.u.index);
     } else {
 #if defined(HAVE_LIBFREETYPE) && defined(HAVE_GD_FREETYPE)
-       err = gdImageStringFTEx(im, brect, style->pencolor.u.index,
-                               fontlist, fontsz, job->rotation ? (PI / 2) : 0,
-                               ROUND(mp.x), ROUND(mp.y), str, &strex);
+       err = gdImageStringFTEx(im, brect, job->style->pencolor.u.index,
+                               para->fontname, para->fontsize, job->rotation ? (PI / 2) : 0,
+                               ROUND(mp.x), ROUND(mp.y), (char *)(para->str), &strex);
 #if 0
        gdImagePolygon(im, (gdPointPtr) brect, 4,
-                      style->pencolor.u.index);
+                      job->style->pencolor.u.index);
 #endif
 #if 0
        fprintf(stderr,
                "textpara: font=%s size=%g pos=%g,%g width=%g dpi=%d width/dpi=%g\n",
-               fontlist, fontsz, mp.x, mp.y, (double) (brect[4] - brect[0]),
+               para->fontname, para->fontsize, mp.x, mp.y, (double) (brect[4] - brect[0]),
                strex.hdpi,
                (((double) (brect[4] - brect[0])) / strex.hdpi));
 #endif
        if (err) {
            /* revert to builtin fonts */
-           gdgen_missingfont(err, style->fontfam);
+           gdgen_missingfont(err, para->fontname);
 #endif
            mp.y += 2;
-           if (fontsz <= 8.5) {
+           if (para->fontsize <= 8.5) {
                gdImageString(im, gdFontTiny,
                              ROUND(mp.x), ROUND(mp.y - 9.),
-                             (unsigned char *) str,
-                             style->pencolor.u.index);
-           } else if (fontsz <= 9.5) {
+                             (unsigned char *)para->str,
+                             job->style->pencolor.u.index);
+           } else if (para->fontsize <= 9.5) {
                gdImageString(im, gdFontSmall,
                              ROUND(mp.x), ROUND(mp.y - 12.),
-                             (unsigned char *) str,
-                             style->pencolor.u.index);
-           } else if (fontsz <= 10.5) {
+                             (unsigned char *)para->str,
+                             job->style->pencolor.u.index);
+           } else if (para->fontsize <= 10.5) {
                gdImageString(im, gdFontMediumBold,
                              ROUND(mp.x), ROUND(mp.y - 13.),
-                             (unsigned char *) str,
-                             style->pencolor.u.index);
-           } else if (fontsz <= 11.5) {
+                             (unsigned char *)para->str,
+                             job->style->pencolor.u.index);
+           } else if (para->fontsize <= 11.5) {
                gdImageString(im, gdFontLarge,
                              ROUND(mp.x), ROUND(mp.y - 14.),
-                             (unsigned char *) str,
-                             style->pencolor.u.index);
+                             (unsigned char *)para->str,
+                             job->style->pencolor.u.index);
            } else {
                gdImageString(im, gdFontGiant,
                              ROUND(mp.x), ROUND(mp.y - 15.),
-                             (unsigned char *) str,
-                             style->pencolor.u.index);
+                             (unsigned char *)para->str,
+                             job->style->pencolor.u.index);
            }
 #if defined(HAVE_LIBFREETYPE) && defined(HAVE_GD_FREETYPE)
        }
index 786daa96143863bade1332846b1a9414e8c97e89..240e655c8a426edb2a2b0291b6fe6770d89d1a4a 100644 (file)
@@ -33,7 +33,7 @@
 /* fontsize at which text is rendered by a simple line */
 #define FONTSIZE_TOO_SMALL 1.5
 
-void textlayout(textpara_t * para, char *fontname, double fontsize, char **fontpath)
+void textlayout(textpara_t * para, char **fontpath)
 {
     static char *fntpath;
     char *err;
@@ -45,30 +45,30 @@ void textlayout(textpara_t * para, char *fontname, double fontsize, char **fontp
     strex.xshow = NULL;
     strex.hdpi = strex.vdpi = 72;
 
-    if (strstr(fontname, "/"))
+    if (strstr(para->fontname, "/"))
        strex.flags |= gdFTEX_FONTPATHNAME;
     else
        strex.flags |= gdFTEX_FONTCONFIG;
 
     para->width = 0.0;
-    para->width = 0.0;
+    para->height = 0.0;
     para->xshow = NULL;
 
-    para->layout = (void*)fontname;
-    para->free_layout = NULL; /* no need to free fontname */
+    para->layout = NULL;
+    para->free_layout = NULL;
 
-    if (fontname) {
-       if (fontsize <= FONTSIZE_MUCH_TOO_SMALL) {
+    if (para->fontname) {
+       if (para->fontsize <= FONTSIZE_MUCH_TOO_SMALL) {
            /* OK, but ignore text entirely */
            return;
-       } else if (fontsize <= FONTSIZE_TOO_SMALL) {
+       } else if (para->fontsize <= FONTSIZE_TOO_SMALL) {
            /* draw line in place of text */
            /* fake a finite fontsize so that line length is calculated */
-           fontsize = FONTSIZE_TOO_SMALL;
+           para->fontsize = FONTSIZE_TOO_SMALL;
        }
        /* call gdImageStringFT with null *im to get brect and to set font cache */
-       err = gdImageStringFTEx(NULL, brect, -1, fontname,
-                               fontsize, 0, 0, 0, para->str, &strex);
+       err = gdImageStringFTEx(NULL, brect, -1, para->fontname,
+                               para->fontsize, 0, 0, 0, para->str, &strex);
 
        if (err) {
            fprintf(stderr,"%s\n", err);