[librsvg: 4/10] RsvgDimensionData::empty(): new; use wherever we were generating this by hand



commit 7715a46a68e65c85540988628553f82812f623ae
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jul 23 14:44:18 2019 -0500

    RsvgDimensionData::empty(): new; use wherever we were generating this by hand

 rsvg_internals/src/c_api.rs  | 14 ++++++++++++++
 rsvg_internals/src/handle.rs | 12 +-----------
 2 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/rsvg_internals/src/c_api.rs b/rsvg_internals/src/c_api.rs
index f7a25042..f69b8e3e 100644
--- a/rsvg_internals/src/c_api.rs
+++ b/rsvg_internals/src/c_api.rs
@@ -136,6 +136,20 @@ pub struct RsvgDimensionData {
     pub ex: f64,
 }
 
+impl RsvgDimensionData {
+    // This is not #[derive(Default)] to make it clear that it
+    // shouldn't be the default value for anything; it is actually a
+    // special case we use to indicate an error to the public API.
+    pub fn empty() -> RsvgDimensionData {
+        RsvgDimensionData {
+            width: 0,
+            height: 0,
+            em: 0.0,
+            ex: 0.0,
+        }
+    }
+}
+
 // Keep in sync with rsvg.h:RsvgPositionData
 #[repr(C)]
 pub struct RsvgPositionData {
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index c70f7b72..f96dc6df 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -129,17 +129,7 @@ impl Handle {
     ) -> RsvgDimensionData {
         match self.get_dimensions(dpi, size_callback, is_testing) {
             Ok(dimensions) => dimensions,
-
-            Err(_) => {
-                RsvgDimensionData {
-                    width: 0,
-                    height: 0,
-                    em: 0.0,
-                    ex: 0.0,
-                }
-
-                // This old API doesn't even let us return an error, sigh.
-            }
+            Err(_) => RsvgDimensionData::empty(),
         }
     }
 


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