[librsvg: 12/19] Move the implementation of get_dimensions_sub to c_api



commit 106c6b62a3ef45fc667ce86eb25cd4a2e666be73
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Apr 24 19:42:00 2020 -0500

    Move the implementation of get_dimensions_sub to c_api

 librsvg/c_api.rs             | 48 ++++++++++++++++++++++++++++++++++----------
 rsvg_internals/src/handle.rs | 43 ---------------------------------------
 2 files changed, 37 insertions(+), 54 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 673aca89..0eb4c0e0 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -681,9 +681,41 @@ impl CHandle {
     fn get_dimensions_sub(&self, id: Option<&str>) -> Result<RsvgDimensionData, RenderingError> {
         let handle = self.get_handle_ref()?;
         let inner = self.inner.borrow();
-        handle
-            .get_dimensions_sub(id, inner.dpi, &inner.size_callback, inner.is_testing)
-            .map_err(warn_on_invalid_id)
+
+        // This function is probably called from the cairo_render functions,
+        // or is being erroneously called within the size_func.
+        // To prevent an infinite loop we are saving the state, and
+        // returning a meaningless size.
+        if inner.size_callback.get_in_loop() {
+            return Ok(RsvgDimensionData {
+                width: 1,
+                height: 1,
+                em: 1.0,
+                ex: 1.0,
+            });
+        }
+
+        inner.size_callback.start_loop();
+
+        let res = handle
+            .get_geometry_sub(id, inner.dpi, inner.is_testing)
+            .and_then(|(ink_r, _)| {
+                let width = ink_r.width().round() as libc::c_int;
+                let height = ink_r.height().round() as libc::c_int;
+
+                let (w, h) = inner.size_callback.call(width, height);
+
+                Ok(RsvgDimensionData {
+                    width: w,
+                    height: h,
+                    em: ink_r.width(),
+                    ex: ink_r.height(),
+                })
+            });
+
+        inner.size_callback.end_loop();
+
+        res.map_err(warn_on_invalid_id)
     }
 
     fn get_position_sub(&self, id: Option<&str>) -> Result<RsvgPositionData, RenderingError> {
@@ -727,18 +759,12 @@ impl CHandle {
             width: f64::from(dimensions.width),
             height: f64::from(dimensions.height),
         };
-        
+
         self.render_layer(cr, id, &viewport)
     }
 
     fn get_pixbuf_sub(&self, id: Option<&str>) -> Result<Pixbuf, RenderingError> {
-        let handle = self.get_handle_ref()?;
-        let inner = self.inner.borrow();
-
-        let dpi = inner.dpi;
-        let is_testing = inner.is_testing;
-
-        let dimensions = handle.get_dimensions_sub(None, dpi, &inner.size_callback, is_testing)?;
+        let dimensions = self.get_dimensions_sub(None)?;
 
         if dimensions.width == 0 || dimensions.height == 0 {
             return empty_pixbuf();
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index af4f8b52..c6d9396e 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -206,49 +206,6 @@ impl Handle {
         }
     }
 
-    pub fn get_dimensions_sub(
-        &self,
-        id: Option<&str>,
-        dpi: Dpi,
-        size_callback: &SizeCallback,
-        is_testing: bool,
-    ) -> Result<RsvgDimensionData, RenderingError> {
-        // This function is probably called from the cairo_render functions,
-        // or is being erroneously called within the size_func.
-        // To prevent an infinite loop we are saving the state, and
-        // returning a meaningless size.
-        if size_callback.get_in_loop() {
-            return Ok(RsvgDimensionData {
-                width: 1,
-                height: 1,
-                em: 1.0,
-                ex: 1.0,
-            });
-        }
-
-        size_callback.start_loop();
-
-        let res = self
-            .get_geometry_sub(id, dpi, is_testing)
-            .and_then(|(ink_r, _)| {
-                let width = ink_r.width().round() as libc::c_int;
-                let height = ink_r.height().round() as libc::c_int;
-
-                let (w, h) = size_callback.call(width, height);
-
-                Ok(RsvgDimensionData {
-                    width: w,
-                    height: h,
-                    em: ink_r.width(),
-                    ex: ink_r.height(),
-                })
-            });
-
-        size_callback.end_loop();
-
-        res
-    }
-
     pub fn get_position_sub(
         &self,
         id: Option<&str>,


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