[librsvg: 9/15] Inline get_svg_size() in its only caller




commit 23adc6f55a825532b901872ca0517e8914082aa4
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Oct 27 14:01:43 2020 -0600

    Inline get_svg_size() in its only caller

 librsvg/c_api.rs | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index b769fedf..9cbc8dd6 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -895,13 +895,27 @@ impl CHandle {
         }
     }
 
+    /// Returns the SVG's size suitable for the legacy C API.
+    ///
+    /// The legacy C API can compute an SVG document's size from the
+    /// `width`, `height`, and `viewBox` attributes of the toplevel `<svg>`
+    /// element.  If these are not available, then the size must be computed
+    /// by actually measuring the geometries of elements in the document.
+    ///
+    /// See https://www.w3.org/TR/css-images-3/#sizing-terms for terminology and logic.
     fn legacy_document_size_in_pixels(
         &self,
     ) -> Result<(cairo::Rectangle, cairo::Rectangle), RenderingError> {
         let handle = self.get_handle_ref()?;
         let inner = self.inner.borrow();
 
-        if let Some((width, height)) = self.get_svg_size()? {
+        let size_from_intrinsic_dimensions = handle
+            .get_intrinsic_size_in_pixels(inner.dpi.into())
+            .or_else(|| {
+                size_in_pixels_from_percentage_width_and_height(&handle.get_intrinsic_dimensions())
+            });
+
+        if let Some((width, height)) = size_from_intrinsic_dimensions {
             let rect = cairo::Rectangle::from_size(width, height);
             Ok((rect, rect))
         } else {
@@ -914,27 +928,6 @@ impl CHandle {
         }
     }
 
-    // Returns the SVG's size suitable for the legacy C API, or None
-    // if it must be computed by hand.
-    //
-    // The legacy C API can compute an SVG document's size from the
-    // `width`, `height`, and `viewBox` attributes of the toplevel `<svg>`
-    // element.  If these are not available, then the size must be computed
-    // by actually measuring the geometries of elements in the document; this last
-    // case is implemented by the caller.
-    //
-    // See https://www.w3.org/TR/css-images-3/#sizing-terms for terminology and logic.
-    fn get_svg_size(&self) -> Result<Option<(f64, f64)>, RenderingError> {
-        let handle = self.get_handle_ref()?;
-        let inner = self.inner.borrow();
-
-        Ok(handle
-            .get_intrinsic_size_in_pixels(inner.dpi.into())
-            .or_else(|| {
-                size_in_pixels_from_percentage_width_and_height(&handle.get_intrinsic_dimensions())
-            }))
-    }
-
     fn set_stylesheet(&self, css: &str) -> Result<(), LoadingError> {
         match *self.load_state.borrow_mut() {
             LoadState::ClosedOk { ref mut handle } => handle.set_stylesheet(css),


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