[librsvg] rsvg_handle_set_base_gfile(): Port the implementation to Rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] rsvg_handle_set_base_gfile(): Port the implementation to Rust
- Date: Wed, 9 Jan 2019 00:57:09 +0000 (UTC)
commit 8de888f02f2bcc5ec36f767355def6c61f915552
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Jan 8 17:48:21 2019 -0600
rsvg_handle_set_base_gfile(): Port the implementation to Rust
librsvg/rsvg-handle.c | 7 ++-----
rsvg_internals/src/handle.rs | 24 +++++++++++++++++++++++-
rsvg_internals/src/lib.rs | 1 +
3 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index adb85776..082c57a9 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -151,6 +151,7 @@ extern double rsvg_handle_rust_get_dpi_y (RsvgHandleRust *raw_handle);
extern void rsvg_handle_rust_set_dpi_x (RsvgHandleRust *raw_handle, double dpi_x);
extern void rsvg_handle_rust_set_dpi_y (RsvgHandleRust *raw_handle, double dpi_y);
extern void rsvg_handle_rust_set_base_url (RsvgHandleRust *raw_handle, const char *uri);
+extern void rsvg_handle_rust_set_base_gfile (RsvgHandleRust *raw_handle, GFile *file);
extern const char *rsvg_handle_rust_get_base_url (RsvgHandleRust *raw_handle);
extern GFile *rsvg_handle_rust_get_base_gfile (RsvgHandleRust *raw_handle);
extern guint rsvg_handle_rust_get_flags (RsvgHandleRust *raw_handle);
@@ -817,14 +818,10 @@ void
rsvg_handle_set_base_gfile (RsvgHandle *handle,
GFile *base_file)
{
- char *uri;
-
g_return_if_fail (RSVG_IS_HANDLE (handle));
g_return_if_fail (G_IS_FILE (base_file));
- uri = g_file_get_uri (base_file);
- rsvg_handle_rust_set_base_url (handle->priv->rust_handle, uri);
- g_free (uri);
+ rsvg_handle_rust_set_base_gfile (handle->priv->rust_handle, base_file);
}
/**
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index e2e33821..16497567 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -9,7 +9,7 @@ use cairo::{self, ImageSurface, Status};
use cairo_sys;
use gdk_pixbuf::{Colorspace, Pixbuf, PixbufLoader, PixbufLoaderExt};
use gdk_pixbuf_sys;
-use gio::File as GFile;
+use gio::{File as GFile, FileExt};
use gio_sys;
use glib::translate::*;
use glib_sys;
@@ -194,6 +194,14 @@ impl Handle {
}
}
+ fn set_base_gfile(&self, file: &GFile) {
+ if let Some(uri) = file.get_uri() {
+ self.set_base_url(&uri);
+ } else {
+ rsvg_g_warning("file has no URI; will not set the base URI");
+ }
+ }
+
pub fn read_stream_sync(
&mut self,
handle: *mut RsvgHandle,
@@ -751,6 +759,20 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_base_gfile(
}
}
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_handle_rust_set_base_gfile(
+ raw_handle: *const Handle,
+ raw_gfile: *mut gio_sys::GFile,
+) {
+ let handle = &*raw_handle;
+
+ assert!(!raw_gfile.is_null());
+
+ let file: GFile = from_glib_none(raw_gfile);
+
+ handle.set_base_gfile(&file);
+}
+
#[no_mangle]
pub unsafe extern "C" fn rsvg_handle_rust_get_base_url(
raw_handle: *const Handle,
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 66637c0a..4ee9766c 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -55,6 +55,7 @@ pub use handle::{
rsvg_handle_rust_new,
rsvg_handle_rust_read_stream_sync,
rsvg_handle_rust_render_cairo_sub,
+ rsvg_handle_rust_set_base_gfile,
rsvg_handle_rust_set_base_url,
rsvg_handle_rust_set_dpi_x,
rsvg_handle_rust_set_dpi_y,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]