[librsvg: 14/17] Move all the logic for XML processing instructions to the XML module
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 14/17] Move all the logic for XML processing instructions to the XML module
- Date: Tue, 30 Aug 2022 02:13:12 +0000 (UTC)
commit c7ad43cdfe76e289f46d98c4fac7a8dcc72fa6dd
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Aug 29 20:30:25 2022 -0500
Move all the logic for XML processing instructions to the XML module
I.e. load the xml-stylesheet there, instead of having a
DocumentBuilder::append_stylesheet_from_xml_processing_instruction().
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/738>
src/document.rs | 17 -----------------
src/xml/mod.rs | 31 +++++++++++++++++++++----------
2 files changed, 21 insertions(+), 27 deletions(-)
---
diff --git a/src/document.rs b/src/document.rs
index 190d6fa47..569eb3129 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -543,23 +543,6 @@ impl DocumentBuilder {
self.stylesheets.push(stylesheet);
}
- pub fn append_stylesheet_from_xml_processing_instruction(
- &mut self,
- href: &str,
- ) -> Result<(), LoadingError> {
- let aurl = self
- .load_options
- .url_resolver
- .resolve_href(href)
- .map_err(|_| LoadingError::BadUrl)?;
-
- if let Ok(stylesheet) = Stylesheet::from_href(&aurl, Origin::Author, self.session.clone()) {
- self.append_stylesheet(stylesheet);
- }
-
- Ok(())
- }
-
/// Creates an element of the specified `name` as a child of `parent`.
///
/// This is the main function to create new SVG elements while parsing XML.
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index ac4529bc9..da9788d42 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -20,6 +20,7 @@ use std::sync::Arc;
use xml5ever::tendril::format_tendril;
use xml5ever::tokenizer::{TagKind, Token, TokenSink, XmlTokenizer, XmlTokenizerOpts};
+use crate::css::{Origin, Stylesheet};
use crate::document::{Document, DocumentBuilder};
use crate::error::{ImplementationLimit, LoadingError};
use crate::handle::LoadOptions;
@@ -283,18 +284,28 @@ impl XmlState {
}
if let Some(href) = href {
- // FIXME: https://www.w3.org/TR/xml-stylesheet/ does not seem to specify
- // what to do if the stylesheet cannot be loaded, so here we ignore the error.
- if inner
- .document_builder
- .as_mut()
- .unwrap()
- .append_stylesheet_from_xml_processing_instruction(&href)
- .is_err()
- {
+ if let Ok(aurl) = self.load_options.url_resolver.resolve_href(&href) {
+ if let Ok(stylesheet) =
+ Stylesheet::from_href(&aurl, Origin::Author, session.clone())
+ {
+ inner
+ .document_builder
+ .as_mut()
+ .unwrap()
+ .append_stylesheet(stylesheet);
+ } else {
+ // FIXME: https://www.w3.org/TR/xml-stylesheet/ does not seem to specify
+ // what to do if the stylesheet cannot be loaded, so here we ignore the error.
+ rsvg_log!(
+ session,
+ "could not create stylesheet from {} in XML processing instruction",
+ href
+ );
+ }
+ } else {
rsvg_log!(
session,
- "invalid xml-stylesheet {} in XML processing instruction",
+ "{} not allowed for xml-stylesheet in XML processing instruction",
href
);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]