From: ellson Date: Fri, 7 Jan 2011 18:43:06 +0000 (+0000) Subject: Better fix for bug #2102 X-Git-Tag: LAST_LIBGRAPH~32^2~1116 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=592f0b815bb03243cc29f57046ff3d7173682dc5;p=graphviz Better fix for bug #2102 Root cause was zero-divides from rendering of degenerate ellipse --- diff --git a/plugin/gd/gvdevice_gd.c b/plugin/gd/gvdevice_gd.c index a973786cd..e22bc8943 100644 --- a/plugin/gd/gvdevice_gd.c +++ b/plugin/gd/gvdevice_gd.c @@ -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; } diff --git a/plugin/pango/gvrender_pango.c b/plugin/pango/gvrender_pango.c index af6aa7241..41d835611 100644 --- a/plugin/pango/gvrender_pango.c +++ b/plugin/pango/gvrender_pango.c @@ -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);