[librsvg: 33/45] Pass a Session to the node creation code




commit c0a336b8a3121033c0ddf59444a8ab7a26f95dff
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Aug 23 17:34:46 2022 -0500

    Pass a Session to the node creation code
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/731>

 src/document.rs   |  2 +-
 src/element.rs    | 22 +++++++++++++++-------
 src/gradient.rs   |  5 +++++
 src/node.rs       |  5 +++--
 src/pattern.rs    |  1 +
 src/properties.rs |  9 ++++++---
 6 files changed, 31 insertions(+), 13 deletions(-)
---
diff --git a/src/document.rs b/src/document.rs
index 1a7650c11..0af3d9e5c 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -542,7 +542,7 @@ impl DocumentBuilder {
         attrs: Attributes,
         parent: Option<Node>,
     ) -> Node {
-        let node = Node::new(NodeData::new_element(name, attrs));
+        let node = Node::new(NodeData::new_element(&self.session, name, attrs));
 
         if let Some(id) = node.borrow_element().get_id() {
             // This is so we don't overwrite an existing id
diff --git a/src/element.rs b/src/element.rs
index ffa47fb08..2926680fe 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -38,6 +38,7 @@ use crate::marker::Marker;
 use crate::node::*;
 use crate::pattern::Pattern;
 use crate::properties::{ComputedValues, SpecifiedValues};
+use crate::session::Session;
 use crate::shapes::{Circle, Ellipse, Line, Path, Polygon, Polyline, Rect};
 use crate::structure::{ClipPath, Group, Link, Mask, NonRendering, Svg, Switch, Symbol, Use};
 use crate::style::Style;
@@ -107,6 +108,7 @@ pub struct ElementInner<T: SetAttributes + Draw> {
 
 impl<T: SetAttributes + Draw> ElementInner<T> {
     fn new(
+        session: &Session,
         element_name: QualName,
         attributes: Attributes,
         result: Result<(), ElementError>,
@@ -127,7 +129,7 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
 
         let mut set_attributes = || -> Result<(), ElementError> {
             e.set_conditional_processing_attributes()?;
-            e.set_presentation_attributes()?;
+            e.set_presentation_attributes(session)?;
             Ok(())
         };
 
@@ -215,9 +217,9 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
 
     /// Hands the `attrs` to the node's state, to apply the presentation attributes.
     #[allow(clippy::unnecessary_wraps)]
-    fn set_presentation_attributes(&mut self) -> Result<(), ElementError> {
+    fn set_presentation_attributes(&mut self, session: &Session) -> Result<(), ElementError> {
         self.specified_values
-            .parse_presentation_attributes(&self.attributes)
+            .parse_presentation_attributes(session, &self.attributes)
     }
 
     // Applies a style declaration to the node's specified_values
@@ -449,7 +451,7 @@ impl Element {
     ///
     /// This operation does not fail.  Unknown element names simply produce a [`NonRendering`]
     /// element.
-    pub fn new(name: &QualName, mut attrs: Attributes) -> Element {
+    pub fn new(session: &Session, name: &QualName, mut attrs: Attributes) -> Element {
         let (create_fn, flags): (ElementCreateFn, ElementCreateFlags) = if name.ns == ns!(svg) {
             match ELEMENT_CREATORS.get(name.local.as_ref()) {
                 // hack in the SVG namespace for supported element names
@@ -470,7 +472,7 @@ impl Element {
 
         //    sizes::print_sizes();
 
-        create_fn(name, attrs)
+        create_fn(session, name, attrs)
     }
 
     pub fn element_name(&self) -> &QualName {
@@ -589,12 +591,17 @@ impl fmt::Display for Element {
 
 macro_rules! e {
     ($name:ident, $element_type:ident) => {
-        pub fn $name(element_name: &QualName, attributes: Attributes) -> Element {
+        pub fn $name(
+            session: &Session,
+            element_name: &QualName,
+            attributes: Attributes,
+        ) -> Element {
             let mut element_impl = <$element_type>::default();
 
             let result = element_impl.set_attributes(&attributes);
 
             let element = Element::$element_type(Box::new(ElementInner::new(
+                session,
                 element_name.clone(),
                 attributes,
                 result,
@@ -679,7 +686,8 @@ mod creators {
 
 use creators::*;
 
-type ElementCreateFn = fn(element_name: &QualName, attributes: Attributes) -> Element;
+type ElementCreateFn =
+    fn(session: &Session, element_name: &QualName, attributes: Attributes) -> Element;
 
 #[derive(Copy, Clone, PartialEq)]
 enum ElementCreateFlags {
diff --git a/src/gradient.rs b/src/gradient.rs
index ac914e763..b1e6813e7 100644
--- a/src/gradient.rs
+++ b/src/gradient.rs
@@ -716,6 +716,7 @@ impl ResolvedGradient {
 mod tests {
     use super::*;
     use crate::node::{Node, NodeData};
+    use crate::session::Session;
     use markup5ever::{namespace_url, ns, QualName};
 
     #[test]
@@ -734,7 +735,10 @@ mod tests {
 
     #[test]
     fn gradient_resolved_from_defaults_is_really_resolved() {
+        let session = Session::default();
+
         let node = Node::new(NodeData::new_element(
+            &session,
             &QualName::new(None, ns!(svg), local_name!("linearGradient")),
             Attributes::new(),
         ));
@@ -745,6 +749,7 @@ mod tests {
         assert!(gradient.is_resolved());
 
         let node = Node::new(NodeData::new_element(
+            &session,
             &QualName::new(None, ns!(svg), local_name!("radialGradient")),
             Attributes::new(),
         ));
diff --git a/src/node.rs b/src/node.rs
index 5d99ec9a6..52f655a5a 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -18,6 +18,7 @@ use crate::element::*;
 use crate::error::*;
 use crate::paint_server::PaintSource;
 use crate::properties::ComputedValues;
+use crate::session::Session;
 use crate::text::Chars;
 use crate::xml::Attributes;
 
@@ -65,8 +66,8 @@ pub enum NodeData {
 }
 
 impl NodeData {
-    pub fn new_element(name: &QualName, attrs: Attributes) -> NodeData {
-        NodeData::Element(Element::new(name, attrs))
+    pub fn new_element(session: &Session, name: &QualName, attrs: Attributes) -> NodeData {
+        NodeData::Element(Element::new(session, name, attrs))
     }
 
     pub fn new_chars(initial_text: &str) -> NodeData {
diff --git a/src/pattern.rs b/src/pattern.rs
index e14bb3e29..7152c13e6 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -497,6 +497,7 @@ mod tests {
     #[test]
     fn pattern_resolved_from_defaults_is_really_resolved() {
         let node = Node::new(NodeData::new_element(
+            &Session::default(),
             &QualName::new(None, ns!(svg), local_name!("pattern")),
             Attributes::new(),
         ));
diff --git a/src/properties.rs b/src/properties.rs
index 893afaf00..8d4390d9f 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -26,6 +26,7 @@ use crate::css::{DeclParser, Declaration, Origin};
 use crate::error::*;
 use crate::parsers::{Parse, ParseValue};
 use crate::property_macros::Property;
+use crate::session::Session;
 use crate::transform::{Transform, TransformAttribute, TransformProperty};
 use crate::xml::Attributes;
 
@@ -805,7 +806,7 @@ impl SpecifiedValues {
         }
     }
 
-    fn parse_one_presentation_attribute(&mut self, attr: QualName, value: &str) {
+    fn parse_one_presentation_attribute(&mut self, session: &Session, attr: QualName, value: &str) {
         let mut input = ParserInput::new(value);
         let mut parser = Parser::new(&mut input);
 
@@ -814,7 +815,8 @@ impl SpecifiedValues {
                 if parser.expect_exhausted().is_ok() {
                     self.set_parsed_property(&prop);
                 } else {
-                    rsvg_log!(
+                    rsvg_log_session!(
+                        session,
                         "(ignoring invalid presentation attribute {:?}\n    value=\"{}\")\n",
                         attr.expanded(),
                         value,
@@ -887,6 +889,7 @@ impl SpecifiedValues {
 
     pub fn parse_presentation_attributes(
         &mut self,
+        session: &Session,
         attrs: &Attributes,
     ) -> Result<(), ElementError> {
         for (attr, value) in attrs.iter() {
@@ -918,7 +921,7 @@ impl SpecifiedValues {
                     )));
                 }
 
-                _ => self.parse_one_presentation_attribute(attr, value),
+                _ => self.parse_one_presentation_attribute(session, attr, value),
             }
         }
 


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