[librsvg: 6/7] Start differentiating between TransformProperty and TransformAttribute
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 6/7] Start differentiating between TransformProperty and TransformAttribute
- Date: Wed, 1 Sep 2021 00:59:51 +0000 (UTC)
commit f9436f350011fb023834cfd783afc43876576bb0
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Aug 31 19:36:21 2021 -0500
Start differentiating between TransformProperty and TransformAttribute
At least with types for now. Transform is still just a matrix, but is
not tied to the attribute anymore.
The transform, gradientTransform, and patternTransform attributes now
use TransformAttribute to parse.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/582>
src/gradient.rs | 7 +++++--
src/pattern.rs | 5 +++--
src/properties.rs | 9 ++++-----
src/transform.rs | 23 ++++++++++++++++++-----
4 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/src/gradient.rs b/src/gradient.rs
index f91bd465..d2a35e88 100644
--- a/src/gradient.rs
+++ b/src/gradient.rs
@@ -17,7 +17,7 @@ use crate::node::{CascadedValues, Node, NodeBorrow};
use crate::paint_server::resolve_color;
use crate::parsers::{Parse, ParseValue};
use crate::properties::ComputedValues;
-use crate::transform::Transform;
+use crate::transform::{Transform, TransformAttribute};
use crate::unit_interval::UnitInterval;
use crate::xml::Attributes;
@@ -536,7 +536,10 @@ impl SetAttributes for Common {
for (attr, value) in attrs.iter() {
match attr.expanded() {
expanded_name!("", "gradientUnits") => self.units = attr.parse(value)?,
- expanded_name!("", "gradientTransform") => self.transform = attr.parse(value)?,
+ expanded_name!("", "gradientTransform") => {
+ let transform_attr: TransformAttribute = attr.parse(value)?;
+ self.transform = Some(transform_attr.to_transform());
+ }
expanded_name!("", "spreadMethod") => self.spread = attr.parse(value)?,
ref a if is_href(a) => {
set_href(
diff --git a/src/pattern.rs b/src/pattern.rs
index 3262f297..96778e40 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -15,7 +15,7 @@ use crate::node::{Node, NodeBorrow, WeakNode};
use crate::parsers::ParseValue;
use crate::properties::ComputedValues;
use crate::rect::Rect;
-use crate::transform::Transform;
+use crate::transform::{Transform, TransformAttribute};
use crate::unit_interval::UnitInterval;
use crate::viewbox::*;
use crate::xml::Attributes;
@@ -134,7 +134,8 @@ impl SetAttributes for Pattern {
self.common.preserve_aspect_ratio = attr.parse(value)?
}
expanded_name!("", "patternTransform") => {
- self.common.transform = attr.parse(value)?
+ let transform_attr: TransformAttribute = attr.parse(value)?;
+ self.common.transform = Some(transform_attr.to_transform());
}
ref a if is_href(a) => {
set_href(
diff --git a/src/properties.rs b/src/properties.rs
index 3627a842..47c11b7c 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -26,8 +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::transform::TransformProperty;
+use crate::transform::{Transform, TransformAttribute, TransformProperty};
use crate::xml::Attributes;
// Re-export the actual properties so they are easy to find from a single place `properties::*`.
@@ -752,9 +751,9 @@ impl SpecifiedValues {
// 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.transform = Some(transform);
+ let transform_attr = TransformAttribute::parse_str(value)
+ .unwrap_or_else(|_| TransformAttribute::default());
+ self.transform = Some(transform_attr.to_transform());
}
expanded_name!(xml "lang") => {
diff --git a/src/transform.rs b/src/transform.rs
index ed7c3d07..7ab0072e 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -10,7 +10,7 @@
//! grammar than the `transform` property from SVG2.
//!
//! [prop]: https://www.w3.org/TR/css-transforms-1/#transform-property
-//! [attr]: https://www.w3.org/TR/SVG11/coords.html#TransformAttribute and
https://www.w3.org/TR/css-transforms-1/#transform-property
+//! [attr]: https://www.w3.org/TR/SVG11/coords.html#TransformAttribute
use cssparser::{Parser, Token};
@@ -42,6 +42,12 @@ pub enum TransformProperty {
List(Vec<TransformFunction>),
}
+/// The `transform` attribute from SVG1.1
+///
+/// https://www.w3.org/TR/SVG11/coords.html#TransformAttribute
+#[derive(Default, Debug, Clone, PartialEq)]
+pub struct TransformAttribute(Transform);
+
impl Default for TransformProperty {
fn default() -> Self {
TransformProperty::None
@@ -528,9 +534,15 @@ impl Default for Transform {
}
}
-impl Parse for Transform {
- fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Transform, ParseError<'i>> {
- parse_transform_list(parser)
+impl TransformAttribute {
+ pub fn to_transform(&self) -> Transform {
+ self.0
+ }
+}
+
+impl Parse for TransformAttribute {
+ fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<TransformAttribute, ParseError<'i>> {
+ Ok(TransformAttribute(parse_transform_list(parser)?))
}
}
@@ -685,7 +697,8 @@ mod tests {
}
fn parse_transform(s: &str) -> Result<Transform, ParseError<'_>> {
- Transform::parse_str(s)
+ let transform_attr = TransformAttribute::parse_str(s)?;
+ Ok(transform_attr.to_transform())
}
fn parse_transform_prop(s: &str) -> Result<TransformProperty, ParseError<'_>> {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]