[librsvg] load_css(): Move to css.rs
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] load_css(): Move to css.rs
- Date: Thu, 10 Jan 2019 23:42:32 +0000 (UTC)
commit acf9af0357bb32b8428506e4f2ff607575aa4116
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Jan 10 17:26:36 2019 -0600
load_css(): Move to css.rs
rsvg_internals/src/css.rs | 37 +++++++++++++++++++++++++++++++++++--
rsvg_internals/src/defs.rs | 4 +++-
rsvg_internals/src/handle.rs | 38 --------------------------------------
rsvg_internals/src/io.rs | 6 +++++-
rsvg_internals/src/xml.rs | 2 +-
5 files changed, 44 insertions(+), 43 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index bc4d4152..1b17b5f9 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -12,7 +12,8 @@ use glib_sys::{gboolean, gpointer, GList};
use allowed_url::AllowedUrl;
use attributes::Attribute;
use croco::*;
-use handle;
+use error::LoadingError;
+use io::{self, BinaryData};
use state::State;
use util::utf8_cstr;
@@ -137,6 +138,38 @@ fn init_cr_doc_handler(handler: &mut CRDocHandler) {
handler.unrecoverable_error = Some(css_unrecoverable_error);
}
+// This function just slurps CSS data from a possibly-relative href
+// and parses it. We'll move it to a better place in the end.
+pub fn load_css(css_styles: &mut CssStyles, aurl: &AllowedUrl) -> Result<(), LoadingError> {
+ io::acquire_data(aurl, None)
+ .and_then(|data| {
+ let BinaryData {
+ data: bytes,
+ content_type,
+ } = data;
+
+ if content_type.as_ref().map(String::as_ref) == Some("text/css") {
+ Ok(bytes)
+ } else {
+ rsvg_log!("\"{}\" is not of type text/css; ignoring", aurl);
+ Err(LoadingError::BadCss)
+ }
+ })
+ .and_then(|bytes| {
+ String::from_utf8(bytes).map_err(|_| {
+ rsvg_log!(
+ "\"{}\" does not contain valid UTF-8 CSS data; ignoring",
+ aurl
+ );
+ LoadingError::BadCss
+ })
+ })
+ .and_then(|utf8| {
+ parse_into_css_styles(css_styles, Some(aurl.url().clone()), &utf8);
+ Ok(()) // FIXME: return CSS parsing errors
+ })
+}
+
unsafe extern "C" fn css_import_style(
a_this: *mut CRDocHandler,
_a_media_list: *mut GList,
@@ -155,7 +188,7 @@ unsafe extern "C" fn css_import_style(
if let Ok(aurl) = AllowedUrl::from_href(uri, handler_data.base_url.as_ref()) {
// FIXME: handle CSS errors
- let _ = handle::load_css(handler_data.css_styles, &aurl);
+ let _ = load_css(handler_data.css_styles, &aurl);
} else {
rsvg_log!("disallowed URL \"{}\" for importing CSS", uri);
}
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index 5c0374a4..73000cb5 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -56,7 +56,9 @@ impl Defs {
impl Drop for Defs {
fn drop(&mut self) {
for (_, handle) in self.externs.iter() {
- unsafe { gobject_sys::g_object_unref(*handle as *mut _); }
+ unsafe {
+ gobject_sys::g_object_unref(*handle as *mut _);
+ }
}
}
}
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index b99b3488..e0adf6ee 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -20,7 +20,6 @@ use libc;
use url::Url;
use allowed_url::AllowedUrl;
-use css::{self, CssStyles};
use defs::Href;
use dpi::Dpi;
use drawing_ctx::{DrawingCtx, RsvgRectangle};
@@ -692,11 +691,6 @@ pub fn get_base_url<'a>(handle: *const RsvgHandle) -> Ref<'a, Option<Url>> {
rhandle.base_url.borrow()
}
-pub struct BinaryData {
- pub data: Vec<u8>,
- pub content_type: Option<String>,
-}
-
pub fn load_image_to_surface(
load_options: &LoadOptions,
url: &str,
@@ -758,38 +752,6 @@ pub fn load_image_to_surface(
Ok(surface)
}
-// This function just slurps CSS data from a possibly-relative href
-// and parses it. We'll move it to a better place in the end.
-pub fn load_css(css_styles: &mut CssStyles, aurl: &AllowedUrl) -> Result<(), LoadingError> {
- io::acquire_data(aurl, None)
- .and_then(|data| {
- let BinaryData {
- data: bytes,
- content_type,
- } = data;
-
- if content_type.as_ref().map(String::as_ref) == Some("text/css") {
- Ok(bytes)
- } else {
- rsvg_log!("\"{}\" is not of type text/css; ignoring", aurl);
- Err(LoadingError::BadCss)
- }
- })
- .and_then(|bytes| {
- String::from_utf8(bytes).map_err(|_| {
- rsvg_log!(
- "\"{}\" does not contain valid UTF-8 CSS data; ignoring",
- aurl
- );
- LoadingError::BadCss
- })
- })
- .and_then(|utf8| {
- css::parse_into_css_styles(css_styles, Some(aurl.url().clone()), &utf8);
- Ok(()) // FIXME: return CSS parsing errors
- })
-}
-
#[no_mangle]
pub unsafe extern "C" fn rsvg_handle_rust_new() -> *mut Handle {
Box::into_raw(Box::new(Handle::new()))
diff --git a/rsvg_internals/src/io.rs b/rsvg_internals/src/io.rs
index ea07d105..ea8a66a9 100644
--- a/rsvg_internals/src/io.rs
+++ b/rsvg_internals/src/io.rs
@@ -17,7 +17,11 @@ use glib::{self, Bytes as GBytes, Cast};
use allowed_url::AllowedUrl;
use error::{LoadingError, RsvgError};
-use handle::BinaryData;
+
+pub struct BinaryData {
+ pub data: Vec<u8>,
+ pub content_type: Option<String>,
+}
fn decode_data_uri(uri: &str) -> Result<BinaryData, LoadingError> {
let data_url = data_url::DataUrl::process(uri).map_err(|_| LoadingError::BadDataUrl)?;
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 5b36b3ce..86041bf4 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -225,7 +225,7 @@ impl XmlState {
handle::get_base_url(self.handle).as_ref(),
) {
// FIXME: handle CSS errors
- let _ = handle::load_css(self.css_styles.as_mut().unwrap(), &aurl);
+ let _ = css::load_css(self.css_styles.as_mut().unwrap(), &aurl);
} else {
self.error("disallowed URL in xml-stylesheet");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]