[librsvg: 15/17] Create inline stylesheets in the XML module instead of DocumentBuilder




commit 86c34e24e6ebc885d6b424b998e828fbf4c23d71
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Aug 29 20:37:07 2022 -0500

    Create inline stylesheets in the XML module instead of DocumentBuilder
    
    Similar in spirit to the last commit, to remove
    DocumentBuilder::append_stylesheet_from_text() this time.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/738>

 src/document.rs | 12 ------------
 src/xml/mod.rs  | 13 ++++++++++++-
 2 files changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/src/document.rs b/src/document.rs
index 569eb3129..d02701479 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -580,18 +580,6 @@ impl DocumentBuilder {
         node
     }
 
-    pub fn append_stylesheet_from_text(&mut self, text: &str) {
-        // FIXME: handle CSS errors
-        if let Ok(stylesheet) = Stylesheet::from_data(
-            text,
-            &self.load_options.url_resolver,
-            Origin::Author,
-            self.session.clone(),
-        ) {
-            self.append_stylesheet(stylesheet);
-        }
-    }
-
     /// Creates a node for an XML text element as a child of `parent`.
     pub fn append_characters(&mut self, text: &str, parent: &mut Node) {
         if !text.is_empty() {
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index da9788d42..a9ccffac2 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -407,7 +407,18 @@ impl XmlState {
                 .collect::<String>();
 
             let builder = inner.document_builder.as_mut().unwrap();
-            builder.append_stylesheet_from_text(&stylesheet_text);
+            let session = builder.session().clone();
+
+            if let Ok(stylesheet) = Stylesheet::from_data(
+                &stylesheet_text,
+                &self.load_options.url_resolver,
+                Origin::Author,
+                session.clone(),
+            ) {
+                builder.append_stylesheet(stylesheet);
+            } else {
+                rsvg_log!(session, "invalid inline stylesheet");
+            }
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]