]> granicus.if.org Git - graphviz/commitdiff
Fix bugs introduced when moving code from common to the plugin architecture.
authorerg <devnull@localhost>
Mon, 4 Dec 2006 19:20:04 +0000 (19:20 +0000)
committererg <devnull@localhost>
Mon, 4 Dec 2006 19:20:04 +0000 (19:20 +0000)
 - 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.

lib/common/const.h
lib/common/fontmetrics.c
lib/common/htmltable.c
lib/common/htmltable.h
lib/common/labels.c
lib/common/macros.h
plugin/gd/gvtextlayout_gd.c

index 754d596b98dbfd05d9e5570f85d4b768821c2017..95cb2e57e4e811f05cab59da8fd768f789d2ff4d 100644 (file)
@@ -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
 #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 */
index 921958736a460f4dd37e129588d4aff60d62138b..7f86cd983d6c09dec1c0bc9bfbf6ba70adc02eab 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 * 1.3;
+    para->height = para->fontsize * LINESPACING;
     para->xshow = NULL;
     para->layout = para->fontname;
     para->free_layout = NULL;
index 9093c1a60d339a1851e6dd75ccdbe91de0449268..bf9ecbdc917c27df80fe2242cb296c896272eb81 100644 (file)
@@ -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; i<nparas; i++) {
        switch (paras[i].just) {
@@ -132,14 +139,10 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p,
            p.x = center_x;
            break;
        }
-
-       if (i == 0) {
-           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;
-       }
+       p_.y -= paras[i].lfsize;  /* move to current base line */
 
        ti = paras[i].items;
+       offset = 0.0;
        for(j=0; j<paras[i].nitems; j++) {
            if (ti->font && (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;
 }
 
index 476599beb17ba2cf54ca9dde58e3537c047a853e..2d0684fb5edac485b28f07eccc352e6908d21034 100644 (file)
@@ -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 {
index 10af571eba554a7bc0389de07b878023cfd47c94..aad6e2e4552a3b3b1b1a21a1182b90f42eaef8b5 100644 (file)
@@ -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);
index e1cae9eb8d58bbe1639d7fe82d1127e21ea9863b..b15f6c144167e1b6187ae0db5521d389039a2980 100644 (file)
@@ -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))
 
index a614758af38e3dce0e64976edd13eb0ca0122ba8..8d1fe4aace988f2aec472dc95e35305fbc3ffa59 100644 (file)
@@ -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);
        }
     }
 }