[librsvg: 4/5] SharedImageSurface::from_pixbuf(): Call surf.set_mime_data() here, not in the single caller
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 4/5] SharedImageSurface::from_pixbuf(): Call surf.set_mime_data() here, not in the single caller
- Date: Thu, 7 Mar 2019 23:15:29 +0000 (UTC)
commit a58915190887d8cc61bb7ad2d8af84bc9465002b
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Mar 7 17:13:09 2019 -0600
SharedImageSurface::from_pixbuf(): Call surf.set_mime_data() here, not in the single caller
And use the safe binding to that function, not cairo-sys-rs directly.
Thanks to Sebastian Dröge for showing me how AsRef<[u8]> really works :)
rsvg_internals/src/surface_utils/shared_surface.rs | 14 +++++++-
rsvg_internals/src/svg.rs | 40 ++++------------------
2 files changed, 20 insertions(+), 34 deletions(-)
---
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs
b/rsvg_internals/src/surface_utils/shared_surface.rs
index 1319fb11..96c6bf2f 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -172,7 +172,11 @@ impl SharedImageSurface {
}
}
- pub fn from_pixbuf(pixbuf: &Pixbuf) -> Result<SharedImageSurface, cairo::Status> {
+ pub fn from_pixbuf(
+ pixbuf: &Pixbuf,
+ data: Option<Vec<u8>>,
+ content_type: Option<&str>,
+ ) -> Result<SharedImageSurface, cairo::Status> {
assert!(pixbuf.get_colorspace() == Colorspace::Rgb);
let n_channels = pixbuf.get_n_channels();
@@ -236,6 +240,14 @@ impl SharedImageSurface {
}
}
+ match (data, content_type) {
+ (Some(bytes), Some(content_type)) => {
+ surf.set_mime_data(content_type, bytes)?;
+ }
+
+ (_, _) => (),
+ }
+
Self::new(surf, SurfaceType::SRgb)
}
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index 520f7518..cd03fe44 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -1,6 +1,5 @@
use gdk_pixbuf::{PixbufLoader, PixbufLoaderExt};
use gio;
-use glib::translate::*;
use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
@@ -201,39 +200,14 @@ fn load_image(
let pixbuf = loader.get_pixbuf().ok_or(LoadingError::Unknown)?;
- let surface = SharedImageSurface::from_pixbuf(&pixbuf)?;
-
- if load_options.flags.keep_image_data {
- if let Some(mime_type) = content_type {
- let data_ptr = ToGlibContainerFromSlice::to_glib_full_from_slice(&bytes);
-
- extern "C" {
- fn cairo_surface_set_mime_data(
- surface: *mut cairo_sys::cairo_surface_t,
- mime_type: *const libc::c_char,
- data: *mut libc::c_char,
- length: libc::c_ulong,
- destroy: cairo_sys::cairo_destroy_func_t,
- closure: *mut libc::c_void,
- ) -> cairo_sys::cairo_status_t;
- }
+ let bytes = if load_options.flags.keep_image_data {
+ Some(bytes)
+ } else {
+ None
+ };
- unsafe {
- let status = cairo_surface_set_mime_data(
- surface.to_glib_none().0,
- mime_type.to_glib_none().0,
- data_ptr as *mut _,
- bytes.len() as libc::c_ulong,
- Some(glib_sys::g_free),
- data_ptr as *mut _,
- );
-
- if status != cairo_sys::STATUS_SUCCESS {
- return Err(LoadingError::Cairo(status.into()));
- }
- }
- }
- }
+ let surface =
+ SharedImageSurface::from_pixbuf(&pixbuf, bytes, content_type.as_ref().map(String::as_str))?;
Ok(surface)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]