diff options
author | Federico Mena Quintero <federico@gnome.org> | 2022-08-29 20:30:25 -0500 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2022-08-29 20:30:25 -0500 |
commit | c7ad43cdfe76e289f46d98c4fac7a8dcc72fa6dd (patch) | |
tree | fda22c974daa920a4800be800f59e8cf29005d5e | |
parent | 20c95d4c9100a81773a19b3337e4e441d7f3b911 (diff) | |
download | librsvg-c7ad43cdfe76e289f46d98c4fac7a8dcc72fa6dd.tar.gz |
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>
-rw-r--r-- | src/document.rs | 17 | ||||
-rw-r--r-- | src/xml/mod.rs | 31 |
2 files changed, 21 insertions, 27 deletions
diff --git a/src/document.rs b/src/document.rs index 190d6fa4..569eb312 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 ac4529bc..da9788d4 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 ); } |