[librsvg: 1/2] Remove duplicated code




commit 2803c29486fdffdeee59f8d535b64aa00a6c2098
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Oct 1 16:00:20 2021 -0500

    Remove duplicated code
    
    This moves the code to test for percentage units to the API implementation.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/596>

 src/api.rs    | 16 +++++++++++++++-
 src/handle.rs | 33 ---------------------------------
 2 files changed, 15 insertions(+), 34 deletions(-)
---
diff --git a/src/api.rs b/src/api.rs
index b38880d4..8316b290 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -365,7 +365,21 @@ impl<'a> CairoRenderer<'a> {
     /// kind require more information to be resolved to pixels; for example, the calling
     /// application can use a viewport size to scale percentage-based dimensions.
     pub fn intrinsic_size_in_pixels(&self) -> Option<(f64, f64)> {
-        self.handle.0.get_intrinsic_size_in_pixels(self.dpi)
+        let dim = self.intrinsic_dimensions();
+
+        // missing width/height default to "auto", which compute to "100%"
+        let width = dim
+            .width
+            .unwrap_or_else(|| Length::new(1.0, LengthUnit::Percent));
+        let height = dim
+            .height
+            .unwrap_or_else(|| Length::new(1.0, LengthUnit::Percent));
+
+        if width.unit == LengthUnit::Percent || height.unit == LengthUnit::Percent {
+            return None;
+        }
+
+        Some(self.handle.0.width_height_to_user(self.dpi))
     }
 
     /// Renders the whole SVG document fitted to a viewport
diff --git a/src/handle.rs b/src/handle.rs
index 4c6a5325..4c8ea852 100644
--- a/src/handle.rs
+++ b/src/handle.rs
@@ -108,39 +108,6 @@ impl Handle {
         }
     }
 
-    /// If the intrinsic dimensions are in physical units, computes their pixel size, or
-    /// returns `None`.
-    ///
-    /// If any of the width/height are percentages, we cannot compute the size here.  Here
-    /// just normalize lengths with physical units, or units based on the font size.
-    pub fn get_intrinsic_size_in_pixels(&self, dpi: Dpi) -> Option<(f64, f64)> {
-        let dimensions = self.get_intrinsic_dimensions();
-
-        if dimensions.width.is_none() || dimensions.height.is_none() {
-            // If either of width/height don't exist, the spec says they should default to 100%,
-            // which is a percentage-based unit - which we can't resolve here.
-            return None;
-        }
-
-        let w = dimensions.width.unwrap();
-        let h = dimensions.height.unwrap();
-
-        use crate::length::LengthUnit::*;
-
-        if w.unit == Percent || h.unit == Percent {
-            return None;
-        }
-
-        let view_params = ViewParams::new(dpi, 0.0, 0.0);
-        let root = self.document.root();
-        let cascaded = CascadedValues::new_from_node(&root);
-        let values = cascaded.get();
-
-        let params = NormalizeParams::new(values, &view_params);
-
-        Some((w.to_user(&params), h.to_user(&params)))
-    }
-
     /// Normalizes the svg's width/height properties with a 0-sized viewport
     ///
     /// This assumes that if one of the properties is in percentage units, then


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