From a724a5af59a34333f5fa13d864b04a662e76fabb Mon Sep 17 00:00:00 2001 From: John Ellson Date: Wed, 6 Nov 2013 10:30:12 -0500 Subject: [PATCH] extract font creation from textsize() (no textspan_size() ) --- lib/common/emit.c | 9 ++++++++- lib/common/fontmetrics.c | 24 ++++++++++-------------- lib/common/htmltable.c | 4 +++- lib/common/labels.c | 13 +++++++++++-- lib/common/render.h | 2 +- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/lib/common/emit.c b/lib/common/emit.c index fbad83369..97f5a596d 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -2958,7 +2958,14 @@ boxf xdotBB (Agraph_t* g) op->span = NEW(textspan_t); op->span->str = strdup (op->op.u.text.text); op->span->just = adjust [op->op.u.text.align]; - sz = textsize (GD_gvc(g), op->span, fontname, fontsize); +/* FIXME - use mkFont() */ + op->span->font = NEW(htmlfont_t); + op->span->font->name=fontname; + op->span->font->size=fontsize; + op->span->font->flags=0; + op->span->font->cnt=1; +/**/ + sz = textspan_size (GD_gvc(g), op->span); bb0 = textBB (op->op.u.text.x, op->op.u.text.y, op->span); op->bb = bb0; expandBB (&bb, bb0.LL); diff --git a/lib/common/fontmetrics.c b/lib/common/fontmetrics.c index 99a24187a..5e5da52be 100644 --- a/lib/common/fontmetrics.c +++ b/lib/common/fontmetrics.c @@ -116,11 +116,11 @@ static double courFontWidth[] = { 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, 0.5999, /* øùúû */ }; -/* estimate_textsize: +/* estimate_textspan_size: * Estimate size of textspan, for given face and size, in points. */ static void -estimate_textlayout(textspan_t * span, char **fontpath) +estimate_textspan_size(textspan_t * span, char **fontpath) { double *Fontwidth, fontsize; char c, *p, *fpp, *fontname; @@ -190,32 +190,28 @@ static PostscriptAlias* translate_postscript_fontname(char* fontname) return result; } -pointf textsize(GVC_t *gvc, textspan_t * span, char *fontname, double fontsize) +pointf textspan_size(GVC_t *gvc, textspan_t * span) { char **fpp = NULL, *fontpath = NULL; htmlfont_t *font; - font = NEW(htmlfont_t); - font->name = strdup(fontname); - font->size = fontsize; - font->color = NULL; - font->flags = 0; + assert(span->font); - span->font = font; - span->postscript_alias = translate_postscript_fontname(fontname); + font = span->font; + span->postscript_alias = translate_postscript_fontname(font->name); - if (Verbose && emit_once(fontname)) + if (Verbose && emit_once(font->name)) fpp = &fontpath; if (! gvtextlayout(gvc, span, fpp)) - estimate_textlayout(span, fpp); + estimate_textspan_size(span, fpp); if (fpp) { if (fontpath) fprintf(stderr, "fontname: \"%s\" resolved to: %s\n", - fontname, fontpath); + font->name, fontpath); else - fprintf(stderr, "fontname: unable to resolve \"%s\"\n", fontname); + fprintf(stderr, "fontname: unable to resolve \"%s\"\n", font->name); } return span->size; diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index 8c4366d96..38f468644 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -1055,7 +1055,9 @@ static int size_html_txt(graph_t * g, htmltxt_t * ftxt, htmlenv_t * env) fname = env->finfo.name; lp.font->flags = 0; } - sz = textsize(GD_gvc(g), &lp, fname, fsize); + lp.font->name = fname; + lp.font->size = fsize; + sz = textspan_size(GD_gvc(g), &lp); free(ftxt->spans[i].items[j].str); ftxt->spans[i].items[j].str = lp.str; ftxt->spans[i].items[j].size.x = sz.x; diff --git a/lib/common/labels.c b/lib/common/labels.c index 144864819..1d21dc821 100644 --- a/lib/common/labels.c +++ b/lib/common/labels.c @@ -28,8 +28,17 @@ static void storeline(GVC_t *gvc, textlabel_t *lp, char *line, char terminator) span = &(lp->u.txt.span[lp->u.txt.nspans]); span->str = line; span->just = terminator; - if (line && line[0]) - size = textsize(gvc, span, lp->fontname, lp->fontsize); + if (line && line[0]) { +/* FIXME -- use mkFont() */ + span->font = NEW(htmlfont_t); + span->font->name = strdup(lp->fontname); + span->font->size = lp->fontsize; + span->font->color = NULL; + span->font->flags = 0; + span->font->cnt = 1; +/* */ + size = textspan_size(gvc, span); + } else { size.x = 0.0; span->size.y = size.y = (int)(lp->fontsize * LINESPACING); diff --git a/lib/common/render.h b/lib/common/render.h index 9405c715d..1d1ba17b2 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -157,7 +157,7 @@ extern "C" { extern int stripedBox (GVJ_t * job, pointf* AF, char* clrs, int rotate); extern stroke_t* taper (bezier*, double (*radfunc_t)(double,double,double), double initwid, int linejoin, int linecap); extern stroke_t* taper0 (bezier* bez, double initwid); - extern pointf textsize(GVC_t * gvc, textspan_t * span, char *fontname, double fontsize); + extern pointf textspan_size(GVC_t * gvc, textspan_t * span); extern void translate_bb(Agraph_t *, int); extern int wedgedEllipse (GVJ_t* job, pointf * pf, char* clrs); extern void update_bb_bz(boxf *bb, pointf *cp); -- 2.40.0