[librsvg: 1/2] Handle: move LoadFlags to c_api
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/2] Handle: move LoadFlags to c_api
- Date: Tue, 9 Apr 2019 23:18:38 +0000 (UTC)
commit 127de3eb72dbbad0649f691d9e1e94427868c816
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Apr 9 20:31:52 2019 +0200
Handle: move LoadFlags to c_api
The extra struct is needed only in c_api where we need to convert
to/from C flags.
librsvg_crate/src/lib.rs | 13 ++++---------
rsvg_internals/src/c_api.rs | 13 +++++++++++--
rsvg_internals/src/handle.rs | 36 +++++++++++++++++++++---------------
rsvg_internals/src/lib.rs | 2 +-
rsvg_internals/src/pixbuf_utils.rs | 4 ++--
rsvg_internals/src/svg.rs | 2 +-
rsvg_internals/src/xml.rs | 2 +-
rsvg_internals/src/xml2_load.rs | 9 ++++-----
8 files changed, 45 insertions(+), 36 deletions(-)
---
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index 7cfc7dcc..f0b6cf6c 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -98,7 +98,7 @@ use std::path::Path;
use gio::{Cancellable, FileExt};
use glib::object::Cast;
-use rsvg_internals::{Dpi, Handle, LoadFlags};
+use rsvg_internals::{Dpi, Handle};
pub use rsvg_internals::{
DefsLookupErrorKind, HrefError, Length, LengthUnit, LoadOptions, LoadingError, RenderingError,
@@ -208,13 +208,6 @@ impl Loader {
self
}
- fn load_flags(&self) -> LoadFlags {
- LoadFlags {
- unlimited_size: self.unlimited_size,
- keep_image_data: self.keep_image_data,
- }
- }
-
/// Reads an SVG file from `path`.
///
/// # Example:
@@ -285,7 +278,9 @@ impl Loader {
None
};
- let load_options = LoadOptions::new(self.load_flags(), base_url);
+ let load_options = LoadOptions::new(base_url)
+ .with_unlimited_size(self.unlimited_size)
+ .keep_image_data(self.keep_image_data);
Ok(SvgHandle(Handle::from_stream(
&load_options,
diff --git a/rsvg_internals/src/c_api.rs b/rsvg_internals/src/c_api.rs
index 0a7bde4f..597148a5 100644
--- a/rsvg_internals/src/c_api.rs
+++ b/rsvg_internals/src/c_api.rs
@@ -27,7 +27,7 @@ use gobject_sys::{self, GEnumValue, GFlagsValue};
use crate::dpi::Dpi;
use crate::drawing_ctx::RsvgRectangle;
use crate::error::{set_gerror, LoadingError, RenderingError, RSVG_ERROR_FAILED};
-use crate::handle::{Handle, LoadFlags, LoadOptions};
+use crate::handle::{Handle, LoadOptions};
use crate::length::RsvgLength;
use crate::structure::IntrinsicDimensions;
use crate::util::rsvg_g_warning;
@@ -89,6 +89,12 @@ mod handle_flags {
}
}
+#[derive(Default, Copy, Clone)]
+struct LoadFlags {
+ pub unlimited_size: bool,
+ pub keep_image_data: bool,
+}
+
pub use self::handle_flags::*;
impl From<HandleFlags> for LoadFlags {
@@ -509,7 +515,10 @@ impl CHandle {
}
fn load_options(&self) -> LoadOptions {
- LoadOptions::new(self.load_flags.get(), self.base_url.borrow().clone())
+ let flags = self.load_flags.get();
+ LoadOptions::new(self.base_url.borrow().clone())
+ .with_unlimited_size(flags.unlimited_size)
+ .keep_image_data(flags.keep_image_data)
}
pub fn set_size_callback(
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index a2c7f50a..9a8a7f1b 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -20,39 +20,45 @@ use crate::svg::Svg;
use crate::util::rsvg_g_warning;
use url::Url;
-/// Flags used during loading
-///
-/// We communicate these to/from the C code with a HandleFlags
-/// and this struct provides to_flags() and from_flags() methods.
-#[derive(Default, Copy, Clone)]
-pub struct LoadFlags {
+#[derive(Clone)]
+pub struct LoadOptions {
+ /// Base URL
+ pub base_url: Option<Url>,
+
/// Whether to turn off size limits in libxml2
pub unlimited_size: bool,
/// Whether to keep original (undecoded) image data to embed in Cairo PDF surfaces
pub keep_image_data: bool,
-}
-#[derive(Clone)]
-pub struct LoadOptions {
- pub flags: LoadFlags,
- pub base_url: Option<Url>,
locale: Locale,
}
impl LoadOptions {
- pub fn new(flags: LoadFlags, base_url: Option<Url>) -> LoadOptions {
+ pub fn new(base_url: Option<Url>) -> Self {
LoadOptions {
- flags,
base_url,
+ unlimited_size: false,
+ keep_image_data: false,
locale: locale_from_environment(),
}
}
- pub fn copy_with_base_url(&self, base_url: &AllowedUrl) -> LoadOptions {
+ pub fn with_unlimited_size(mut self, unlimited: bool) -> Self {
+ self.unlimited_size = unlimited;
+ self
+ }
+
+ pub fn keep_image_data(mut self, keep: bool) -> Self {
+ self.keep_image_data = keep;
+ self
+ }
+
+ pub fn copy_with_base_url(&self, base_url: &AllowedUrl) -> Self {
LoadOptions {
- flags: self.flags,
base_url: Some((*base_url).clone()),
+ unlimited_size: self.unlimited_size,
+ keep_image_data: self.keep_image_data,
locale: self.locale.clone(),
}
}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index e5fce48b..7be0e9b1 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -60,7 +60,7 @@ pub use crate::error::{
RenderingError,
};
-pub use crate::handle::{Handle, LoadFlags, LoadOptions};
+pub use crate::handle::{Handle, LoadOptions};
pub use crate::length::{Length, LengthUnit};
diff --git a/rsvg_internals/src/pixbuf_utils.rs b/rsvg_internals/src/pixbuf_utils.rs
index 1a5995cd..c2f25ab1 100644
--- a/rsvg_internals/src/pixbuf_utils.rs
+++ b/rsvg_internals/src/pixbuf_utils.rs
@@ -15,7 +15,7 @@ use url::Url;
use crate::c_api::{RsvgDimensionData, SizeCallback};
use crate::dpi::Dpi;
use crate::error::{set_gerror, LoadingError, RenderingError};
-use crate::handle::{Handle, LoadFlags, LoadOptions};
+use crate::handle::{Handle, LoadOptions};
use crate::rect::IRect;
use crate::surface_utils::{
iterators::Pixels, shared_surface::SharedImageSurface, shared_surface::SurfaceType,
@@ -223,7 +223,7 @@ fn pixbuf_from_file_with_size_mode(
}
};
- let load_options = LoadOptions::new(LoadFlags::default(), Some(base_url));
+ let load_options = LoadOptions::new(Some(base_url));
let cancellable: Option<&gio::Cancellable> = None;
let handle = match file
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index 38141f52..563578b6 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -199,7 +199,7 @@ fn load_image(
let pixbuf = loader.get_pixbuf().ok_or(LoadingError::Unknown)?;
- let bytes = if load_options.flags.keep_image_data {
+ let bytes = if load_options.keep_image_data {
Some(bytes)
} else {
None
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 69249133..2588bc03 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -492,7 +492,7 @@ impl XmlState {
stream: gio::InputStream,
cancellable: Option<&gio::Cancellable>,
) -> Result<(), ParseFromStreamError> {
- Xml2Parser::from_stream(self, self.load_options.flags, stream, cancellable)
+ Xml2Parser::from_stream(self, self.load_options.unlimited_size, stream, cancellable)
.and_then(|parser| parser.parse())
}
diff --git a/rsvg_internals/src/xml2_load.rs b/rsvg_internals/src/xml2_load.rs
index eb6eb079..798c4b9b 100644
--- a/rsvg_internals/src/xml2_load.rs
+++ b/rsvg_internals/src/xml2_load.rs
@@ -15,7 +15,6 @@ use std::sync::Once;
use glib::translate::*;
use crate::error::LoadingError;
-use crate::handle::LoadFlags;
use crate::property_bag::PropertyBag;
use crate::util::cstr;
use crate::util::utf8_cstr;
@@ -214,10 +213,10 @@ unsafe extern "C" fn sax_get_parameter_entity_cb(
sax_get_entity_cb(ctx, name)
}
-fn set_xml_parse_options(parser: xmlParserCtxtPtr, load_flags: LoadFlags) {
+fn set_xml_parse_options(parser: xmlParserCtxtPtr, unlimited_size: bool) {
let mut options: libc::c_int = XML_PARSE_NONET | XML_PARSE_BIG_LINES;
- if load_flags.unlimited_size {
+ if unlimited_size {
options |= XML_PARSE_HUGE;
}
@@ -319,7 +318,7 @@ pub struct Xml2Parser {
impl Xml2Parser {
pub fn from_stream(
xml: &mut XmlState,
- load_flags: LoadFlags,
+ unlimited_size: bool,
stream: gio::InputStream,
cancellable: Option<&gio::Cancellable>,
) -> Result<Xml2Parser, ParseFromStreamError> {
@@ -357,7 +356,7 @@ impl Xml2Parser {
// stream_ctx_close function
Err(ParseFromStreamError::CouldNotCreateXmlParser)
} else {
- set_xml_parse_options(parser, load_flags);
+ set_xml_parse_options(parser, unlimited_size);
Ok(Xml2Parser { parser, gio_error })
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]