[librsvg] Move pixbuf_utils to the librsvg_c_api crate
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Move pixbuf_utils to the librsvg_c_api crate
- Date: Thu, 3 Oct 2019 15:54:00 +0000 (UTC)
commit 4df277869466fe28b6f95461657545c2b369d54a
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Oct 3 10:39:34 2019 -0500
Move pixbuf_utils to the librsvg_c_api crate
All those functions are either implementations for the deprectated
rsvg_pixbuf_*() functions, or utilities to implement
rsvg_handle_get_pixbuf_sub().
Makefile.am | 2 +-
librsvg/c_api.rs | 33 ++++++++++++++++++++-----
librsvg/lib.rs | 9 +++++++
{rsvg_internals/src => librsvg}/pixbuf_utils.rs | 11 +++------
rsvg_internals/src/handle.rs | 29 ----------------------
rsvg_internals/src/lib.rs | 13 +++++-----
6 files changed, 47 insertions(+), 50 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 7704d197..a83042c0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -79,7 +79,6 @@ LIBRSVG_INTERNALS_SRC = \
rsvg_internals/src/path_builder.rs \
rsvg_internals/src/path_parser.rs \
rsvg_internals/src/pattern.rs \
- rsvg_internals/src/pixbuf_utils.rs \
rsvg_internals/src/properties.rs \
rsvg_internals/src/property_bag.rs \
rsvg_internals/src/property_defs.rs \
@@ -122,6 +121,7 @@ LIBRSVG_C_API_SRC = \
librsvg/build.rs \
librsvg/c_api.rs \
librsvg/lib.rs \
+ librsvg/pixbuf_utils.rs \
$(NULL)
RUST_EXTRA = \
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index e084068b..51831e52 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -7,7 +7,7 @@ use std::slice;
use std::sync::Once;
use std::{f64, i32};
-use cairo;
+use cairo::{self, ImageSurface};
use cairo_sys;
use gdk_pixbuf::Pixbuf;
use gdk_pixbuf_sys;
@@ -36,9 +36,12 @@ use gobject_sys::{self, GEnumValue, GFlagsValue};
use rsvg_internals::{
rsvg_log, set_gerror, DefsLookupErrorKind, Dpi, Handle, IntrinsicDimensions, LoadOptions,
LoadingError, RenderingError, RsvgDimensionData, RsvgLength, RsvgPositionData, RsvgRectangle,
- RsvgSizeFunc, SizeCallback, RSVG_ERROR_FAILED,
+ RsvgSizeFunc, SizeCallback, RSVG_ERROR_FAILED, SharedImageSurface, SurfaceType,
};
+use crate::pixbuf_utils::{empty_pixbuf, pixbuf_from_surface};
+
+
mod handle_flags {
// The following is entirely stolen from the auto-generated code
// for GBindingFlags, from gtk-rs/glib/src/gobject/auto/flags.rs
@@ -608,9 +611,28 @@ impl CHandle {
fn get_pixbuf_sub(&self, id: Option<&str>) -> Result<Pixbuf, RenderingError> {
let handle = self.get_handle_ref()?;
let size_callback = self.size_callback.borrow();
- handle
- .get_pixbuf_sub(id, self.dpi.get(), &*size_callback, self.is_testing.get())
- .map_err(warn_on_invalid_id)
+ let dpi = self.dpi.get();
+ let is_testing = self.is_testing.get();
+
+ let dimensions = handle.get_dimensions(dpi, &size_callback, is_testing)?;
+
+ if dimensions.width == 0 || dimensions.height == 0 {
+ return empty_pixbuf();
+ }
+
+ let surface =
+ ImageSurface::create(cairo::Format::ARgb32, dimensions.width, dimensions.height)?;
+
+ {
+ let cr = cairo::Context::new(&surface);
+ handle
+ .render_cairo_sub(&cr, id, dpi, &size_callback, is_testing)
+ .map_err(warn_on_invalid_id)?;
+ }
+
+ let surface = SharedImageSurface::new(surface, SurfaceType::SRgb)?;
+
+ pixbuf_from_surface(&surface)
}
fn render_document(
@@ -1414,7 +1436,6 @@ pub fn rsvg_g_warning(msg: &str) {
}
}
-
pub fn rsvg_g_critical(msg: &str) {
unsafe {
extern "C" {
diff --git a/librsvg/lib.rs b/librsvg/lib.rs
index 20a4a39a..116203cb 100644
--- a/librsvg/lib.rs
+++ b/librsvg/lib.rs
@@ -2,6 +2,7 @@
#![allow(clippy::not_unsafe_ptr_arg_deref)]
#![allow(clippy::too_many_arguments)]
#![warn(unused)]
+#![cfg_attr(rustfmt, rustfmt_skip)]
pub use crate::c_api::{
rsvg_rust_error_get_type,
@@ -39,4 +40,12 @@ pub use crate::c_api::{
rsvg_rust_handle_write,
};
+pub use crate::pixbuf_utils::{
+ rsvg_rust_pixbuf_from_file_at_max_size,
+ rsvg_rust_pixbuf_from_file_at_size,
+ rsvg_rust_pixbuf_from_file_at_zoom,
+ rsvg_rust_pixbuf_from_file_at_zoom_with_max,
+};
+
mod c_api;
+mod pixbuf_utils;
diff --git a/rsvg_internals/src/pixbuf_utils.rs b/librsvg/pixbuf_utils.rs
similarity index 96%
rename from rsvg_internals/src/pixbuf_utils.rs
rename to librsvg/pixbuf_utils.rs
index 041ee1ad..5c452d32 100644
--- a/rsvg_internals/src/pixbuf_utils.rs
+++ b/librsvg/pixbuf_utils.rs
@@ -11,14 +11,9 @@ use glib_sys;
use libc;
use url::Url;
-use crate::dpi::Dpi;
-use crate::error::{set_gerror, LoadingError, RenderingError};
-use crate::handle::{Handle, LoadOptions, RsvgDimensionData, SizeCallback};
-use crate::rect::IRect;
-use crate::surface_utils::{
- iterators::Pixels,
- shared_surface::SharedImageSurface,
- shared_surface::SurfaceType,
+use rsvg_internals::{
+ set_gerror, Dpi, Handle, IRect, LoadOptions, LoadingError, Pixels, RenderingError,
+ RsvgDimensionData, SharedImageSurface, SizeCallback, SurfaceType,
};
fn pixbuf_new(width: i32, height: i32) -> Result<Pixbuf, RenderingError> {
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index d1107dd6..b3e91331 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -3,7 +3,6 @@ use std::ptr;
use std::rc::Rc;
use cairo::{self, ImageSurface, Status};
-use gdk_pixbuf::Pixbuf;
use gio;
use glib::{self, IsA};
use libc;
@@ -15,9 +14,7 @@ use crate::dpi::Dpi;
use crate::drawing_ctx::{DrawingCtx, RsvgRectangle};
use crate::error::{DefsLookupErrorKind, LoadingError, RenderingError};
use crate::node::{CascadedValues, RsvgNode};
-use crate::pixbuf_utils::{empty_pixbuf, pixbuf_from_surface};
use crate::structure::{IntrinsicDimensions, NodeSvg};
-use crate::surface_utils::{shared_surface::SharedImageSurface, shared_surface::SurfaceType};
use crate::svg::Svg;
use url::Url;
@@ -583,32 +580,6 @@ impl Handle {
res
}
- pub fn get_pixbuf_sub(
- &self,
- id: Option<&str>,
- dpi: Dpi,
- size_callback: &SizeCallback,
- is_testing: bool,
- ) -> Result<Pixbuf, RenderingError> {
- let dimensions = self.get_dimensions(dpi, size_callback, is_testing)?;
-
- if dimensions.width == 0 || dimensions.height == 0 {
- return empty_pixbuf();
- }
-
- let surface =
- ImageSurface::create(cairo::Format::ARgb32, dimensions.width, dimensions.height)?;
-
- {
- let cr = cairo::Context::new(&surface);
- self.render_cairo_sub(&cr, id, dpi, size_callback, is_testing)?;
- }
-
- let surface = SharedImageSurface::new(surface, SurfaceType::SRgb)?;
-
- pixbuf_from_surface(&surface)
- }
-
pub fn get_intrinsic_dimensions(&self) -> IntrinsicDimensions {
self.svg.get_intrinsic_dimensions()
}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 4257232a..6d2276d2 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -22,15 +22,17 @@ pub use crate::handle::{
pub use crate::length::{Length, LengthUnit, RsvgLength};
-pub use crate::pixbuf_utils::{
- rsvg_rust_pixbuf_from_file_at_max_size, rsvg_rust_pixbuf_from_file_at_size,
- rsvg_rust_pixbuf_from_file_at_zoom, rsvg_rust_pixbuf_from_file_at_zoom_with_max,
-};
-
pub use crate::rect::IRect;
pub use crate::structure::IntrinsicDimensions;
+pub use crate::surface_utils::{
+ iterators::Pixels,
+ shared_surface::{
+ SharedImageSurface, SurfaceType,
+ },
+};
+
#[macro_use]
pub mod log;
@@ -74,7 +76,6 @@ mod parsers;
mod path_builder;
mod path_parser;
mod pattern;
-mod pixbuf_utils;
mod properties;
mod property_bag;
mod property_defs;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]