From: erg Date: Mon, 4 Dec 2006 19:20:04 +0000 (+0000) Subject: Fix bugs introduced when moving code from common to the plugin architecture. X-Git-Tag: LAST_LIBGRAPH~32^2~5804 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b5e5e55d515c982a3f39dfe80827b27354f555b;p=graphviz Fix bugs introduced when moving code from common to the plugin architecture. - Make sure storeline adds height for empty lines. This is handled explicitly in storeline. Alternatively, we could have textsize always return the appropriate height, even for empty strings. - The changed html code was using the wrong offset to get the next baseline, and was using the last font rather than the largest font to calculate a line's height. - Reintroduce constant LINESPACING rather than having a concrete number spread various places in the code. --- diff --git a/lib/common/const.h b/lib/common/const.h index 754d596b9..95cb2e57e 100644 --- a/lib/common/const.h +++ b/lib/common/const.h @@ -69,6 +69,7 @@ #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 @@ -207,6 +208,14 @@ #define AUXLABELS (1 << 3) #define INVISIBLE (1 << 4) +/* edge types */ +#define ET_NONE (0 << 1) +#define ET_LINE (1 << 1) +#define ET_PLINE (2 << 1) +#define ET_ORTHO (3 << 1) +#define ET_SPLINE (4 << 1) +#define ET_COMPOUND (5 << 1) + /* user-specified node position: ND_pinned */ #define P_SET 1 /* position supplied by user */ #define P_FIX 2 /* position fixed during topological layout */ diff --git a/lib/common/fontmetrics.c b/lib/common/fontmetrics.c index 921958736..7f86cd983 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 * 1.3; + para->height = para->fontsize * LINESPACING; para->xshow = NULL; para->layout = para->fontname; para->free_layout = NULL; diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index 9093c1a60..bf9ecbdc9 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -105,7 +105,7 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p, { int i,j; double tmp, center_x, left_x, right_x, fsize_; - double offset=0.0; + double offset; char *fname_ , *fcolor_; textpara_t tl; pointf p_ = {0.0, 0.0}; @@ -115,6 +115,13 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p, left_x = center_x - halfwidth_x; right_x = center_x + halfwidth_x; + /* Initial p is in center of text block; set initial baseline + * to top of text block. + */ + p_.y = p.y + (double)(b.UR.y-b.LL.y)/2.0; + tmp = ROUND(p_.y); /* align with integer points */ + p_.y = (double)tmp; + gvrender_begin_context(job); for(i=0; ifont && (ti->font->size > 0)) fsize_ = ti->font->size; @@ -172,9 +175,6 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p, p_.x = p.x + offset; ti++; } - /* position for next para */ - p_.y -= paras[i].lfsize * 1.3; - offset = 0.0; } gvrender_end_context(job); @@ -636,14 +636,20 @@ int html_path(node_t * n, port* p, int side, box * rv, int *k) static int size_html_txt(graph_t *g, htmltxt_t* ftxt, htmlenv_t* env) { - double xsize = 0.0, ysize = 0.0; - double fsize, lsize = 0.0; + double xsize = 0.0; /* width of text block */ + double ysize = 0.0; /* height of text block */ + double fsize; + double lsize; /* height of current line */ + double mxfsize; /* max. font size for the current line */ + double curbline = 0; /* dist. of current base line from top */ pointf sz; - int i, j, w = 0, width = 0; + int i, j, w, width; char *fname; textpara_t lp; for (i = 0; i < ftxt->nparas; i++) { + width = w = 0; + mxfsize = 0; for (j = 0; j < ftxt->paras[i].nitems; j++) { lp.str = strdup_and_subst_obj (ftxt->paras[i].items[j].str, env->obj); if (ftxt->paras[i].items[j].font) { @@ -668,17 +674,26 @@ size_html_txt(graph_t *g, htmltxt_t* ftxt, htmlenv_t* env) ftxt->paras[i].items[j].layout = lp.layout; ftxt->paras[i].items[j].free_layout = lp.free_layout; width += sz.x; - ftxt->paras[i].size = (double) width; - lsize = MAX(fsize, lsize); + mxfsize = MAX(fsize, mxfsize); } - ftxt->paras[i].lfsize = lsize; + lsize = mxfsize * LINESPACING; + ftxt->paras[i].size = (double) width; + /* ysize - curbline is the distance from the previous + * baseline to the bottom of the previous line. + * Then, in the current line, we set the baseline to + * be 5/6 of the max. font size. Thus, lfsize gives the + * distance from the previous baseline to the new one. + */ + ftxt->paras[i].lfsize = 5*mxfsize/6 + ysize - curbline; + curbline += ftxt->paras[i].lfsize; xsize = MAX(width, xsize); - ysize += sz.y; - width = w = 0; - lsize = 0; + ysize += lsize; } ftxt->box.UR.x = xsize; - ftxt->box.UR.y = (int) (ysize); + if (ftxt->nparas == 1) + ftxt->box.UR.y = (int) (mxfsize); + else + ftxt->box.UR.y = (int) (ysize); return 0; } diff --git a/lib/common/htmltable.h b/lib/common/htmltable.h index 476599beb..2d0684fb5 100644 --- a/lib/common/htmltable.h +++ b/lib/common/htmltable.h @@ -76,8 +76,8 @@ extern "C" { textitem_t *items; short nitems; char just; - double size; /* size of para */ - double lfsize; /* size of largest font in para */ + double size; /* width of para */ + double lfsize; /* offset from previous baseline to current one */ } htextpara_t; typedef struct { diff --git a/lib/common/labels.c b/lib/common/labels.c index 10af571eb..aad6e2e45 100644 --- a/lib/common/labels.c +++ b/lib/common/labels.c @@ -21,7 +21,7 @@ static void storeline(graph_t *g, textlabel_t *lp, char *line, char terminator) { - pointf size = {0.,0.}; + pointf size; textpara_t *para; lp->u.txt.para = @@ -31,6 +31,11 @@ static void storeline(graph_t *g, textlabel_t *lp, char *line, char terminator) para->just = terminator; if (line && line[0]) size = textsize(g, para, lp->fontname, lp->fontsize); + else { + size.x = 0.0; + para->height = size.y = (int)(lp->fontsize * LINESPACING); + } + lp->u.txt.nparas++; /* width = max line width */ lp->dimen.x = MAX(lp->dimen.x, size.x); diff --git a/lib/common/macros.h b/lib/common/macros.h index e1cae9eb8..b15f6c144 100644 --- a/lib/common/macros.h +++ b/lib/common/macros.h @@ -25,6 +25,7 @@ #define IS_CLUST_NODE(n) (ND_clustnode(n)) #define HAS_CLUST_EDGE(g) (GD_flags(g) & 1) #define SET_CLUST_EDGE(g) (GD_flags(g) |= 1) +#define EDGE_TYPE(g) (GD_flags(g) & (7 << 1)) #define SET_RANKDIR(g,rd) ((g)->u.rankdir = (rd)) diff --git a/plugin/gd/gvtextlayout_gd.c b/plugin/gd/gvtextlayout_gd.c index a614758af..8d1fe4aac 100644 --- a/plugin/gd/gvtextlayout_gd.c +++ b/plugin/gd/gvtextlayout_gd.c @@ -160,7 +160,10 @@ 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 = para->fontsize * 1.3; + /* 1.2 specifies how much extra space to leave between lines; + * see LINESPACING in const.h. + */ + para->height = (int)(para->fontsize * 1.2); } } }