[librsvg/librsvg-2.40] Backport: bgo#777834: Don't try to render text whose PangoLayout has zero extents



commit 823e30ed5ebce64ffd7c5f6e307ef7a822ee896f
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Mar 2 18:50:39 2017 -0600

    Backport: bgo#777834: Don't try to render text whose PangoLayout has zero extents
    
    From commit 8bf4354fdc3703c0ea6ecec86ce2f3583933c03a
    
    Text elements sometimes have children with empty strings for their
    contents, so PangoLayout returns an ink_rect with (width, height) = (0, 0).
    
    In this case, we would set a bbox's size to (0, 0), then use that in an
    affine matrix, and try to invert it, and kaboom.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777834

 rsvg-cairo-draw.c                                  |    8 ++++++--
 .../bugs/777834-empty-text-children-ref.png        |  Bin 0 -> 9386 bytes
 .../reftests/bugs/777834-empty-text-children.svg}  |    0
 3 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index c29d071..0a50255 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -450,12 +450,16 @@ rsvg_cairo_render_pango_layout (RsvgDrawingCtx * ctx, PangoLayout * layout, doub
     PangoGravity gravity = pango_context_get_gravity (pango_layout_get_context (layout));
     double rotation;
 
+    pango_layout_get_extents (layout, &ink, NULL);
+
+    if (ink.width == 0 || ink.height == 0) {
+        return;
+    }
+
     cairo_set_antialias (render->cr, state->text_rendering_type);
 
     _set_rsvg_affine (render, &state->affine);
 
-    pango_layout_get_extents (layout, &ink, NULL);
-
     rsvg_bbox_init (&bbox, &state->affine);
     if (PANGO_GRAVITY_IS_VERTICAL (gravity)) {
         bbox.rect.x = x + (ink.x - ink.height) / (double)PANGO_SCALE;
diff --git a/tests/fixtures/reftests/bugs/777834-empty-text-children-ref.png 
b/tests/fixtures/reftests/bugs/777834-empty-text-children-ref.png
new file mode 100644
index 0000000..58a4c03
Binary files /dev/null and b/tests/fixtures/reftests/bugs/777834-empty-text-children-ref.png differ
diff --git a/tests/samples/text-gradient-3.svg b/tests/fixtures/reftests/bugs/777834-empty-text-children.svg
similarity index 100%
rename from tests/samples/text-gradient-3.svg
rename to tests/fixtures/reftests/bugs/777834-empty-text-children.svg


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]