]> granicus.if.org Git - graphviz/commitdiff
fix the assymetries in usershape images
authorellson <devnull@localhost>
Fri, 9 Jun 2006 19:22:19 +0000 (19:22 +0000)
committerellson <devnull@localhost>
Fri, 9 Jun 2006 19:22:19 +0000 (19:22 +0000)
lib/common/psgen.c
lib/gvc/gvrender.c

index f9381d4e76f778f7df310fcd9f2ab7d902873133..8ace600b7fd85a2c46e739c1597927dd47b81f95 100644 (file)
@@ -491,17 +491,17 @@ static void ps_polyline(point * A, int n)
 }
 
 #ifdef HAVE_LIBGD
-static void writePSBitmap (gdImagePtr im, point p, point sz)
+static void writePSBitmap (gdImagePtr im, boxf b)
 {
     int x, y, px;
 
     fprintf(Output_file, "gsave\n");
 
     /* this sets the position of the image */
-    fprintf(Output_file, "%d %d translate %% lower-left coordinate\n", p.x, p.y);
+    fprintf(Output_file, "%g %g translate %% lower-left coordinate\n", b.LL.x, b.LL.y);
 
-    /* this sets the rendered size, from 'pixels' to points (1/72 inch) */
-    fprintf(Output_file,"%d %d scale\n", sz.x, sz.y);
+    /* this sets the rendered size to fit the box */
+    fprintf(Output_file,"%g %g scale\n", b.UR.x - b.LL.x, b.UR.y - b.LL.y);
 
     /* xsize ysize bits-per-sample [matrix] */
     fprintf(Output_file, "%d %d 8 [%d 0 0 %d 0 %d]\n", im->sx, im->sy, 
@@ -672,10 +672,7 @@ static void ps_usershape(usershape_t *us, boxf b, point *A, int n, bool filled)
 
 #ifdef HAVE_LIBGD
     if (gd_img) {
-       point sz;
-       sz.x = A[0].x - A[2].x;
-       sz.y = A[0].y - A[2].y;
-       writePSBitmap (gd_img, A[2], sz);
+       writePSBitmap (gd_img, b);
        return;
     }
 #endif
index 5c6ef1487dfa3d43ac3cffb3bfbaebb89422b025..418cdfd46aa31ca74151125d1e05d9669977e130 100644 (file)
@@ -1029,10 +1029,14 @@ void gvrender_usershape(GVJ_t * job, char *name, pointf * a, int n, bool filled)
        th = us->h * scaley;
     }
     /* if image is smaller than target area then center it */
-    if (tw < pw)
+    if (tw < pw) {
        b.LL.x += (pw - tw) / 2.0;
-    if (th < ph)
+       b.UR.x -= (pw - tw) / 2.0;
+    }
+    if (th < ph) {
        b.LL.y += (ph - th) / 2.0;
+       b.UR.y -= (ph - th) / 2.0;
+    }
 
     if (gvre && gvre->usershape)
         gvre->usershape(job, us, b, filled);