[librsvg: 5/21] WIP: Move parsing of the transform attribute to properties.rs




commit 8a1d51d2a26571f59dc0bb7d601a152e755515db
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Aug 18 19:47:46 2021 -0500

    WIP: Move parsing of the transform attribute to properties.rs
    
    Instead of handling it as a special case in ElementInner::new(), we'll
    do it as part of SpecifiedValues::parse_presentation_attributes().
    
    FIXME: one test fails, the one with matrix(0, 0, 0, 0, 0, 0)
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/576>

 src/element.rs    | 18 ------------------
 src/properties.rs |  8 ++++++++
 2 files changed, 8 insertions(+), 18 deletions(-)
---
diff --git a/src/element.rs b/src/element.rs
index 7c132b11..675756ea 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -36,14 +36,12 @@ use crate::gradient::{LinearGradient, RadialGradient, Stop};
 use crate::image::Image;
 use crate::marker::Marker;
 use crate::node::*;
-use crate::parsers::Parse;
 use crate::pattern::Pattern;
 use crate::properties::{ComputedValues, SpecifiedValues};
 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;
 use crate::text::{TRef, TSpan, Text};
-use crate::transform::Transform;
 use crate::xml::Attributes;
 
 // After creating/parsing a Element, it will be in a success or an error state.
@@ -134,7 +132,6 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
         };
 
         let mut set_attributes = || -> Result<(), ElementError> {
-            e.set_transform_attribute()?;
             e.set_conditional_processing_attributes()?;
             e.set_presentation_attributes()?;
             Ok(())
@@ -192,21 +189,6 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
                 .unwrap_or(true)
     }
 
-    // TODO for madds: this whole function will go away, as the transform attribute will be
-    // handled automatically by set_presentation_attributes() below.
-    fn set_transform_attribute(&mut self) -> Result<(), ElementError> {
-        let transform = self
-            .attributes
-            .iter()
-            .find(|(attr, _)| attr.expanded() == expanded_name!("", "transform"))
-            .map(|(attr, value)| Transform::parse_str(value).attribute(attr))
-            .unwrap_or_else(|| Ok(Transform::default()))?;
-
-        self.specified_values.set_transform(transform);
-
-        Ok(())
-    }
-
     fn set_conditional_processing_attributes(&mut self) -> Result<(), ElementError> {
         for (attr, value) in self.attributes.iter() {
             match attr.expanded() {
diff --git a/src/properties.rs b/src/properties.rs
index 9d9e1096..b5fcc7e9 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -751,6 +751,14 @@ impl SpecifiedValues {
     ) -> Result<(), ElementError> {
         for (attr, value) in attrs.iter() {
             match attr.expanded() {
+                expanded_name!("", "transform") => {
+                    // FIXME: we parse the transform attribute here because we don't yet have
+                    // a better way to distinguish attributes whose values have different
+                    // grammars than properties.
+                    let transform = Transform::parse_str(value).unwrap_or_else(|_| Transform::default());
+                    self.set_transform(transform);
+                }
+
                 expanded_name!(xml "lang") => {
                     // xml:lang is a non-presentation attribute and as such cannot have the
                     // "inherit" value.  So, we don't call parse_one_presentation_attribute()


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