[cairo-commit] src/cairo-pattern.c

Chris Wilson ickle at kemper.freedesktop.org
Fri Oct 23 07:06:15 PDT 2009


 src/cairo-pattern.c |   27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

New commits:
commit c701d7813b6d116c9db53f63f791928a407499c7
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Oct 23 14:42:48 2009 +0100

    [pattern] Compute zero extents for empty patterns
    
    If the pattern is for example a repeating 0x0 image, then treat it as
    having zero extents.
    
    This should workaround the bug presented here:
    
      https://bugs.freedesktop.org/show_bug.cgi?id=24693
      Attached PDF crashes evince with a Floating point exception

diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index cf6dab2..a744118 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -2446,9 +2446,6 @@ _cairo_pattern_get_extents (const cairo_pattern_t         *pattern,
     double x1, y1, x2, y2;
     cairo_status_t status;
 
-    if (pattern->extend != CAIRO_EXTEND_NONE)
-	goto UNBOUNDED;
-
     switch (pattern->type) {
     case CAIRO_PATTERN_TYPE_SOLID:
 	goto UNBOUNDED;
@@ -2464,6 +2461,12 @@ _cairo_pattern_get_extents (const cairo_pattern_t         *pattern,
 	    if (! _cairo_surface_get_extents (surface, &surface_extents))
 		goto UNBOUNDED;
 
+	    if (surface_extents.width == 0 || surface_extents.height == 0)
+		goto EMPTY;
+
+	    if (pattern->extend != CAIRO_EXTEND_NONE)
+		goto UNBOUNDED;
+
 	    /* The filter can effectively enlarge the extents of the
 	     * pattern, so extend as necessary.
 	     */
@@ -2483,6 +2486,9 @@ _cairo_pattern_get_extents (const cairo_pattern_t         *pattern,
 	    double cx2, cy2;
 	    double r, D;
 
+	    if (radial->r1 == 0 && radial->r2 == 0)
+		goto EMPTY;
+
 	    cx1 = _cairo_fixed_to_double (radial->c1.x);
 	    cy1 = _cairo_fixed_to_double (radial->c1.y);
 	    r = _cairo_fixed_to_double (radial->r1);
@@ -2493,6 +2499,9 @@ _cairo_pattern_get_extents (const cairo_pattern_t         *pattern,
 	    cy2 = _cairo_fixed_to_double (radial->c2.y);
 	    r = fabs (_cairo_fixed_to_double (radial->r2));
 
+	    if (pattern->extend != CAIRO_EXTEND_NONE)
+		goto UNBOUNDED;
+
 	    /* We need to be careful, as if the circles are not
 	     * self-contained, then the solution is actually unbounded.
 	     */
@@ -2517,6 +2526,12 @@ _cairo_pattern_get_extents (const cairo_pattern_t         *pattern,
 	    const cairo_linear_pattern_t *linear =
 		(const cairo_linear_pattern_t *) pattern;
 
+	    if (linear->p1.x == linear->p2.x && linear->p1.y == linear->p2.y)
+		goto EMPTY;
+
+	    if (pattern->extend != CAIRO_EXTEND_NONE)
+		goto UNBOUNDED;
+
 	    if (pattern->matrix.xy != 0. || pattern->matrix.yx != 0.)
 		goto UNBOUNDED;
 
@@ -2570,6 +2585,12 @@ _cairo_pattern_get_extents (const cairo_pattern_t         *pattern,
   UNBOUNDED:
     /* unbounded patterns -> 'infinite' extents */
     _cairo_unbounded_rectangle_init (extents);
+    return;
+
+  EMPTY:
+    extents->x = extents->y = 0;
+    extents->width = extents->height = 0;
+    return;
 }
 
 


More information about the cairo-commit mailing list