From: ellson Date: Thu, 17 Aug 2006 18:08:33 +0000 (+0000) Subject: use textpara height from text_layout instead of basing it on fontsize X-Git-Tag: LAST_LIBGRAPH~32^2~5961 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8520e86a71c242663fb2a906440158d86357115c;p=graphviz use textpara height from text_layout instead of basing it on fontsize --- diff --git a/lib/common/const.h b/lib/common/const.h index 019e6800c..754d596b9 100644 --- a/lib/common/const.h +++ b/lib/common/const.h @@ -69,7 +69,6 @@ #define MIN_FONTSIZE 1.0 #define DEFAULT_FONTNAME "Times-Roman" #define DEFAULT_FILL "lightgrey" -#define LINESPACING 1.20 #define DEFAULT_NODEHEIGHT 0.5 #define MIN_NODEHEIGHT 0.02 diff --git a/lib/common/fontmetrics.c b/lib/common/fontmetrics.c index e6115b746..921958736 100644 --- a/lib/common/fontmetrics.c +++ b/lib/common/fontmetrics.c @@ -137,7 +137,7 @@ estimate_textlayout(graph_t *g, textpara_t * para, char **fontpath) char c, *p; para->width = 0.0; - para->height = para->fontsize; + para->height = para->fontsize * 1.3; para->xshow = NULL; para->layout = para->fontname; para->free_layout = NULL; diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index 3a0db576a..9e620929d 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -134,7 +134,7 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p, } if (i == 0) { - p_.y = p.y + (double)(b.UR.y-b.LL.y)/2 - paras[i].lfsize * 0.9 ; + p_.y = p.y + (double)(b.UR.y-b.LL.y)/2. - paras[i].lfsize; tmp = ROUND(p_.y); /* align with integer points */ p_.y = (double)tmp; } @@ -173,8 +173,7 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p, ti++; } /* position for next para */ - if(i != nparas-1) - p_.y -= paras[i+1].lfsize * LINESPACING; + p_.y -= paras[i].lfsize * 1.3; offset = 0.0; } @@ -692,7 +691,6 @@ size_html_txt(graph_t *g, htmltxt_t* ftxt, htmlenv_t* env) fname = env->finfo.name; } sz = textsize(g, &lp, fname, fsize); - w = sz.x; free (ftxt->paras[i].items[j].str); ftxt->paras[i].items[j].str = lp.str; ftxt->paras[i].items[j].size = sz.x; @@ -700,15 +698,13 @@ size_html_txt(graph_t *g, htmltxt_t* ftxt, htmlenv_t* env) ftxt->paras[i].items[j].postscript_alias = lp.postscript_alias; ftxt->paras[i].items[j].layout = lp.layout; ftxt->paras[i].items[j].free_layout = lp.free_layout; - width += w; + width += sz.x; ftxt->paras[i].size = (double) width; - if (fsize > lsize) - lsize = fsize; + lsize = MAX(fsize, lsize); } ftxt->paras[i].lfsize = lsize; - if (width > xsize) - xsize = width; - ysize += lsize * LINESPACING; + xsize = MAX(width, xsize); + ysize += sz.y; width = w = 0; lsize = 0; } diff --git a/lib/common/labels.c b/lib/common/labels.c index 0af682e47..375bb5e6c 100644 --- a/lib/common/labels.c +++ b/lib/common/labels.c @@ -31,11 +31,10 @@ static void storeline(graph_t *g, textlabel_t *lp, char *line, char terminator) 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) - lp->dimen.x = size.x; - /* recalculate total height */ - lp->dimen.y = lp->u.txt.nparas * (int) (lp->fontsize * LINESPACING); + /* width = max line width */ + lp->dimen.x = MAX(lp->dimen.x, size.x); + /* accumulate height */ + lp->dimen.y += size.y; } /* compiles into a label and returns its bounding box size. */ @@ -45,6 +44,7 @@ static pointf label_size(graph_t * g, textlabel_t * lp) unsigned char byte = 0x00; int charset = GD_charset(g); + lp->dimen.x = lp->dimen.y = 0.0; if (*str == '\0') return lp->dimen; @@ -166,30 +166,45 @@ void free_label(textlabel_t * p) } } -void -emit_textparas(GVJ_t* job, int nparas, textpara_t paras[], pointf p, - double halfwidth_x, char* fname, double fsize, char* fcolor) +void emit_label(GVJ_t * job, emit_state_t emit_state, textlabel_t * lp) { - int i, paraspacing, tmp; - double center_x, left_x, right_x; + obj_state_t *obj = job->obj; + double halfwidth_x, center_x, left_x, right_x; + int i, tmp; + pointf p; + emit_state_t old_emit_state; + + old_emit_state = obj->emit_state; + obj->emit_state = emit_state; + + if (lp->html) { + emit_html_label(job, lp->u.html, lp); + return; + } + + /* make sure that there is something to do */ + if (lp->u.txt.nparas < 1) + return; + + p.x = lp->p.x; + p.y = lp->p.y; + + /* dimensions of box for label, no padding, adjusted for resizing */ + halfwidth_x = (lp->dimen.x + lp->d.x) / 2.0; center_x = p.x; left_x = center_x - halfwidth_x; right_x = center_x + halfwidth_x; - /* set paraspacing to an exact no. of pixelrows */ - paraspacing = (int) (fsize * LINESPACING); - /* position for first para */ - p.y += paraspacing * (nparas - 1) / 2 /* cl of top para */ - - fsize * 0.30; /* Empirically determined fudge factor */ + p.y += lp->dimen.y / 2. - lp->fontsize; gvrender_begin_context(job); - gvrender_set_pencolor(job, fcolor); - gvrender_set_font(job, fname, fsize); + gvrender_set_pencolor(job, lp->fontcolor); + gvrender_set_font(job, lp->fontname, lp->fontsize); - for (i = 0; i < nparas; i++) { - switch (paras[i].just) { + for (i = 0; i < lp->u.txt.nparas; i++) { + switch (lp->u.txt.para[i].just) { case 'l': p.x = left_x; break; @@ -201,49 +216,18 @@ emit_textparas(GVJ_t* job, int nparas, textpara_t paras[], pointf p, p.x = center_x; break; } - tmp = ROUND(p.x); /* align with integer points */ p.x = (double)tmp; tmp = ROUND(p.y); /* align with integer points */ p.y = (double)tmp; - gvrender_textpara(job, p, &(paras[i])); + gvrender_textpara(job, p, &(lp->u.txt.para[i])); - /* position for next para */ - p.y -= paraspacing; + /* UL position for next para */ + p.y -= lp->u.txt.para[i].height; } gvrender_end_context(job); -} - -void emit_label(GVJ_t * job, emit_state_t emit_state, textlabel_t * lp) -{ - obj_state_t *obj = job->obj; - double halfwidth_x; - pointf p; - emit_state_t old_emit_state; - - old_emit_state = obj->emit_state; - obj->emit_state = emit_state; - - if (lp->html) { - emit_html_label(job, lp->u.html, lp); - return; - } - - /* make sure that there is something to do */ - if (lp->u.txt.nparas < 1) - return; - - p.x = lp->p.x; - p.y = lp->p.y; - - /* dimensions of box for label, no padding, adjusted for resizing */ - halfwidth_x = (lp->dimen.x + lp->d.x) / 2.0; - - emit_textparas(job, lp->u.txt.nparas, lp->u.txt.para, p, - halfwidth_x, lp->fontname, lp->fontsize, lp->fontcolor); - obj->emit_state = old_emit_state; } diff --git a/lib/common/render.h b/lib/common/render.h index 104443e23..4b61d246b 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -100,8 +100,6 @@ extern "C" { extern void emit_label(GVJ_t * job, emit_state_t emit_state, textlabel_t *); extern int emit_once(char *message); extern void emit_jobs_eof(GVC_t * gvc); - extern void emit_textparas(GVJ_t*, int, textpara_t*, pointf, - double, char*, double, char*); extern void enqueue_neighbors(nodequeue *, Agnode_t *, int); extern void endpath(path *, Agedge_t *, int, pathend_t *, bool); extern void epsf_init(node_t * n); diff --git a/plugin/gd/gvtextlayout_gd.c b/plugin/gd/gvtextlayout_gd.c index 93ecb228b..1f59b6424 100644 --- a/plugin/gd/gvtextlayout_gd.c +++ b/plugin/gd/gvtextlayout_gd.c @@ -89,7 +89,7 @@ static void gd_textlayout(GVCOMMON_t *common, textpara_t * para, char **fontpath if (para->str && para->str[0]) { /* can't use brect on some archtectures if strlen 0 */ para->width = (double) (brect[4] - brect[0]); - para->height = (double) (brect[1] - brect[5]); + para->height = para->fontsize * 1.3; } } }