[librsvg: 30/45] gradient: check the validity of the bbox as late as possible



commit 7a701f66eacf979598264809da12253fa906c566
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Sep 30 08:49:10 2019 -0500

    gradient: check the validity of the bbox as late as possible
    
    Resolving a gradient does not use the bbox of the "applicable element"
    at all.  The only rule is that if we have
    gradientUnits=objectBoundingBox, then the element's bounding box must
    not be empty.  Thus, the bbox only needs to be tested during
    set_pattern_on_draw_context().

 rsvg_internals/src/gradient.rs | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index 7365f12b..66e428a6 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -501,14 +501,6 @@ impl UnresolvedGradient {
 
         UnresolvedGradient { units, affine, spread, stops, variant }
     }
-
-    fn bounds_are_valid(&self, bbox: &BoundingBox) -> bool {
-        if self.units == Some(GradientUnits(CoordUnits::UserSpaceOnUse)) {
-            true
-        } else {
-            bbox.rect.map_or(false, |r| !r.is_empty())
-        }
-    }
 }
 
 struct Unresolved {
@@ -591,7 +583,7 @@ impl PaintSource for NodeGradient {
         &self,
         node: &RsvgNode,
         draw_ctx: &mut DrawingCtx,
-        bbox: &BoundingBox,
+        _bbox: &BoundingBox,
     ) -> Result<Option<Self::Resolved>, RenderingError> {
         let Unresolved { mut gradient, mut fallback } = self.get_unresolved(node);
 
@@ -620,11 +612,7 @@ impl PaintSource for NodeGradient {
             }
         }
 
-        if gradient.bounds_are_valid(bbox) {
-            Ok(Some(gradient.to_resolved()))
-        } else {
-            Ok(None)
-        }
+        Ok(Some(gradient.to_resolved()))
     }
 }
 
@@ -637,6 +625,11 @@ impl ResolvedPaintSource for Gradient {
         bbox: &BoundingBox,
     ) -> Result<bool, RenderingError> {
         let params = if self.units == GradientUnits(CoordUnits::ObjectBoundingBox) {
+            if bbox.rect.map_or(true, |r| r.is_empty()) {
+                // objectBoundingBox requires a non-empty bbox, see issues #187, #373
+                return Ok(false);
+            }
+
             draw_ctx.push_view_box(1.0, 1.0)
         } else {
             draw_ctx.get_view_params()


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