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.
parent a78864b7
Pipeline #43687 passed with stages
in 32 minutes and 53 seconds
......@@ -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)
{
......
......@@ -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);
......
......@@ -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)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment