[librsvg: 8/14] handle: move rsvg_handle_get_dimensions_sub to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 8/14] handle: move rsvg_handle_get_dimensions_sub to rust
- Date: Sun, 6 Jan 2019 03:25:29 +0000 (UTC)
commit bdb23f0d40d227e02aeda081cdc58af9dc7e4b53
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jan 5 22:21:27 2019 +0100
handle: move rsvg_handle_get_dimensions_sub to rust
librsvg/rsvg-handle.c | 21 ++++-----------------
rsvg_internals/src/handle.rs | 39 +++++++++++++++++++++++++++++++++++++++
rsvg_internals/src/lib.rs | 1 +
3 files changed, 44 insertions(+), 17 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 4710c462..dc6a54e0 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -170,6 +170,9 @@ extern gboolean rsvg_handle_rust_render_cairo_sub (RsvgHandle *handle,
cairo_t *cr,
const char *id);
extern GdkPixbuf *rsvg_handle_rust_get_pixbuf_sub (RsvgHandle *handle, const char *id);
+extern gboolean rsvg_handle_rust_get_dimensions_sub (RsvgHandle *handle,
+ RsvgDimensionData *dimension_data,
+ const char *id);
typedef struct {
RsvgSizeFunc func;
@@ -1064,8 +1067,6 @@ rsvg_handle_get_dimensions (RsvgHandle * handle, RsvgDimensionData * dimension_d
gboolean
rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimension_data, const char *id)
{
- RsvgRectangle ink_r;
-
g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
g_return_val_if_fail (dimension_data, FALSE);
@@ -1073,21 +1074,7 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
return FALSE;
}
- memset (&ink_r, 0, sizeof (RsvgRectangle));
- memset (dimension_data, 0, sizeof (RsvgDimensionData));
-
- if (!rsvg_handle_get_geometry_sub (handle, &ink_r, NULL, id)) {
- return FALSE;
- }
-
- dimension_data->width = ink_r.width;
- dimension_data->height = ink_r.height;
- dimension_data->em = dimension_data->width;
- dimension_data->ex = dimension_data->height;
-
- rsvg_handle_rust_call_size_closure (handle->priv->rust_handle, &dimension_data->width,
&dimension_data->height);
-
- return TRUE;
+ return rsvg_handle_rust_get_dimensions_sub (handle, dimension_data, id);
}
/**
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index fe5f2e4e..aee1a04a 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -1063,3 +1063,42 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_pixbuf_sub(
Err(_) => ptr::null_mut(),
}
}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_get_dimensions_sub(
+ handle: *mut RsvgHandle,
+ dimension_data: *mut RsvgDimensionData,
+ id: *const libc::c_char,
+) -> glib_sys::gboolean {
+ 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) {
+ (*dimension_data).width = ink_r.width as libc::c_int;
+ (*dimension_data).height = ink_r.height as libc::c_int;
+ (*dimension_data).em = ink_r.width;
+ (*dimension_data).ex = ink_r.height;
+
+ if !rhandle.size_closure.is_null() {
+ rsvg_size_closure_call(
+ rhandle.size_closure,
+ &mut (*dimension_data).width,
+ &mut (*dimension_data).height,
+ );
+ }
+ } else {
+ (*dimension_data).width = 0;
+ (*dimension_data).height = 0;
+ (*dimension_data).em = 0.0;
+ (*dimension_data).ex = 0.0;
+ }
+
+ res
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index ea5d3db8..a9830f72 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -41,6 +41,7 @@ pub use handle::{
rsvg_handle_rust_close,
rsvg_handle_rust_free,
rsvg_handle_rust_get_base_gfile,
+ rsvg_handle_rust_get_dimensions_sub,
rsvg_handle_rust_get_dpi_x,
rsvg_handle_rust_get_dpi_y,
rsvg_handle_rust_get_flags,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]