[librsvg: 14/38] Handle::get_dimensions_no_error(): Implement the error-less version here



commit b01e5d67945e101e6b530118e34a4ae2e8241c93
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jan 22 19:06:51 2019 -0600

    Handle::get_dimensions_no_error(): Implement the error-less version here
    
    The public rsvg_handle_get_dimensions() doesn't return an error code,
    but just an all-zeros RsvgDimensionData.  Put that logic in Handle,
    since we'll need it for the GObject::get_property implementation.

 rsvg_internals/src/handle.rs | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 6a1db06f..e15d306d 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -378,6 +378,25 @@ impl Handle {
         })
     }
 
+    pub fn get_dimensions_no_error(&mut self) -> RsvgDimensionData {
+        match self.get_dimensions() {
+            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.
+            }
+        }
+    }
+
     fn get_dimensions_sub(
         &mut self,
         id: Option<&str>,
@@ -947,22 +966,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_dimensions(
 ) {
     let rhandle = get_rust_handle(handle);
 
-    match rhandle.get_dimensions() {
-        Ok(dimensions) => {
-            *dimension_data = dimensions;
-        }
-
-        Err(_) => {
-            let d = &mut *dimension_data;
-
-            d.width = 0;
-            d.height = 0;
-            d.em = 0.0;
-            d.ex = 0.0;
-
-            // This old API doesn't even let us return an error, sigh.
-        }
-    }
+    *dimension_data = rhandle.get_dimensions_no_error();
 }
 
 #[no_mangle]


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