]> granicus.if.org Git - graphviz/commitdiff
use textpara height from text_layout instead of basing it on fontsize
authorellson <devnull@localhost>
Thu, 17 Aug 2006 18:08:33 +0000 (18:08 +0000)
committerellson <devnull@localhost>
Thu, 17 Aug 2006 18:08:33 +0000 (18:08 +0000)
lib/common/const.h
lib/common/fontmetrics.c
lib/common/htmltable.c
lib/common/labels.c
lib/common/render.h
plugin/gd/gvtextlayout_gd.c

index 019e6800cd91ee8c2e24d413e3139be91d97a032..754d596b98dbfd05d9e5570f85d4b768821c2017 100644 (file)
@@ -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
index e6115b7464c9b5857343310fe44869e02ba3eb09..921958736a460f4dd37e129588d4aff60d62138b 100644 (file)
@@ -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;
index 3a0db576ac9fe2b40ba34ff4865251392752baec..9e620929de11ac3959b2c564c60598dd2350d32b 100644 (file)
@@ -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;
     }
index 0af682e475dce19c621840cea17c432455e57773..375bb5e6ca13da9cfbf0c807f75ae04858ddd43d 100644 (file)
@@ -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 <str> into a label <lp> 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;
 }
 
index 104443e2320c6880365220238bc981ee73fd9b02..4b61d246bf9b66345e9d20db8c40ca776693df75 100644 (file)
@@ -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);
index 93ecb228b769c39cd6b5b6cf5e4fee710e6a1011..1f59b642423ff664390728487f5162400f28b832 100644 (file)
@@ -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;
        }
     }
 }