[librsvg: 9/14] handle: move rsvg_handle_get_position_sub to rust



commit 3c915c59c07f7c6a00a45db6b642123004d4cf82
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jan 5 22:48:08 2019 +0100

    handle: move rsvg_handle_get_position_sub to rust

 librsvg/rsvg-handle.c        | 25 ++++-------------------
 rsvg_internals/src/handle.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++
 rsvg_internals/src/lib.rs    |  1 +
 3 files changed, 52 insertions(+), 21 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index dc6a54e0..d05c2550 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -173,6 +173,9 @@ extern GdkPixbuf *rsvg_handle_rust_get_pixbuf_sub (RsvgHandle *handle, const cha
 extern gboolean rsvg_handle_rust_get_dimensions_sub (RsvgHandle *handle,
                                                      RsvgDimensionData *dimension_data,
                                                      const char *id);
+extern gboolean rsvg_handle_rust_get_position_sub (RsvgHandle *handle,
+                                                   RsvgPositionData *dimension_data,
+                                                   const char *id);
 
 typedef struct {
     RsvgSizeFunc func;
@@ -1121,9 +1124,6 @@ rsvg_handle_get_geometry_sub (RsvgHandle * handle, RsvgRectangle * ink_rect, Rsv
 gboolean
 rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_data, const char *id)
 {
-    RsvgRectangle ink_r;
-    int width, height;
-
     g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
     g_return_val_if_fail (position_data != NULL, FALSE);
 
@@ -1131,24 +1131,7 @@ rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_d
         return FALSE;
     }
 
-    memset (position_data, 0, sizeof (*position_data));
-
-    /* Short-cut when no id is given. */
-    if (NULL == id || '\0' == *id)
-        return TRUE;
-
-    if (!rsvg_handle_get_geometry_sub (handle, &ink_r, NULL, id))
-        return FALSE;
-
-    position_data->x = ink_r.x;
-    position_data->y = ink_r.y;
-
-    width = ink_r.width;
-    height = ink_r.height;
-
-    rsvg_handle_rust_call_size_closure (handle->priv->rust_handle, &width, &height);
-
-    return TRUE;
+    return rsvg_handle_rust_get_position_sub (handle, position_data, id);
 }
 
 /**
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index aee1a04a..a31f55bc 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -68,6 +68,13 @@ pub struct RsvgDimensionData {
     ex: f64,
 }
 
+// Keep in sync with rsvg.h:RsvgPositionData
+#[repr(C)]
+pub struct RsvgPositionData {
+    x: libc::c_int,
+    y: libc::c_int,
+}
+
 /// Flags used during loading
 ///
 /// We communicate these to/from the C code with a guint <-> u32,
@@ -1102,3 +1109,43 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_dimensions_sub(
 
     res
 }
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_get_position_sub(
+    handle: *mut RsvgHandle,
+    position: *mut RsvgPositionData,
+    id: *const libc::c_char,
+) -> glib_sys::gboolean {
+    // Short-cut when no id is given
+    if id.is_null() || *id == 0 {
+        (*position).x = 0;
+        (*position).y = 0;
+        return true.to_glib();
+    }
+
+    let rhandle = get_rust_handle(handle);
+
+    let mut ink_r = RsvgRectangle {
+        x: 0.0,
+        y: 0.0,
+        width: 0.0,
+        height: 0.0,
+    };
+
+    let res = rsvg_handle_rust_get_geometry_sub(handle, &mut ink_r, ptr::null_mut(), id);
+    if from_glib(res) {
+        (*position).x = ink_r.x as libc::c_int;
+        (*position).y = ink_r.y as libc::c_int;
+
+        let mut width = ink_r.width as libc::c_int;
+        let mut height = ink_r.height as libc::c_int;
+        if !rhandle.size_closure.is_null() {
+            rsvg_size_closure_call(rhandle.size_closure, &mut width, &mut height);
+        }
+    } else {
+        (*position).x = 0;
+        (*position).y = 0;
+    }
+
+    res
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index a9830f72..9b18eab5 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -47,6 +47,7 @@ pub use handle::{
     rsvg_handle_rust_get_flags,
     rsvg_handle_rust_get_geometry_sub,
     rsvg_handle_rust_get_pixbuf_sub,
+    rsvg_handle_rust_get_position_sub,
     rsvg_handle_rust_has_sub,
     rsvg_handle_rust_is_at_start_for_setting_base_file,
     rsvg_handle_rust_is_loaded,


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