]> granicus.if.org Git - graphviz/commitdiff
Better fix for bug #2102
authorellson <devnull@localhost>
Fri, 7 Jan 2011 18:43:06 +0000 (18:43 +0000)
committerellson <devnull@localhost>
Fri, 7 Jan 2011 18:43:06 +0000 (18:43 +0000)
Root cause was zero-divides from rendering of degenerate ellipse

plugin/gd/gvdevice_gd.c
plugin/pango/gvrender_pango.c

index a973786cd921a09101b0f7823e443aa437724ab1..e22bc89431a683b6272321ea3d4619293b8c612f 100644 (file)
@@ -85,17 +85,15 @@ static void gd_format(GVJ_t * job)
     switch (job->device.id) {
 #ifdef HAVE_GD_PNG
     case FORMAT_PNG:
-       if (data) {
-            for (y = 0; y < height; y++) {
-                for (x = 0; x < width; x++) {
-                    color = *data++;
-                   /* gd's max alpha is 127 */
-                   /*   so right-shift 25 to lose lsb of alpha */
-                   alpha = (color >> 25) & 0x7f;
-                   im->tpixels[y][x] = (color & 0xffffff) | ((0x7f - alpha) << 24);
-               }
-            }
-       }
+        for (y = 0; y < height; y++) {
+            for (x = 0; x < width; x++) {
+                color = *data++;
+               /* gd's max alpha is 127 */
+               /*   so right-shift 25 to lose lsb of alpha */
+               alpha = (color >> 25) & 0x7f;
+               im->tpixels[y][x] = (color & 0xffffff) | ((0x7f - alpha) << 24);
+           }
+        }
         break;
 #endif
     default:
@@ -104,20 +102,18 @@ static void gd_format(GVJ_t * job)
 
         gdImageColorTransparent(im, TRANSPARENT);
         gdImageAlphaBlending(im, FALSE);
-       if (data) {
-            for (y = 0; y < height; y++) {
-                for (x = 0; x < width; x++) {
-                    color = *data++;
-                   /* gd's max alpha is 127 */
-                   /*   so right-shift 25 to lose lsb of alpha */
-                   if ((alpha = (color >> 25) & 0x7f) >= 0x20)
-                       /* if not > 75% transparent */
-                       im->tpixels[y][x] = (color & 0xffffff) | ((0x7f - alpha) << 24);
-                   else
-                       im->tpixels[y][x] = TRANSPARENT;
-               }
-            }
-       }
+        for (y = 0; y < height; y++) {
+            for (x = 0; x < width; x++) {
+                color = *data++;
+               /* gd's max alpha is 127 */
+               /*   so right-shift 25 to lose lsb of alpha */
+               if ((alpha = (color >> 25) & 0x7f) >= 0x20)
+                   /* if not > 75% transparent */
+                   im->tpixels[y][x] = (color & 0xffffff) | ((0x7f - alpha) << 24);
+               else
+                   im->tpixels[y][x] = TRANSPARENT;
+           }
+        }
         break;
     }
 
index af6aa7241493a82508ca7eaf8f4cbbbd3a105c3b..41d8356114b2169d61b3ed6a3a2e83f8713309c8 100644 (file)
@@ -200,6 +200,10 @@ static void cairogen_end_page(GVJ_t * job)
     case FORMAT_CAIRO:
     default:
         surface = cairo_get_target(cr);
+        if (cairo_image_surface_get_width(surface) == 0 || cairo_image_surface_get_height(surface) == 0) {
+           /* apparently cairo never allocates a surface if nothing was ever written to it */
+           fprintf(stderr, "ERROR: cairo surface has zero area, this may indicate some problem during rendering shapes.\n");
+       }
        job->imagedata = (char *)(cairo_image_surface_get_data(surface));       
        break;
                /* formatting will be done by gvdevice_format() */
@@ -260,14 +264,17 @@ static void cairogen_ellipse(GVJ_t * job, pointf * A, int filled)
     cairogen_set_penstyle(job, cr);
 
     cairo_get_matrix(cr, &matrix);
-    cairo_translate(cr, A[0].x, -A[0].y);
 
     rx = A[1].x - A[0].x;
     ry = A[1].y - A[0].y;
-    cairo_scale(cr, 1, ry / rx);
-    cairo_move_to(cr, rx, 0);
-    cairo_arc(cr, 0, 0, rx, 0, 2 * M_PI);
-    cairo_close_path(cr);
+
+#define RMIN 0.01
+if (rx < RMIN) rx = RMIN;
+if (ry < RMIN) ry = RMIN;
+
+    cairo_translate(cr, A[0].x, -A[0].y);
+    cairo_scale(cr, rx, ry);
+    cairo_arc(cr, 0., 0., 1., 0., 2 * M_PI);
 
     cairo_set_matrix(cr, &matrix);