]> granicus.if.org Git - graphviz/commitdiff
completely segregate yoffset terms
authorellson <devnull@localhost>
Thu, 25 Oct 2007 17:38:12 +0000 (17:38 +0000)
committerellson <devnull@localhost>
Thu, 25 Oct 2007 17:38:12 +0000 (17:38 +0000)
lib/common/fontmetrics.c
lib/common/htmltable.c
lib/common/htmltable.h
lib/common/textpara.h
plugin/core/gvrender_core_ps.c
plugin/core/gvrender_core_svg.c
plugin/gd/gvrender_gd.c
plugin/gd/gvtextlayout_gd.c
plugin/pango/gvrender_pango.c
plugin/pango/gvtextlayout_pango.c

index 2c22e24ecd03c8712395a99a7705f0550e94cde8..981b4eb936ff286f6215e7246ab477851cc33232 100644 (file)
@@ -137,7 +137,8 @@ estimate_textlayout(graph_t *g, textpara_t * para, char **fontpath)
 
     para->width = 0.0;
     para->height = para->fontsize * LINESPACING;
-    para->yoffset = 0.0;
+    para->yoffset_layout = 0.0;
+    para->yoffset_centerline = 0.1 * para->fontsize;
     para->xshow = NULL;
     para->layout = para->fontname;
     para->free_layout = NULL;
