[librsvg] Handle.get_geometry_for_element() - new fundamental method without the "no size" magic



commit 97f61e8396e61e5c0d0abd49107c7e9b6c6ae9b9
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Feb 19 17:41:53 2019 -0600

    Handle.get_geometry_for_element() - new fundamental method without the "no size" magic
    
    get_dimensions() and friends have this logic:
    
    - if the <svg> element has width/height attributes, return them
    - otherwise, if the element has a viewBox, return its size
    - otherwise, compute the actual element size by recursively computing bboxes
    
    We'll move to a model where computing element bboxes is not done
    implicitly.  This is the new primitive that actually does that.

 librsvg_crate/src/lib.rs     |  4 ++--
 rsvg_internals/src/handle.rs | 26 ++++++++++++++++++--------
 2 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index 871e815d..d49650fb 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -376,7 +376,7 @@ impl<'a> CairoRenderer<'a> {
         }
     }
 
-    /// Returns (ink_rect, logical_rect) of an SVG element.
+    /// Computes the (ink_rect, logical_rect) of an SVG element.
     ///
     /// Element IDs should look like an URL fragment identifier; for
     /// example, pass `Some("#foo")` to get the geometry of the
@@ -405,7 +405,7 @@ impl<'a> CairoRenderer<'a> {
     ) -> Result<(cairo::Rectangle, cairo::Rectangle), RenderingError> {
         self.handle
             .0
-            .get_geometry_sub(id)
+            .get_geometry_for_element(id)
             .map(|(i, l)| (i.into(), l.into()))
     }
 
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 853e1bb4..ee43ca8a 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -420,15 +420,9 @@ impl Handle {
         &self,
         id: Option<&str>,
     ) -> Result<(RsvgRectangle, RsvgRectangle), RenderingError> {
+        let node = self.get_node_or_root(id)?;
         let root = self.get_root();
-
-        let (node, is_root) = if let Some(id) = id {
-            let n = self.lookup_node(id).map_err(RenderingError::InvalidId)?;
-            let is_root = Rc::ptr_eq(&n, &root);
-            (n, is_root)
-        } else {
-            (root, true)
-        };
+        let is_root = Rc::ptr_eq(&node, &root);
 
         if is_root {
             let cascaded = node.get_cascaded_values();
@@ -453,6 +447,22 @@ impl Handle {
         self.get_node_geometry(&node)
     }
 
+    fn get_node_or_root(&self, id: Option<&str>) -> Result<RsvgNode, RenderingError> {
+        if let Some(id) = id {
+            self.lookup_node(id).map_err(RenderingError::InvalidId)
+        } else {
+            Ok(self.get_root())
+        }
+    }
+
+    pub fn get_geometry_for_element(
+        &self,
+        id: Option<&str>,
+    ) -> Result<(RsvgRectangle, RsvgRectangle), RenderingError> {
+        let node = self.get_node_or_root(id)?;
+        self.get_node_geometry(&node)
+    }
+
     fn lookup_node(&self, id: &str) -> Result<RsvgNode, DefsLookupErrorKind> {
         let svg_ref = self.svg.borrow();
         let svg = svg_ref.as_ref().unwrap();


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