From: John Ellson Date: Wed, 6 Nov 2013 01:46:50 +0000 (-0500) Subject: simplify textpara_t X-Git-Tag: 2.38.0~207 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4da83d786fce29a17305df50b53e87ccb377a4c4;p=graphviz simplify textpara_t --- diff --git a/lib/common/emit.c b/lib/common/emit.c index e4839ac8c..3789b8cf0 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -2882,25 +2882,24 @@ static boxf textBB (double x, double y, textpara_t* para) { boxf bb; - double wd = para->width; - double ht = para->height; + pointf sz = para->size; switch (para->just) { case 'l': bb.LL.x = x; - bb.UR.x = bb.LL.x + wd; + bb.UR.x = bb.LL.x + sz.x; break; case 'n': - bb.LL.x = x - wd/2.0; - bb.UR.x = x + wd/2.0; + bb.LL.x = x - sz.x / 2.0; + bb.UR.x = x + sz.x / 2.0; break; case 'r': bb.UR.x = x; - bb.LL.x = bb.UR.x - wd; + bb.LL.x = bb.UR.x - sz.x; break; } bb.UR.y = y + para->yoffset_layout; - bb.LL.y = bb.UR.y - ht; + bb.LL.y = bb.UR.y - sz.y; return bb; } diff --git a/lib/common/fontmetrics.c b/lib/common/fontmetrics.c index c37ebe1dc..8cb914f75 100644 --- a/lib/common/fontmetrics.c +++ b/lib/common/fontmetrics.c @@ -131,8 +131,8 @@ estimate_textlayout(textpara_t * para, char **fontpath) fontname = para->font->name; fontsize = para->font->size; - para->width = 0.0; - para->height = fontsize * LINESPACING; + para->size.x = 0.0; + para->size.y = fontsize * LINESPACING; para->yoffset_layout = 0.0; para->yoffset_centerline = 0.1 * fontsize; para->layout = NULL; @@ -153,8 +153,8 @@ estimate_textlayout(textpara_t * para, char **fontpath) *fontpath = fpp; if ((p = para->str)) { while ((c = *p++)) - para->width += Fontwidth[(unsigned char) c]; - para->width *= fontsize; + para->size.x += Fontwidth[(unsigned char) c]; + para->size.x *= fontsize; } } @@ -193,7 +193,6 @@ static PostscriptAlias* translate_postscript_fontname(char* fontname) pointf textsize(GVC_t *gvc, textpara_t * para, char *fontname, double fontsize) { char **fpp = NULL, *fontpath = NULL; - pointf size; htmlfont_t *font; font = NEW(htmlfont_t); @@ -219,7 +218,5 @@ pointf textsize(GVC_t *gvc, textpara_t * para, char *fontname, double fontsize) fprintf(stderr, "fontname: unable to resolve \"%s\"\n", fontname); } - size.x = para->width; - size.y = para->height; - return size; + return para->size; } diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index bf6f060f8..a80fb5ea6 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -174,13 +174,13 @@ emit_htextparas(GVJ_t * job, int nparas, htextpara_t * paras, pointf p, tl.yoffset_centerline = 1; tl.postscript_alias = ti->postscript_alias; tl.layout = ti->layout; - tl.width = ti->size; - tl.height = paras[i].lfsize; + tl.size.x = ti->size.x; + tl.size.y = paras[i].lfsize; tl.just = 'l'; p_.x = p.x; gvrender_textpara(job, p_, &tl); - p.x += ti->size; + p.x += ti->size.x; ti++; } } @@ -1058,7 +1058,7 @@ static int size_html_txt(graph_t * g, htmltxt_t * ftxt, htmlenv_t * env) sz = textsize(GD_gvc(g), &lp, fname, fsize); free(ftxt->paras[i].items[j].str); ftxt->paras[i].items[j].str = lp.str; - ftxt->paras[i].items[j].size = sz.x; + ftxt->paras[i].items[j].size.x = sz.x; ftxt->paras[i].items[j].yoffset_layout = lp.yoffset_layout; ftxt->paras[i].items[j].yoffset_centerline = lp.yoffset_centerline; ftxt->paras[i].items[j].postscript_alias = lp.postscript_alias; diff --git a/lib/common/labels.c b/lib/common/labels.c index 1f703b52c..d09d70461 100644 --- a/lib/common/labels.c +++ b/lib/common/labels.c @@ -32,7 +32,7 @@ static void storeline(GVC_t *gvc, textlabel_t *lp, char *line, char terminator) size = textsize(gvc, para, lp->fontname, lp->fontsize); else { size.x = 0.0; - para->height = size.y = (int)(lp->fontsize * LINESPACING); + para->size.y = size.y = (int)(lp->fontsize * LINESPACING); } lp->u.txt.nparas++; @@ -268,7 +268,7 @@ void emit_label(GVJ_t * job, emit_state_t emit_state, textlabel_t * lp) gvrender_textpara(job, p, &(lp->u.txt.para[i])); /* UL position for next para */ - p.y -= lp->u.txt.para[i].height; + p.y -= lp->u.txt.para[i].size.y; } gvrender_end_label(job); diff --git a/lib/common/textpara.h b/lib/common/textpara.h index 389f12012..e1c1150cf 100644 --- a/lib/common/textpara.h +++ b/lib/common/textpara.h @@ -57,8 +57,8 @@ extern "C" { void *layout; void (*free_layout) (void *layout); /* FIXME - this is ugly */ htmlfont_t *font; - double size, yoffset_layout, yoffset_centerline; - double width, height; /* FIXME */ + double yoffset_layout, yoffset_centerline; + pointf size; char just; /* 'l' 'n' 'r' */ /* FIXME */ } textpara_t; diff --git a/plugin/core/gvrender_core_dia.c b/plugin/core/gvrender_core_dia.c index 1702b3ef6..5adf915dd 100644 --- a/plugin/core/gvrender_core_dia.c +++ b/plugin/core/gvrender_core_dia.c @@ -543,8 +543,8 @@ static void dia_textpara(GVJ_t * job, pointf p, textpara_t * para) #if 0 gvputs(job, " \n"); gvprintf(job, " \n", - p.x - (Scale * (para->width) / 2.), p.y - 0.4, - p.x + (Scale * (para->width) / 2.), p.y + 0.4); + p.x - (Scale * (para->size.x) / 2.), p.y - 0.4, + p.x + (Scale * (para->size.x) / 2.), p.y + 0.4); gvputs(job, " \n"); #endif gvputs(job, " \n"); diff --git a/plugin/core/gvrender_core_dot.c b/plugin/core/gvrender_core_dot.c index b00c9aead..d46cdb596 100644 --- a/plugin/core/gvrender_core_dot.c +++ b/plugin/core/gvrender_core_dot.c @@ -579,7 +579,7 @@ static void xdot_textpara(GVJ_t * job, pointf p, textpara_t * para) xdot_point(xbufs[emit_state], p); sprintf(buf, "%d ", j); agxbput(xbufs[emit_state], buf); - xdot_fmt_num (buf, para->width); + xdot_fmt_num (buf, para->size.x); agxbput(xbufs[emit_state], buf); xdot_str (job, "", para->str); } diff --git a/plugin/core/gvrender_core_pic.c b/plugin/core/gvrender_core_pic.c index 28939fdf1..16c613ee1 100644 --- a/plugin/core/gvrender_core_pic.c +++ b/plugin/core/gvrender_core_pic.c @@ -435,16 +435,16 @@ static void pic_textpara(GVJ_t * job, pointf p, textpara_t * para) case 'l': break; case 'r': - p.x -= para->width; + p.x -= para->size.x; break; default: case 'n': - p.x -= para->width / 2; + p.x -= para->size.x / 2; break; } /* Why on earth would we do this. But it works. SCN 2/26/2002 */ p.y += para->font->size / (3.0 * POINTS_PER_INCH); - p.x += para->width / (2.0 * POINTS_PER_INCH); + p.x += para->size.x / (2.0 * POINTS_PER_INCH); if (para->font->name && (!(lastname) || strcmp(lastname, para->font->name))) { gvprintf(job, ".ft %s\n", picfontname(para->font->name)); diff --git a/plugin/core/gvrender_core_pov.c b/plugin/core/gvrender_core_pov.c index f0544f77c..85fa9cd32 100644 --- a/plugin/core/gvrender_core_pov.c +++ b/plugin/core/gvrender_core_pov.c @@ -601,11 +601,11 @@ static void pov_textpara(GVJ_t * job, pointf c, textpara_t * para) case 'l': //left justified break; case 'r': //right justified - c.x = c.x - para->width; + c.x = c.x - para->size.x; break; default: case 'n': //centered - c.x = c.x - para->width / 2.0; + c.x = c.x - para->size.x / 2.0; break; } diff --git a/plugin/core/gvrender_core_ps.c b/plugin/core/gvrender_core_ps.c index 521533aef..9bd95e6e4 100644 --- a/plugin/core/gvrender_core_ps.c +++ b/plugin/core/gvrender_core_ps.c @@ -284,20 +284,20 @@ static void psgen_textpara(GVJ_t * job, pointf p, textpara_t * para) str = ps_string(para->str,isLatin1); switch (para->just) { case 'r': - p.x -= para->width; + p.x -= para->size.x; break; case 'l': p.x -= 0.0; break; case 'n': default: - p.x -= para->width / 2.0; + p.x -= para->size.x / 2.0; break; } p.y += para->yoffset_centerline; gvprintpointf(job, p); gvputs(job, " moveto "); - gvprintdouble(job, para->width); + gvprintdouble(job, para->size.x); gvprintf(job, " %s alignedtext\n", str); } diff --git a/plugin/core/gvrender_core_vml.c b/plugin/core/gvrender_core_vml.c index bd42cdf5e..de5843673 100644 --- a/plugin/core/gvrender_core_vml.c +++ b/plugin/core/gvrender_core_vml.c @@ -378,22 +378,22 @@ static void vml_textpara(GVJ_t * job, pointf p, textpara_t * para) p1.x=p.x; break; case 'r': - p1.x=p.x-para->width; + p1.x=p.x-para->size.x; break; default: case 'n': - p1.x=p.x-(para->width/2); + p1.x=p.x-(para->size.x/2); break; } - p2.x=p1.x+para->width; - if (para->height < para->font->size){ - para->height = 1 + (1.1*para->font->size); + p2.x=p1.x+para->size.x; + if (para->size.y < para->font->size){ + para->size.y = 1 + (1.1*para->font->size); } p1.x-=8; /* vml textbox margin fudge factor */ p2.x+=8; /* vml textbox margin fudge factor */ p2.y=graphHeight-(p.y); - p1.y=(p2.y-para->height); + p1.y=(p2.y-para->size.y); /* text "y" was too high * Graphviz uses "baseline", VML seems to use bottom of descenders - so we fudge a little * (heuristics - based on eyeballs) */ diff --git a/plugin/gd/gvrender_gd.c b/plugin/gd/gvrender_gd.c index f0d00024a..2f62c0402 100644 --- a/plugin/gd/gvrender_gd.c +++ b/plugin/gd/gvrender_gd.c @@ -366,7 +366,7 @@ static void gdgen_textpara(GVJ_t * job, pointf p, textpara_t * para) { gdImagePtr im = (gdImagePtr) job->context; pointf spf, epf; - double parawidth = para->width * job->zoom * job->dpi.x / POINTS_PER_INCH; + double parawidth = para->size.x * job->zoom * job->dpi.x / POINTS_PER_INCH; char* fontname; if (!im) diff --git a/plugin/gd/gvrender_gd_vrml.c b/plugin/gd/gvrender_gd_vrml.c index 8ee098043..6f6cf5961 100644 --- a/plugin/gd/gvrender_gd_vrml.c +++ b/plugin/gd/gvrender_gd_vrml.c @@ -342,14 +342,14 @@ static void vrml_textpara(GVJ_t *job, pointf p, textpara_t * para) case 'l': break; case 'r': - p.x -= para->width; + p.x -= para->size.x; break; default: case 'n': - p.x -= para->width / 2; + p.x -= para->size.x / 2; break; } - q.x = p.x + para->width; + q.x = p.x + para->size.x; q.y = p.y; spf = vrml_node_point(job, obj->u.n, p); diff --git a/plugin/gd/gvtextlayout_gd.c b/plugin/gd/gvtextlayout_gd.c index f63c87a37..74c866552 100644 --- a/plugin/gd/gvtextlayout_gd.c +++ b/plugin/gd/gvtextlayout_gd.c @@ -138,8 +138,8 @@ static boolean gd_textlayout(textpara_t * para, char **fontpath) else strex.flags |= gdFTEX_FONTCONFIG; - para->width = 0.0; - para->height = 0.0; + para->size.x = 0.0; + para->size.y = 0.0; para->yoffset_layout = 0.0; para->layout = NULL; @@ -181,11 +181,11 @@ static boolean gd_textlayout(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->size.x = (double) (brect[4] - brect[0]); /* 1.2 specifies how much extra space to leave between lines; * see LINESPACING in const.h. */ - para->height = (int)(fontsize * 1.2); + para->size.y = (int)(fontsize * 1.2); } } return TRUE; diff --git a/plugin/lasi/gvrender_lasi.cpp b/plugin/lasi/gvrender_lasi.cpp index 68668f0ac..0ddffc11d 100644 --- a/plugin/lasi/gvrender_lasi.cpp +++ b/plugin/lasi/gvrender_lasi.cpp @@ -400,20 +400,20 @@ static void lasi_textpara(GVJ_t * job, pointf p, textpara_t * para) doc->osBody() << setFont(font, style, weight, variant, stretch) << setFontSize(para->font->size) << endl; switch (para->just) { case 'r': - p.x -= para->width; + p.x -= para->size.x; break; case 'l': p.x -= 0.0; break; case 'n': default: - p.x -= para->width / 2.0; + p.x -= para->size.x / 2.0; break; } p.y += para->yoffset_centerline; gvprintpointf(job, p); gvputs(job, " moveto "); -// gvprintdouble(job, para->width); +// gvprintdouble(job, para->size.x); // str = ps_string(para->str,isLatin1); // gvprintf(job, " %s alignedtext\n", str); doc->osBody() << show(para->str) << endl; diff --git a/plugin/pango/gvrender_pango.c b/plugin/pango/gvrender_pango.c index 174d1ef7a..164ecd712 100644 --- a/plugin/pango/gvrender_pango.c +++ b/plugin/pango/gvrender_pango.c @@ -229,14 +229,14 @@ static void cairogen_textpara(GVJ_t * job, pointf p, textpara_t * para) switch (para->just) { case 'r': - p.x -= para->width; + p.x -= para->size.x; break; case 'l': p.x -= 0.0; break; case 'n': default: - p.x -= para->width / 2.0; + p.x -= para->size.x / 2.0; break; } p.y += para->yoffset_centerline + para->yoffset_layout; diff --git a/plugin/pango/gvtextlayout_pango.c b/plugin/pango/gvtextlayout_pango.c index b69563b03..1ee293633 100644 --- a/plugin/pango/gvtextlayout_pango.c +++ b/plugin/pango/gvtextlayout_pango.c @@ -240,8 +240,8 @@ static boolean pango_textlayout(textpara_t * para, char **fontpath) logical_rect.height = 0; textlayout_scale = POINTS_PER_INCH / (FONT_DPI * PANGO_SCALE); - para->width = (int)(logical_rect.width * textlayout_scale + 1); /* round up so that width/height are never too small */ - para->height = (int)(logical_rect.height * textlayout_scale + 1); + para->size.x = (int)(logical_rect.width * textlayout_scale + 1); /* round up so that width/height are never too small */ + para->size.y = (int)(logical_rect.height * textlayout_scale + 1); /* FIXME -- Horrible kluge !!! */ @@ -250,7 +250,7 @@ static boolean pango_textlayout(textpara_t * para, char **fontpath) * Use an assumed height based on the point size. */ - para->height = (int)(para->font->size * 1.1 + .5); + para->size.y = (int)(para->font->size * 1.1 + .5); /* The y offset from baseline to 0,0 of the bitmap representation */ #if defined PANGO_VERSION_MAJOR && (PANGO_VERSION_MAJOR >= 1)