From: ellson Date: Tue, 6 Jun 2006 01:38:40 +0000 (+0000) Subject: -more work on the new postscipt renderer X-Git-Tag: LAST_LIBGRAPH~32^2~6486 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b129c83ba09dc6ee09cd57cf09059de135de1c12;p=graphviz -more work on the new postscipt renderer -simplify textsize() interface and carry fontname and size in textpara_t --- diff --git a/graphs/directed/Makefile.am b/graphs/directed/Makefile.am index 581dbd0fd..748a4a54f 100644 --- a/graphs/directed/Makefile.am +++ b/graphs/directed/Makefile.am @@ -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 diff --git a/lib/common/fontmetrics.c b/lib/common/fontmetrics.c index 371703274..1f9b35f1e 100644 --- a/lib/common/fontmetrics.c +++ b/lib/common/fontmetrics.c @@ -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; diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index 344539487..e5fc3f112 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -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; diff --git a/lib/common/labels.c b/lib/common/labels.c index 7e8a25198..658ed2cf7 100644 --- a/lib/common/labels.c +++ b/lib/common/labels.c @@ -22,13 +22,14 @@ 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) diff --git a/lib/common/render.h b/lib/common/render.h index ea034b76f..0f1e0e7cb 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -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); diff --git a/lib/common/textpara.h b/lib/common/textpara.h index 7873fdeaf..c8828b85c 100644 --- a/lib/common/textpara.h +++ b/lib/common/textpara.h @@ -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; diff --git a/lib/common/types.h b/lib/common/types.h index 2e8d07f1b..1c8235df7 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -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); diff --git a/lib/gvc/gvcjob.h b/lib/gvc/gvcjob.h index 5d6b67c89..b7ccda083 100644 --- a/lib/gvc/gvcjob.h +++ b/lib/gvc/gvcjob.h @@ -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 */ diff --git a/lib/gvc/gvcproc.h b/lib/gvc/gvcproc.h index d969c50d2..610c104af 100644 --- a/lib/gvc/gvcproc.h +++ b/lib/gvc/gvcproc.h @@ -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); diff --git a/lib/gvc/gvplugin_textlayout.h b/lib/gvc/gvplugin_textlayout.h index b61c0d5c3..b9a91b302 100644 --- a/lib/gvc/gvplugin_textlayout.h +++ b/lib/gvc/gvplugin_textlayout.h @@ -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 diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index fca287447..29901031e 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -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")) diff --git a/lib/gvc/gvtextlayout.c b/lib/gvc/gvtextlayout.c index 4dbb6191a..6678e64e8 100644 --- a/lib/gvc/gvtextlayout.c +++ b/lib/gvc/gvtextlayout.c @@ -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; diff --git a/plugin/gd/gvrender_gd.c b/plugin/gd/gvrender_gd.c index 15dbc83c7..bb602e386 100644 --- a/plugin/gd/gvrender_gd.c +++ b/plugin/gd/gvrender_gd.c @@ -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) } diff --git a/plugin/gd/gvtextlayout_gd.c b/plugin/gd/gvtextlayout_gd.c index 786daa961..240e655c8 100644 --- a/plugin/gd/gvtextlayout_gd.c +++ b/plugin/gd/gvtextlayout_gd.c @@ -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);