[librsvg: 11/31] Add a non-pushing version of push_coord_units




commit d507eb9dd8f4f8b912aae0fa694929c86b78f00b
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jun 2 16:45:06 2021 -0500

    Add a non-pushing version of push_coord_units
    
    The only remaining place that depends on push_coord_units leaving a
    pushed coordinate system is the mask code.
    
    All the other places now call the new get_view_params_for_units().

 src/drawing_ctx.rs | 29 ++++++++++++++++++++++-------
 src/filters/mod.rs | 14 ++++++++------
 src/gradient.rs    |  2 +-
 src/pattern.rs     |  4 ++--
 4 files changed, 33 insertions(+), 16 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 734029fa..f0fbd60e 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -374,6 +374,23 @@ impl DrawingCtx {
             .expect("viewport_stack must never be empty!")
     }
 
+    // Same as `push_coord_units` but doesn't leave the coordinate space pushed
+    pub fn get_view_params_for_units(&self, units: CoordUnits) -> ViewParams {
+        match units {
+            CoordUnits::ObjectBoundingBox => ViewParams {
+                dpi: self.dpi,
+                vbox: ViewBox::from(Rect::from_size(1.0, 1.0)),
+                viewport_stack: None,
+            },
+
+            CoordUnits::UserSpaceOnUse => ViewParams {
+                dpi: self.dpi,
+                vbox: self.get_top_viewport().vbox,
+                viewport_stack: None,
+            },
+        }
+    }
+
     pub fn push_coord_units(&self, units: CoordUnits) -> ViewParams {
         match units {
             CoordUnits::ObjectBoundingBox => self.push_view_box(1.0, 1.0),
@@ -555,8 +572,7 @@ impl DrawingCtx {
         let mask_units = mask.get_units();
 
         let mask_rect = {
-            let view_params = self.push_coord_units(mask_units);
-            let params = NormalizeParams::new(values, &view_params);
+            let params = NormalizeParams::new(values, &self.get_view_params_for_units(mask_units));
             mask.get_rect(&params)
         };
 
@@ -735,11 +751,10 @@ impl DrawingCtx {
                     // being resolved in userSpaceonUse units, since that is the default
                     // for primitive_units.  So, get the corresponding NormalizeParams
                     // here and pass them down.
-                    let user_space_params = {
-                        let view_params =
-                            temporary_draw_ctx.push_coord_units(CoordUnits::UserSpaceOnUse);
-                        NormalizeParams::new(values, &view_params)
-                    };
+                    let user_space_params = NormalizeParams::new(
+                        values,
+                        &temporary_draw_ctx.get_view_params_for_units(CoordUnits::UserSpaceOnUse),
+                    );
 
                     (
                         temporary_draw_ctx.run_filters(
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index f2016fb4..f4e19a6e 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -256,10 +256,10 @@ pub fn extract_filter_from_filter_node(
 
         let filter = borrow_element_as!(filter_node, Filter);
 
-        // This is in a temporary scope so we don't leave the coord_units pushed during
-        // the execution of all the filter primitives.
-        let params = draw_ctx.push_coord_units(filter.get_filter_units());
-        filter.to_user_space(&NormalizeParams::new(filter_values, &params))
+        filter.to_user_space(&NormalizeParams::new(
+            filter_values,
+            &draw_ctx.get_view_params_for_units(filter.get_filter_units()),
+        ))
     };
 
     let primitives = filter_node
@@ -283,9 +283,11 @@ pub fn extract_filter_from_filter_node(
 
             let primitive_name = format!("{}", primitive_node);
 
-            let view_params = draw_ctx.push_coord_units(user_space_filter.primitive_units);
             let primitive_values = elt.get_computed_values();
-            let params = NormalizeParams::new(&primitive_values, &view_params);
+            let params = NormalizeParams::new(
+                &primitive_values,
+                &draw_ctx.get_view_params_for_units(user_space_filter.primitive_units),
+            );
 
             effect
                 .resolve(acquired_nodes, &primitive_node)
diff --git a/src/gradient.rs b/src/gradient.rs
index fea0a7fd..6f5130b9 100644
--- a/src/gradient.rs
+++ b/src/gradient.rs
@@ -692,7 +692,7 @@ impl ResolvedGradient {
             return None;
         };
 
-        let view_params = draw_ctx.push_coord_units(units);
+        let view_params = draw_ctx.get_view_params_for_units(units);
         let params = NormalizeParams::new(values, &view_params);
 
         let transform = transform.pre_transform(&self.transform).invert()?;
diff --git a/src/pattern.rs b/src/pattern.rs
index 3c75362a..c33ba11d 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -332,8 +332,8 @@ impl ResolvedPattern {
     ) -> Option<UserSpacePattern> {
         let node_with_children = self.node_with_children()?;
 
-        let view_params = draw_ctx.push_coord_units(self.units.0);
-        let params = NormalizeParams::new(values, &view_params);
+        let params =
+            NormalizeParams::new(values, &draw_ctx.get_view_params_for_units(self.units.0));
 
         let rect = self.get_rect(&params);
         let bbrect = bbox.rect.unwrap();


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