index aa30e3b3fbf11cf66477d26a7df3420e9341c919..eb5330269cb213254a7d1f39361a9fb986d4a775 100644 (file)
@@ -173,7 +173,8 @@ emit_htextparas(GVJ_t* job, int nparas, htextpara_t* paras, pointf p,
            tl.fontname = fname_;
            tl.fontsize = fsize_;
            tl.xshow = ti->xshow;
-           tl.yoffset = ti->yoffset;
+           tl.yoffset_layout = ti->yoffset_layout;
+           tl.yoffset_centerline = ti->yoffset_centerline;
            tl.postscript_alias = ti->postscript_alias;
            tl.layout = ti->layout;
            tl.width = paras[i].size;
@@ -806,7 +807,8 @@ size_html_txt(graph_t *g, htmltxt_t* ftxt, htmlenv_t* env)
            ftxt->paras[i].items[j].str = lp.str;
            ftxt->paras[i].items[j].size = sz.x;
            ftxt->paras[i].items[j].xshow = lp.xshow;
-           ftxt->paras[i].items[j].yoffset = lp.yoffset;
+           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;
            ftxt->paras[i].items[j].layout = lp.layout;
            ftxt->paras[i].items[j].free_layout = lp.free_layout;
index a8dfdc19f3f8197b3f1b9ed130931fa4408c8a6b..3a4f3dc52bbc7cab8bc3ff720cffa71fee8e6a76 100644 (file)
@@ -69,7 +69,7 @@ extern "C" {
        void *layout;
        void (*free_layout) (void *layout);
        htmlfont_t *font;
-       double size, dpi, yoffset;  /* size of text item according to font */
+       double size, yoffset_layout, yoffset_centerline;
     } textitem_t;
        
     typedef struct {
index 1b38480fe0fdd05493cbf4df401aaf75c5e698a8..c7a4080371b04bc38c150964ce8a641e36e7f12a 100644 (file)
@@ -40,7 +40,7 @@ extern "C" {
        char *xshow;
        void *layout;
        void (*free_layout) (void *layout);   /* FIXME - this is ugly */
-       double fontsize, width, height, yoffset;
+       double fontsize, width, height, yoffset_layout, yoffset_centerline;
        char just;
     } textpara_t;
 
index e68a02f34a53710d96a465f7de4b412fb8c3b9c2..1fdc8f478f4fd3b8c43dc519f5974d27588d86ea 100644 (file)
@@ -271,8 +271,7 @@ static void psgen_textpara(GVJ_t * job, pointf p, textpara_t * para)
     ps_set_color(job, &(job->obj->pencolor));
     gvdevice_printf(job, "%.2f /%s set_font\n", para->fontsize, para->fontname);
     str = ps_string(para->str,isLatin1);
-    /* don't use para->yoffset because we don't need the baseline offset */
-    p.y += .1 * para->fontsize;
+    p.y += para->yoffset_centerline;
     if (para->xshow) {
         switch (para->just) {
         case 'l':
index 4499714672a94d280ca4f2beaa9435b752917db5..2bf4bf7d05c889149c5210b8c70155226788c26d 100644 (file)
@@ -291,8 +291,7 @@ static void svg_textpara(GVJ_t * job, pointf p, textpara_t * para)
        gvdevice_fputs(job, " text-anchor=\"middle\"");
        break;
     }
-    /* don't use para->yoffset because we don't need the baseline offset */
-    p.y += .1 * para->fontsize;
+    p.y += para->yoffset_centerline;
     gvdevice_printf(job, " x=\"%g\" y=\"%g\"", p.x, -p.y);
     gvdevice_fputs(job, " style=\"");
     pA = para->postscript_alias;
index 66f48e30015d05fa186bf2790d0f01de62070074..7b7fc7bae20b5f59129b0677a3a2a0ba65e85718 100644 (file)
@@ -364,7 +364,7 @@ static void gdgen_textpara(GVJ_t * job, pointf p, textpara_t * para)
     else {
        spf.x += p.x;
        epf.x += p.x;
-       epf.y = spf.y = p.y;
+       epf.y = spf.y = p.y - para->yoffset_centerline * job->scale.y;
     }
 
     gdgen_text(im, spf, epf,
index 53aeaada777d2c3c7eb7d18d66d371bea2add8ef..99c06749d367d9abf2b4a129a0f196641ae35564 100644 (file)
@@ -117,13 +117,14 @@ static boolean gd_textlayout(textpara_t * para, char **fontpath)
 
     para->width = 0.0;
     para->height = 0.0;
-    para->yoffset = 0.0;
+    para->yoffset_layout = 0.0;
     para->xshow = NULL;
 
     para->layout = NULL;
     para->free_layout = NULL;
 
     fontsize = para->fontsize;
+    para->yoffset_centerline = 0.1 * fontsize;
 
     if (para->fontname) {
        if (fontsize <= FONTSIZE_MUCH_TOO_SMALL) {
@@ -164,7 +165,6 @@ static boolean gd_textlayout(textpara_t * para, char **fontpath)
              * see LINESPACING in const.h.
              */
            para->height = (int)(para->fontsize * 1.2);
-            para->yoffset = 0.0;
        }
     }
     return TRUE;
index 61da1d30dda2dc633f0142de1117c88043546632..3f1e1f6d852cebbb1c4a8e1b9296580d14f1bc2e 100644 (file)
@@ -221,26 +221,25 @@ static void cairogen_textpara(GVJ_t * job, pointf p, textpara_t * para)
 {
     obj_state_t *obj = job->obj;
     cairo_t *cr = (cairo_t *) job->context;
-    pointf offset;
 
     cairo_set_dash (cr, dashed, 0, 0.0);  /* clear any dashing */
     cairogen_set_color(cr, &(obj->pencolor));
 
     switch (para->just) {
     case 'r':
-       offset.x = para->width;
+       p.x -= para->width;
        break;
     case 'l':
-       offset.x = 0.0;
+       p.x -= 0.0;
        break;
     case 'n':
     default:
-       offset.x = para->width / 2.0;
+       p.x -= para->width / 2.0;
        break;
     }
-    offset.y = para->yoffset;
+    p.y += para->yoffset_centerline + para->yoffset_layout;
 
-    cairo_move_to (cr, p.x-offset.x, -p.y-offset.y);
+    cairo_move_to (cr, p.x, -p.y);
     cairo_save(cr);
     cairo_scale(cr, POINTS_PER_INCH / FONT_DPI, POINTS_PER_INCH / FONT_DPI);
     pango_cairo_show_layout(cr, (PangoLayout*)(para->layout));
index a0af42d4392f0fab583cdffdc8c07b89fce06db0..4eae3e32797c43b637d88ba92946e116ef8603cd 100644 (file)
@@ -161,10 +161,12 @@ static boolean pango_textlayout(textpara_t * para, char **fontpath)
     para->width = logical_rect.width * textlayout_scale;
     para->height = logical_rect.height * textlayout_scale;
 
+    /* The y offset from baseline to 0,0 of the bitmap representation */
     iter = pango_layout_get_iter (layout);
-    para->yoffset = pango_layout_iter_get_baseline (iter) * textlayout_scale
-       +.1 * para->fontsize;  /* In labels.c y is already midline 
-                        * 0.1 is the distance below midline for y centering */
+    para->yoffset_layout = pango_layout_iter_get_baseline (iter) * textlayout_scale;
+
+    /* The distance below midline for y centering of text strings */
+    para->yoffset_centerline = 0.1 * para->fontsize;
 
     /* determine position of each character in the layout */
     para->xshow = NULL;