[librsvg: 11/14] handle: move rsvg_handle_get_dimensions to rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 11/14] handle: move rsvg_handle_get_dimensions to rust
- Date: Sun, 6 Jan 2019 03:25:44 +0000 (UTC)
commit a499355e34e501bd8b162d8ad6ec372e262222e7
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jan 5 23:18:43 2019 +0100
handle: move rsvg_handle_get_dimensions to rust
This includes the in_loop check
librsvg/rsvg-handle.c | 20 +++-----------------
rsvg_internals/src/handle.rs | 25 +++++++++++++++++++++++++
rsvg_internals/src/lib.rs | 1 +
3 files changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index c72fca47..31eb2e73 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -170,6 +170,8 @@ 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 void rsvg_handle_rust_get_dimensions (RsvgHandle *handle,
+ RsvgDimensionData *dimension_data);
extern gboolean rsvg_handle_rust_get_dimensions_sub (RsvgHandle *handle,
RsvgDimensionData *dimension_data,
const char *id);
@@ -225,8 +227,6 @@ extern void rsvg_handle_rust_set_size_closure (RsvgHandleRust *raw_handle, RsvgS
struct RsvgHandlePrivate {
gchar *base_uri; // Keep this here; since rsvg_handle_get_base_uri() returns a const char *
- gboolean in_loop; /* see get_dimension() */
-
RsvgHandleRust *rust_handle;
};
@@ -253,9 +253,6 @@ static void
rsvg_handle_init (RsvgHandle * self)
{
self->priv = rsvg_handle_get_instance_private (self);
-
- self->priv->in_loop = FALSE;
-
self->priv->rust_handle = rsvg_handle_rust_new();
}
@@ -1038,18 +1035,7 @@ rsvg_handle_get_dimensions (RsvgHandle * handle, RsvgDimensionData * dimension_d
return;
}
- /* This function is probably called from the cairo_render functions.
- * To prevent an infinite loop we are saving the state.
- */
- if (!handle->priv->in_loop) {
- handle->priv->in_loop = TRUE;
- rsvg_handle_get_dimensions_sub (handle, dimension_data, NULL);
- handle->priv->in_loop = FALSE;
- } else {
- /* Called within the size function, so return a standard size */
- dimension_data->em = dimension_data->width = 1;
- dimension_data->ex = dimension_data->height = 1;
- }
+ rsvg_handle_rust_get_dimensions (handle, dimension_data);
}
/**
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index c397cdc2..d5f1a6bb 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -104,6 +104,7 @@ pub struct Handle {
load_state: Cell<LoadState>,
load: RefCell<Option<LoadContext>>,
size_closure: *mut RsvgSizeClosure,
+ in_loop: Cell<bool>,
is_testing: Cell<bool>,
}
@@ -117,6 +118,7 @@ impl Handle {
load_state: Cell::new(LoadState::Start),
load: RefCell::new(None),
size_closure: ptr::null_mut(),
+ in_loop: Cell::new(false),
is_testing: Cell::new(false),
}
}
@@ -1058,6 +1060,29 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_pixbuf_sub(
}
}
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_get_dimensions(
+ handle: *mut RsvgHandle,
+ dimension_data: *mut RsvgDimensionData,
+) {
+ let rhandle = get_rust_handle(handle);
+
+ // This function is probably called from the cairo_render functions.
+ // To prevent an infinite loop we are saving the state.
+ if rhandle.in_loop.get() {
+ // Called within the size function, so return a standard size
+ (*dimension_data).width = 1;
+ (*dimension_data).height = 1;
+ (*dimension_data).em = 1.0;
+ (*dimension_data).ex = 1.0;
+ return;
+ }
+
+ rhandle.in_loop.set(true);
+ rsvg_handle_rust_get_dimensions_sub(handle, dimension_data, ptr::null());
+ rhandle.in_loop.set(false);
+}
+
#[no_mangle]
pub unsafe extern "C" fn rsvg_handle_rust_get_dimensions_sub(
handle: *mut RsvgHandle,
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index be0da3a1..09641fed 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -40,6 +40,7 @@ pub use handle::{
rsvg_handle_rust_close,
rsvg_handle_rust_free,
rsvg_handle_rust_get_base_gfile,
+ rsvg_handle_rust_get_dimensions,
rsvg_handle_rust_get_dimensions_sub,
rsvg_handle_rust_get_dpi_x,
rsvg_handle_rust_get_dpi_y,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]