[librsvg] handle::load_extern(): Port to Rust



commit f82daec25ba954f503cad9044e2e7e726d662574
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Nov 30 19:53:41 2018 -0600

    handle::load_extern(): Port to Rust
    
    We actually call rsvg_handle_new_from_gfile_sync() in there.  The
    snake starts eating its own tail.  Yum, yum.

 librsvg/rsvg-handle.c        | 31 ++++++++++++-------------------
 librsvg/rsvg-private.h       | 10 ++++++----
 rsvg_internals/src/handle.rs | 28 ++++++++++++++++++++++++----
 3 files changed, 42 insertions(+), 27 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index fecd32d8..17ab2934 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -1011,12 +1011,24 @@ rsvg_handle_get_desc (RsvgHandle * handle)
     return NULL;
 }
 
+guint
+rsvg_handle_get_flags (RsvgHandle *handle)
+{
+    return (guint) handle->priv->flags;
+}
+
 RsvgDefs *
 rsvg_handle_get_defs (RsvgHandle *handle)
 {
     return handle->priv->defs;
 }
 
+RsvgTree *
+rsvg_handle_get_tree (RsvgHandle *handle)
+{
+    return handle->priv->tree;
+}
+
 RsvgHandleRust *
 rsvg_handle_get_rust (RsvgHandle *handle)
 {
@@ -1029,25 +1041,6 @@ rsvg_handle_get_css_styles (RsvgHandle *handle)
     return handle->priv->css_styles;
 }
 
-RsvgHandle *
-rsvg_handle_load_extern (RsvgHandle *handle, GFile *file)
-{
-    RsvgHandle *res;
-
-    res = rsvg_handle_new_from_gfile_sync (file,
-                                           handle->priv->flags,
-                                           NULL,
-                                           NULL);
-
-    if (res) {
-        rsvg_tree_cascade (res->priv->tree);
-    } else {
-        /* FIXME: rsvg_log!("could not load external resource"); */
-    }
-
-    return res;
-}
-
 gboolean
 rsvg_handle_keep_image_data (RsvgHandle *handle)
 {
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 00bcf203..f934b06b 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -243,9 +243,15 @@ void rsvg_defs_free (RsvgDefs *defs);
 G_GNUC_INTERNAL
 RsvgNode *rsvg_defs_lookup (const RsvgDefs * defs, RsvgHandle *handle, const char *name);
 
+G_GNUC_INTERNAL
+guint rsvg_handle_get_flags (RsvgHandle *handle);
+
 G_GNUC_INTERNAL
 RsvgDefs *rsvg_handle_get_defs (RsvgHandle *handle);
 
+G_GNUC_INTERNAL
+RsvgTree *rsvg_handle_get_tree (RsvgHandle *handle);
+
 G_GNUC_INTERNAL
 RsvgHandleRust *rsvg_handle_get_rust (RsvgHandle *handle);
 
@@ -269,10 +275,6 @@ void rsvg_handle_rust_set_base_url (RsvgHandleRust *raw_handle,
 G_GNUC_INTERNAL
 GFile *rsvg_handle_rust_get_base_gfile (RsvgHandleRust *raw_handle);
 
-G_GNUC_INTERNAL
-RsvgHandle *rsvg_handle_load_extern (RsvgHandle *handle,
-                                     GFile *file);
-
 G_GNUC_INTERNAL
 gboolean rsvg_handle_keep_image_data (RsvgHandle *handle);
 
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 6ea69552..9d8ce5f7 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -18,6 +18,7 @@ use defs::{Defs, RsvgDefs};
 use error::{set_gerror, LoadingError};
 use io;
 use surface_utils::shared_surface::SharedImageSurface;
+use tree::{RsvgTree, Tree};
 
 pub enum RsvgHandle {}
 
@@ -37,12 +38,16 @@ impl Handle {
 
 #[allow(improper_ctypes)]
 extern "C" {
+    fn rsvg_handle_get_flags(handle: *const RsvgHandle) -> u32;
     fn rsvg_handle_get_defs(handle: *const RsvgHandle) -> *const RsvgDefs;
+    fn rsvg_handle_get_tree(handle: *const RsvgHandle) -> *const RsvgTree;
 
-    fn rsvg_handle_load_extern(
-        handle: *const RsvgHandle,
+    fn rsvg_handle_new_from_gfile_sync(
         file: *const gio_sys::GFile,
-    ) -> *const RsvgHandle;
+        flags: u32,
+        cancellable: *const gio_sys::GCancellable,
+        error: *mut *mut glib_sys::GError,
+    ) -> *mut RsvgHandle;
 
     fn rsvg_handle_keep_image_data(handle: *const RsvgHandle) -> glib_sys::gboolean;
 
@@ -63,15 +68,30 @@ pub fn get_defs<'a>(handle: *const RsvgHandle) -> &'a mut Defs {
     }
 }
 
+pub fn get_tree<'a>(handle: *const RsvgHandle) -> &'a Tree {
+    unsafe {
+        let t = rsvg_handle_get_tree(handle);
+        &*(t as *mut Tree)
+    }
+}
+
 pub fn load_extern(handle: *const RsvgHandle, aurl: &AllowedUrl) -> Result<*const RsvgHandle, ()> {
     unsafe {
         let file = GFile::new_for_uri(aurl.url().as_str());
 
-        let res = rsvg_handle_load_extern(handle, file.to_glib_none().0);
+        let res = rsvg_handle_new_from_gfile_sync(
+            file.to_glib_none().0,
+            rsvg_handle_get_flags(handle),
+            ptr::null(),
+            ptr::null_mut(),
+        );
 
         if res.is_null() {
             Err(())
         } else {
+            let tree = get_tree(res);
+            tree.cascade();
+
             Ok(res)
         }
     }


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