rsvg_handle_new_from_stream_sync(): Port to Rust

This is kind of horrible right now, as the rustified version is harder
to read.  However, I think porting these convenience constructors will
make it easier to see a better pattern for Rust construction in
general... and to integrate rsvg-rs into the build.
parent 157b2cbb
......@@ -962,6 +962,7 @@ dependencies = [
"gio-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
"language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
......@@ -181,6 +181,11 @@ extern void rsvg_handle_rust_set_size_callback (RsvgHandleRust *raw_handle,
RsvgSizeFunc size_func,
gpointer user_data,
GDestroyNotify destroy_notify);
extern RsvgHandle *rsvg_handle_rust_new_from_stream_sync (GInputStream *input_stream,
GFile *base_file,
RsvgHandleFlags flags,
GCancellable *cancellable,
GError **error);
struct RsvgHandlePrivate {
RsvgHandleRust *rust_handle;
......@@ -613,24 +618,16 @@ rsvg_handle_new_from_stream_sync (GInputStream *input_stream,
GCancellable *cancellable,
GError **error)
{
RsvgHandle *handle;
g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), NULL);
g_return_val_if_fail (base_file == NULL || G_IS_FILE (base_file), NULL);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
handle = rsvg_handle_new_with_flags (flags);
if (base_file)
rsvg_handle_set_base_gfile (handle, base_file);
if (!rsvg_handle_read_stream_sync (handle, input_stream, cancellable, error)) {
g_object_unref (handle);
return NULL;
}
return handle;
return rsvg_handle_rust_new_from_stream_sync (input_stream,
base_file,
flags,
cancellable,
error);
}
/**
......
......@@ -33,6 +33,7 @@ gio = { version="0.5.1", features=["v2_48"] } # per configure.ac
gio-sys = "0.7.0"
glib = "0.6.0"
glib-sys = "0.7.0"
gobject-sys = "0.7.0"
itertools = "0.7.4"
language-tags = "0.2.2"
lazy_static = "1.0.0"
......
......@@ -13,6 +13,7 @@ use gio::{File as GFile, FileExt};
use gio_sys;
use glib::translate::*;
use glib_sys;
use gobject_sys;
use libc;
use url::Url;
......@@ -574,6 +575,8 @@ impl LoadFlags {
#[allow(improper_ctypes)]
extern "C" {
fn rsvg_handle_new_with_flags(flags: u32) -> *mut RsvgHandle;
fn rsvg_handle_new_from_gfile_sync(
file: *const gio_sys::GFile,
flags: u32,
......@@ -1156,3 +1159,34 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_position_sub(
res
}
#[no_mangle]
pub unsafe extern "C" fn rsvg_handle_rust_new_from_stream_sync(
input_stream: *mut gio_sys::GInputStream,
base_file: *mut gio_sys::GFile,
flags: u32,
cancellable: *mut gio_sys::GCancellable,
error: *mut *mut glib_sys::GError,
) -> *mut RsvgHandle {
let raw_handle = rsvg_handle_new_with_flags(flags);
let rhandle = get_rust_handle(raw_handle);
if !base_file.is_null() {
let file: GFile = from_glib_none(base_file);
rhandle.set_base_gfile(&file);
}
let stream = from_glib_none(input_stream);
let cancellable = from_glib_none(cancellable);
match rhandle.read_stream_sync(raw_handle, stream, cancellable) {
Ok(()) => raw_handle,
Err(e) => {
set_gerror(error, 0, &format!("{}", e));
gobject_sys::g_object_unref(raw_handle as *mut _);
ptr::null_mut()
}
}
}
......@@ -16,6 +16,7 @@ extern crate gio;
extern crate gio_sys;
extern crate glib;
extern crate glib_sys;
extern crate gobject_sys;
extern crate itertools;
extern crate language_tags;
extern crate libc;
......@@ -53,6 +54,7 @@ pub use handle::{
rsvg_handle_rust_get_position_sub,
rsvg_handle_rust_has_sub,
rsvg_handle_rust_new,
rsvg_handle_rust_new_from_stream_sync,
rsvg_handle_rust_read_stream_sync,
rsvg_handle_rust_render_cairo_sub,
rsvg_handle_rust_set_base_gfile,
......
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