[librsvg: 1/5] Store an element's transform in its SpecifiedValues, not in ElementInner




commit adc4ebca67ac9b2d77500a7d6712fd96591c5296
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Aug 3 16:29:32 2021 -0500

    Store an element's transform in its SpecifiedValues, not in ElementInner
    
    This is a preliminary refactoring for #754.  Instead of storing a
    special field for the transform attribute, we'll switch to storing an
    element's transform in its SpecifiedValues.  Since it is all handled
    through getters, the change is small.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/575>

 src/element.rs    | 12 ++++++++----
 src/properties.rs | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/src/element.rs b/src/element.rs
index 4e13c268..4a281baf 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -102,7 +102,6 @@ pub struct ElementInner<T: SetAttributes + Draw> {
     specified_values: SpecifiedValues,
     important_styles: HashSet<QualName>,
     result: ElementResult,
-    transform: Transform,
     values: ComputedValues,
     required_extensions: Option<RequiredExtensions>,
     required_features: Option<RequiredFeatures>,
@@ -127,7 +126,6 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
             specified_values: Default::default(),
             important_styles: Default::default(),
             result,
-            transform: Default::default(),
             values: Default::default(),
             required_extensions: Default::default(),
             required_features: Default::default(),
@@ -194,18 +192,24 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
                 .unwrap_or(true)
     }
 
+    // TODO for madds: this function will go away, because we want code to be doing
+    // values.transform() instead.
     fn get_transform(&self) -> Transform {
-        self.transform
+        self.specified_values.get_transform()
     }
 
+    // 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> {
-        self.transform = self
+        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(())
     }
 
diff --git a/src/properties.rs b/src/properties.rs
index c2d59998..02097a4c 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::transform::Transform;
 use crate::xml::Attributes;
 
 // Re-export the actual properties so they are easy to find from a single place `properties::*`.
@@ -90,6 +91,10 @@ impl PropertyId {
 pub struct SpecifiedValues {
     indices: [u8; PropertyId::UnsetProperty as usize],
     props: Vec<ParsedProperty>,
+
+    // TODO for madds: the following field will go away once the machinery for properties
+    // actually knows about the transform property.
+    transform: Transform,
 }
 
 impl Default for SpecifiedValues {
@@ -98,6 +103,7 @@ impl Default for SpecifiedValues {
             // this many elements, with the same value
             indices: [PropertyId::UnsetProperty.as_u8(); PropertyId::UnsetProperty as usize],
             props: Vec::new(),
+            transform: Default::default(),
         }
     }
 }
@@ -430,6 +436,18 @@ make_properties! {
 }
 
 impl SpecifiedValues {
+    // TODO for madds: this function will go away; it's just a setter
+    // used by ElementInner::set_transform_attribute(), which in turn will go away.
+    pub fn set_transform(&mut self, transform: Transform) {
+        self.transform = transform;
+    }
+
+    // TODO for madds: this function will go away; it's just a getter
+    // used by ElementInner::get_transform()
+    pub fn get_transform(&self) -> Transform {
+        self.transform
+    }
+
     fn property_index(&self, id: PropertyId) -> Option<usize> {
         let v = self.indices[id.as_usize()];
 


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