[librsvg: 1/4] element: Split ElementTrait in two traits, SetAttributes and Draw
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/4] element: Split ElementTrait in two traits, SetAttributes and Draw
- Date: Thu, 16 Apr 2020 22:19:34 +0000 (UTC)
commit 6608c133d501bca6ffe2d1288539c91882fe5bdb
Author: Paolo Borelli <pborelli gnome org>
Date: Wed Apr 15 21:31:07 2020 +0200
element: Split ElementTrait in two traits, SetAttributes and Draw
I think the two separate traits are more "speaking" and also
give us the opportunity to implement SetAttributes for some other
structs like gradient::Common. We use a blanket implementation
of Draw for filter effects.
rsvg_internals/src/element.rs | 20 ++++++----
rsvg_internals/src/filter.rs | 8 ++--
rsvg_internals/src/filters/blend.rs | 8 ++--
rsvg_internals/src/filters/color_matrix.rs | 8 ++--
rsvg_internals/src/filters/component_transfer.rs | 14 ++++---
rsvg_internals/src/filters/composite.rs | 8 ++--
rsvg_internals/src/filters/convolve_matrix.rs | 8 ++--
rsvg_internals/src/filters/displacement_map.rs | 8 ++--
rsvg_internals/src/filters/flood.rs | 8 ++--
rsvg_internals/src/filters/gaussian_blur.rs | 8 ++--
rsvg_internals/src/filters/image.rs | 8 ++--
rsvg_internals/src/filters/light/light_source.rs | 20 ++++++----
rsvg_internals/src/filters/light/lighting.rs | 20 +++++-----
rsvg_internals/src/filters/merge.rs | 14 ++++---
rsvg_internals/src/filters/mod.rs | 17 ++++----
rsvg_internals/src/filters/morphology.rs | 8 ++--
rsvg_internals/src/filters/offset.rs | 8 ++--
rsvg_internals/src/filters/tile.rs | 8 ++--
rsvg_internals/src/filters/turbulence.rs | 8 ++--
rsvg_internals/src/gradient.rs | 28 +++++++------
rsvg_internals/src/image.rs | 8 ++--
rsvg_internals/src/lib.rs | 5 ++-
rsvg_internals/src/marker.rs | 8 ++--
rsvg_internals/src/node.rs | 2 +-
rsvg_internals/src/pattern.rs | 8 ++--
rsvg_internals/src/shapes.rs | 44 ++++++++++++++-------
rsvg_internals/src/structure.rs | 50 ++++++++++++++++--------
rsvg_internals/src/style.rs | 8 ++--
rsvg_internals/src/text.rs | 20 ++++++----
29 files changed, 232 insertions(+), 158 deletions(-)
---
diff --git a/rsvg_internals/src/element.rs b/rsvg_internals/src/element.rs
index 15159ff3..2a50a5c2 100644
--- a/rsvg_internals/src/element.rs
+++ b/rsvg_internals/src/element.rs
@@ -77,15 +77,19 @@ use crate::transform::Transform;
// validator, not a renderer like librsvg is.
pub type ElementResult = Result<(), ElementError>;
-/// The basic trait that all elements must implement
-pub trait ElementTrait {
+pub trait SetAttributes {
/// Sets per-element attributes from the `pbag`
///
/// Each element is supposed to iterate the `pbag`, and parse any attributes it needs.
- fn set_atts(&mut self, _pbag: &PropertyBag<'_>) -> ElementResult {
+ fn set_attributes(&mut self, _pbag: &PropertyBag<'_>) -> ElementResult {
Ok(())
}
+}
+pub trait Draw {
+ /// Draw an element
+ ///
+ /// Each element is supposed to draw itself as needed.
fn draw(
&self,
_node: &Node,
@@ -99,7 +103,7 @@ pub trait ElementTrait {
}
}
-pub struct ElementInner<T: ElementTrait> {
+pub struct ElementInner<T: SetAttributes + Draw> {
element_name: QualName,
id: Option<String>, // id attribute from XML element
class: Option<String>, // class attribute from XML element
@@ -113,7 +117,7 @@ pub struct ElementInner<T: ElementTrait> {
pub element_impl: T,
}
-impl<T: ElementTrait> ElementInner<T> {
+impl<T: SetAttributes + Draw> ElementInner<T> {
fn element_name(&self) -> &QualName {
&self.element_name
}
@@ -236,7 +240,7 @@ impl<T: ElementTrait> ElementInner<T> {
&mut self,
pbag: &PropertyBag<'_>,
) -> Result<(), ElementError> {
- self.element_impl.set_atts(pbag)
+ self.element_impl.set_attributes(pbag)
}
// Applies a style declaration to the node's specified_values
@@ -295,7 +299,7 @@ impl<T: ElementTrait> ElementInner<T> {
}
}
-impl<T: ElementTrait> fmt::Display for ElementInner<T> {
+impl<T: SetAttributes + Draw> fmt::Display for ElementInner<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.element_name().local)?;
write!(f, " id={}", self.get_id().unwrap_or("None"))?;
@@ -303,7 +307,7 @@ impl<T: ElementTrait> fmt::Display for ElementInner<T> {
}
}
-impl<T: ElementTrait> Deref for ElementInner<T> {
+impl<T: SetAttributes + Draw> Deref for ElementInner<T> {
type Target = T;
#[inline]
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index 6615a540..9d4034fb 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -5,7 +5,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::bbox::BoundingBox;
use crate::coord_units::CoordUnits;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{Draw, ElementResult, SetAttributes};
use crate::error::ValueErrorKind;
use crate::length::*;
use crate::parsers::{Parse, ParseValue};
@@ -110,8 +110,8 @@ impl Filter {
}
}
-impl ElementTrait for Filter {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Filter {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
// Parse filterUnits first as it affects x, y, width, height checks.
for (attr, value) in pbag.iter() {
match attr.expanded() {
@@ -182,3 +182,5 @@ impl ElementTrait for Filter {
Ok(())
}
}
+
+impl Draw for Filter {}
diff --git a/rsvg_internals/src/filters/blend.rs b/rsvg_internals/src/filters/blend.rs
index 8f3e9bb2..1e37f350 100755
--- a/rsvg_internals/src/filters/blend.rs
+++ b/rsvg_internals/src/filters/blend.rs
@@ -3,7 +3,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::Node;
use crate::parsers::{Parse, ParseValue};
@@ -52,9 +52,9 @@ impl Default for FeBlend {
}
}
-impl ElementTrait for FeBlend {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeBlend {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/color_matrix.rs b/rsvg_internals/src/filters/color_matrix.rs
index af178ea2..3cb15431 100644
--- a/rsvg_internals/src/filters/color_matrix.rs
+++ b/rsvg_internals/src/filters/color_matrix.rs
@@ -4,7 +4,7 @@ use nalgebra::{Matrix3, Matrix4x5, Matrix5, Vector5};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::Node;
use crate::number_list::{NumberList, NumberListLength};
@@ -51,9 +51,9 @@ impl Default for FeColorMatrix {
}
#[rustfmt::skip]
-impl ElementTrait for FeColorMatrix {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeColorMatrix {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
// First, determine the operation type.
let mut operation_type = Default::default();
diff --git a/rsvg_internals/src/filters/component_transfer.rs
b/rsvg_internals/src/filters/component_transfer.rs
index d78b0e5c..73ef7340 100644
--- a/rsvg_internals/src/filters/component_transfer.rs
+++ b/rsvg_internals/src/filters/component_transfer.rs
@@ -5,7 +5,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::node::{Node, NodeBorrow};
use crate::number_list::{NumberList, NumberListLength};
@@ -34,9 +34,9 @@ impl Default for FeComponentTransfer {
}
}
-impl ElementTrait for FeComponentTransfer {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)
+impl SetAttributes for FeComponentTransfer {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)
}
}
@@ -196,9 +196,9 @@ macro_rules! func_x {
}
}
- impl ElementTrait for $func_name {
+ impl SetAttributes for $func_name {
#[inline]
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "type") => self.function_type = attr.parse(value)?,
@@ -232,6 +232,8 @@ macro_rules! func_x {
Ok(())
}
}
+
+ impl Draw for $func_name {}
};
}
diff --git a/rsvg_internals/src/filters/composite.rs b/rsvg_internals/src/filters/composite.rs
index 6a5c9b6d..4e48fb9e 100644
--- a/rsvg_internals/src/filters/composite.rs
+++ b/rsvg_internals/src/filters/composite.rs
@@ -3,7 +3,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::Node;
use crate::parsers::{Parse, ParseValue};
@@ -50,9 +50,9 @@ impl Default for FeComposite {
}
}
-impl ElementTrait for FeComposite {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeComposite {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/convolve_matrix.rs b/rsvg_internals/src/filters/convolve_matrix.rs
index 74b08881..bea72fca 100644
--- a/rsvg_internals/src/filters/convolve_matrix.rs
+++ b/rsvg_internals/src/filters/convolve_matrix.rs
@@ -4,7 +4,7 @@ use nalgebra::{DMatrix, Dynamic, VecStorage};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::Node;
use crate::number_list::{NumberList, NumberListLength};
@@ -54,9 +54,9 @@ impl Default for FeConvolveMatrix {
}
}
-impl ElementTrait for FeConvolveMatrix {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeConvolveMatrix {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/displacement_map.rs b/rsvg_internals/src/filters/displacement_map.rs
index 99882d66..178a5c45 100644
--- a/rsvg_internals/src/filters/displacement_map.rs
+++ b/rsvg_internals/src/filters/displacement_map.rs
@@ -3,7 +3,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::Node;
use crate::parsers::{Parse, ParseValue};
@@ -45,9 +45,9 @@ impl Default for FeDisplacementMap {
}
}
-impl ElementTrait for FeDisplacementMap {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeDisplacementMap {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/flood.rs b/rsvg_internals/src/filters/flood.rs
index 61fece23..5a320cf2 100644
--- a/rsvg_internals/src/filters/flood.rs
+++ b/rsvg_internals/src/filters/flood.rs
@@ -1,6 +1,6 @@
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::node::{CascadedValues, Node};
use crate::property_bag::PropertyBag;
@@ -22,9 +22,9 @@ impl Default for FeFlood {
}
}
-impl ElementTrait for FeFlood {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)
+impl SetAttributes for FeFlood {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)
}
}
diff --git a/rsvg_internals/src/filters/gaussian_blur.rs b/rsvg_internals/src/filters/gaussian_blur.rs
index 2083ff61..de03dcc9 100644
--- a/rsvg_internals/src/filters/gaussian_blur.rs
+++ b/rsvg_internals/src/filters/gaussian_blur.rs
@@ -6,7 +6,7 @@ use nalgebra::{DMatrix, Dynamic, VecStorage};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::Node;
use crate::parsers::{NumberOptionalNumber, ParseValue};
@@ -42,9 +42,9 @@ impl Default for FeGaussianBlur {
}
}
-impl ElementTrait for FeGaussianBlur {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeGaussianBlur {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index 06e8fe58..88968030 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -4,7 +4,7 @@ use crate::allowed_url::{Fragment, Href};
use crate::aspect_ratio::AspectRatio;
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::{CascadedValues, Node};
use crate::parsers::ParseValue;
@@ -110,9 +110,9 @@ impl FeImage {
}
}
-impl ElementTrait for FeImage {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeImage {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/light/light_source.rs
b/rsvg_internals/src/filters/light/light_source.rs
index 77751c9c..7932cc56 100644
--- a/rsvg_internals/src/filters/light/light_source.rs
+++ b/rsvg_internals/src/filters/light/light_source.rs
@@ -2,7 +2,7 @@ use cssparser;
use markup5ever::{expanded_name, local_name, namespace_url, ns};
use nalgebra::Vector3;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{Draw, ElementResult, SetAttributes};
use crate::filters::context::FilterContext;
use crate::parsers::ParseValue;
use crate::property_bag::PropertyBag;
@@ -102,8 +102,8 @@ impl FeDistantLight {
}
}
-impl ElementTrait for FeDistantLight {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for FeDistantLight {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "azimuth") => self.azimuth = attr.parse(value)?,
@@ -116,6 +116,8 @@ impl ElementTrait for FeDistantLight {
}
}
+impl Draw for FeDistantLight {}
+
#[derive(Default)]
pub struct FePointLight {
x: f64,
@@ -134,8 +136,8 @@ impl FePointLight {
}
}
-impl ElementTrait for FePointLight {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for FePointLight {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value)?,
@@ -149,6 +151,8 @@ impl ElementTrait for FePointLight {
}
}
+impl Draw for FePointLight {}
+
#[derive(Default)]
pub struct FeSpotLight {
x: f64,
@@ -183,8 +187,8 @@ impl FeSpotLight {
}
}
-impl ElementTrait for FeSpotLight {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for FeSpotLight {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value)?,
@@ -209,3 +213,5 @@ impl ElementTrait for FeSpotLight {
Ok(())
}
}
+
+impl Draw for FeSpotLight {}
diff --git a/rsvg_internals/src/filters/light/lighting.rs b/rsvg_internals/src/filters/light/lighting.rs
index 4ed96a37..3b4602ee 100644
--- a/rsvg_internals/src/filters/light/lighting.rs
+++ b/rsvg_internals/src/filters/light/lighting.rs
@@ -7,7 +7,7 @@ use std::cmp::max;
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::filters::{
context::{FilterContext, FilterOutput, FilterResult},
@@ -47,9 +47,11 @@ impl Common {
kernel_unit_length: None,
}
}
+}
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for Common {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
@@ -92,9 +94,9 @@ impl Default for FeDiffuseLighting {
}
}
-impl ElementTrait for FeDiffuseLighting {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.common.set_atts(pbag)?;
+impl SetAttributes for FeDiffuseLighting {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.common.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
@@ -159,9 +161,9 @@ impl Default for FeSpecularLighting {
}
}
-impl ElementTrait for FeSpecularLighting {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.common.set_atts(pbag)?;
+impl SetAttributes for FeSpecularLighting {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.common.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/merge.rs b/rsvg_internals/src/filters/merge.rs
index 80d6471c..39c221d2 100644
--- a/rsvg_internals/src/filters/merge.rs
+++ b/rsvg_internals/src/filters/merge.rs
@@ -2,7 +2,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::node::{Node, NodeBorrow};
use crate::parsers::ParseValue;
use crate::property_bag::PropertyBag;
@@ -33,15 +33,15 @@ impl Default for FeMerge {
}
}
-impl ElementTrait for FeMerge {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)
+impl SetAttributes for FeMerge {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)
}
}
-impl ElementTrait for FeMergeNode {
+impl SetAttributes for FeMergeNode {
#[inline]
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "in") => self.in_ = Some(attr.parse(value)?),
@@ -53,6 +53,8 @@ impl ElementTrait for FeMergeNode {
}
}
+impl Draw for FeMergeNode {}
+
impl FeMergeNode {
fn render(
&self,
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index c8e52bfb..eed87094 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -9,7 +9,7 @@ use crate::bbox::BoundingBox;
use crate::coord_units::CoordUnits;
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::{ParseError, RenderingError};
use crate::length::*;
use crate::node::{CascadedValues, Node, NodeBorrow};
@@ -29,7 +29,7 @@ mod error;
use self::error::FilterError;
/// A filter primitive interface.
-pub trait FilterEffect: ElementTrait {
+pub trait FilterEffect: SetAttributes + Draw {
/// Renders this filter primitive.
///
/// If this filter primitive can't be rendered for whatever reason (for instance, a required
@@ -50,6 +50,9 @@ pub trait FilterEffect: ElementTrait {
fn is_affected_by_color_interpolation_filters(&self) -> bool;
}
+// Filter Effects do not need to draw themselves
+impl<T: FilterEffect> Draw for T {}
+
pub mod blend;
pub mod color_matrix;
pub mod component_transfer;
@@ -195,8 +198,8 @@ impl Primitive {
}
}
-impl ElementTrait for Primitive {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Primitive {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = Some(attr.parse(value)?),
@@ -241,9 +244,9 @@ impl PrimitiveWithInput {
}
}
-impl ElementTrait for PrimitiveWithInput {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for PrimitiveWithInput {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index 1ab57342..dffa1657 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -5,7 +5,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::Node;
use crate::parsers::{NumberOptionalNumber, Parse, ParseValue};
@@ -45,9 +45,9 @@ impl Default for FeMorphology {
}
}
-impl ElementTrait for FeMorphology {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeMorphology {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/offset.rs b/rsvg_internals/src/filters/offset.rs
index 817955cb..3cb54880 100644
--- a/rsvg_internals/src/filters/offset.rs
+++ b/rsvg_internals/src/filters/offset.rs
@@ -2,7 +2,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::node::Node;
use crate::parsers::ParseValue;
use crate::property_bag::PropertyBag;
@@ -29,9 +29,9 @@ impl Default for FeOffset {
}
}
-impl ElementTrait for FeOffset {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeOffset {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/filters/tile.rs b/rsvg_internals/src/filters/tile.rs
index 1d2ca239..8be49ed8 100644
--- a/rsvg_internals/src/filters/tile.rs
+++ b/rsvg_internals/src/filters/tile.rs
@@ -1,6 +1,6 @@
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::node::Node;
use crate::property_bag::PropertyBag;
@@ -22,9 +22,9 @@ impl Default for FeTile {
}
}
-impl ElementTrait for FeTile {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)
+impl SetAttributes for FeTile {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)
}
}
diff --git a/rsvg_internals/src/filters/turbulence.rs b/rsvg_internals/src/filters/turbulence.rs
index b5e14a49..bfd63663 100644
--- a/rsvg_internals/src/filters/turbulence.rs
+++ b/rsvg_internals/src/filters/turbulence.rs
@@ -3,7 +3,7 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns};
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::{CascadedValues, Node};
use crate::parsers::{NumberOptionalNumber, Parse, ParseValue};
@@ -56,9 +56,9 @@ impl Default for FeTurbulence {
}
}
-impl ElementTrait for FeTurbulence {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.base.set_atts(pbag)?;
+impl SetAttributes for FeTurbulence {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.base.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index 184c5834..dedfdcc8 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -12,7 +12,7 @@ use crate::bbox::*;
use crate::coord_units::CoordUnits;
use crate::document::{AcquiredNodes, NodeStack};
use crate::drawing_ctx::{DrawingCtx, ViewParams};
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::length::*;
use crate::node::{CascadedValues, Node, NodeBorrow};
@@ -93,8 +93,8 @@ fn validate_offset(length: Length<Both>) -> Result<Length<Both>, ValueErrorKind>
}
}
-impl ElementTrait for Stop {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Stop {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "offset") => {
@@ -110,6 +110,8 @@ impl ElementTrait for Stop {
}
}
+impl Draw for Stop {}
+
/// Parameters specific to each gradient type, before being resolved.
/// These will be composed together with UnreseolvedVariant from fallback
/// nodes (referenced with e.g. <linearGradient xlink:href="#fallback">) to form
@@ -587,8 +589,8 @@ macro_rules! impl_get_unresolved {
impl_get_unresolved!(LinearGradient);
impl_get_unresolved!(RadialGradient);
-impl Common {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Common {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "gradientUnits") => self.units = Some(attr.parse(value)?),
@@ -607,9 +609,9 @@ impl Common {
}
}
-impl ElementTrait for LinearGradient {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.common.set_atts(pbag)?;
+impl SetAttributes for LinearGradient {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.common.set_attributes(pbag)?;
for (attr, value) in pbag.iter() {
match attr.expanded() {
@@ -626,9 +628,11 @@ impl ElementTrait for LinearGradient {
}
}
-impl ElementTrait for RadialGradient {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
- self.common.set_atts(pbag)?;
+impl Draw for LinearGradient {}
+
+impl SetAttributes for RadialGradient {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+ self.common.set_attributes(pbag)?;
// Create a local expanded name for "fr" because markup5ever doesn't have built-in
let expanded_name_fr = ExpandedName {
ns: &Namespace::from(""),
@@ -657,6 +661,8 @@ impl ElementTrait for RadialGradient {
}
}
+impl Draw for RadialGradient {}
+
macro_rules! impl_paint_source {
($gradient_type:ident, $other_type:ident) => {
impl PaintSource for $gradient_type {
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index fd1c0877..dd5616c9 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -7,7 +7,7 @@ use crate::aspect_ratio::AspectRatio;
use crate::bbox::BoundingBox;
use crate::document::AcquiredNodes;
use crate::drawing_ctx::{ClipMode, DrawingCtx, ViewParams};
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{Draw, ElementResult, SetAttributes};
use crate::error::*;
use crate::length::*;
use crate::node::{CascadedValues, Node};
@@ -27,8 +27,8 @@ pub struct Image {
href: Option<Href>,
}
-impl ElementTrait for Image {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Image {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value)?,
@@ -56,7 +56,9 @@ impl ElementTrait for Image {
Ok(())
}
+}
+impl Draw for Image {
fn draw(
&self,
node: &Node,
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 66906b64..1073a74e 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -22,7 +22,7 @@
//! helper traits used to operate on nodes.
//!
//! * [The `element` module](element/index.html) provides the [`Element`] struct and
-//! [`ElementTrait`] which is implemented by all SVG elements.
+//! the [`SetAttributes`] and [`Draw`] traits which are implemented by all SVG elements.
//!
//! * [The `xml` module](xml/index.html) receives events from the XML parser, and builds a
//! [`Document`] as a tree of [`Node`].
@@ -39,7 +39,8 @@
//! [`Document`]: document/struct.Document.html
//! [`Node`]: node/type.Node.html
//! [`Element`]: element/struct.Element.html
-//! [`ElementTrait`]: element/trait.ElementTrait.html
+//! [`SetAttributes`]: element/trait.SetAttributes.html
+//! [`Draw`]: element/trait.Draw.html
#![allow(clippy::clone_on_ref_ptr)]
#![allow(clippy::not_unsafe_ptr_arg_deref)]
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 1056d46c..eec6316f 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -12,7 +12,7 @@ use crate::aspect_ratio::*;
use crate::bbox::BoundingBox;
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::float_eq_cairo::ApproxEqCairo;
use crate::iri::IRI;
@@ -175,8 +175,8 @@ impl Marker {
}
}
-impl ElementTrait for Marker {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Marker {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "markerUnits") => self.units = attr.parse(value)?,
@@ -201,6 +201,8 @@ impl ElementTrait for Marker {
}
}
+impl Draw for Marker {}
+
// Machinery to figure out marker orientations
#[derive(Debug, PartialEq)]
enum Segment {
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index c086c7e2..370381e5 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -156,7 +156,7 @@ impl<'a> CascadedValues<'a> {
/// Returns the cascaded `ComputedValues`.
///
- /// Nodes should use this from their `ElementTrait::draw()` implementation to get the
+ /// Nodes should use this from their `SetAttributes::draw()` implementation to get the
/// `ComputedValues` from the `CascadedValues` that got passed to `draw()`.
pub fn get(&'a self) -> &'a ComputedValues {
match self.inner {
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index 51251c07..9ba314c9 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -10,7 +10,7 @@ use crate::bbox::*;
use crate::coord_units::CoordUnits;
use crate::document::{AcquiredNodes, NodeStack};
use crate::drawing_ctx::{DrawingCtx, ViewParams};
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::float_eq_cairo::ApproxEqCairo;
use crate::length::*;
@@ -118,8 +118,8 @@ pub struct Pattern {
resolved: RefCell<Option<ResolvedPattern>>,
}
-impl ElementTrait for Pattern {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Pattern {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "patternUnits") => self.common.units = Some(attr.parse(value)?),
@@ -155,6 +155,8 @@ impl ElementTrait for Pattern {
}
}
+impl Draw for Pattern {}
+
impl PaintSource for Pattern {
type Resolved = ResolvedPattern;
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index b08355eb..ec3c1807 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -8,7 +8,7 @@ use std::rc::Rc;
use crate::bbox::BoundingBox;
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{Draw, ElementResult, SetAttributes};
use crate::error::*;
use crate::length::*;
use crate::node::{CascadedValues, Node};
@@ -115,8 +115,8 @@ pub struct Path {
path: Option<Rc<SvgPath>>,
}
-impl ElementTrait for Path {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Path {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
if attr.expanded() == expanded_name!("", "d") {
let mut builder = PathBuilder::new();
@@ -132,7 +132,9 @@ impl ElementTrait for Path {
Ok(())
}
+}
+impl Draw for Path {
fn draw(
&self,
node: &Node,
@@ -219,8 +221,8 @@ pub struct Polygon {
points: Option<Points>,
}
-impl ElementTrait for Polygon {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Polygon {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
if attr.expanded() == expanded_name!("", "points") {
self.points = attr.parse(value).map(Some)?;
@@ -229,7 +231,9 @@ impl ElementTrait for Polygon {
Ok(())
}
+}
+impl Draw for Polygon {
fn draw(
&self,
node: &Node,
@@ -254,8 +258,8 @@ pub struct Polyline {
points: Option<Points>,
}
-impl ElementTrait for Polyline {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Polyline {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
if attr.expanded() == expanded_name!("", "points") {
self.points = attr.parse(value).map(Some)?;
@@ -264,7 +268,9 @@ impl ElementTrait for Polyline {
Ok(())
}
+}
+impl Draw for Polyline {
fn draw(
&self,
node: &Node,
@@ -290,8 +296,8 @@ pub struct Line {
y2: Length<Vertical>,
}
-impl ElementTrait for Line {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Line {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x1") => self.x1 = attr.parse(value)?,
@@ -304,7 +310,9 @@ impl ElementTrait for Line {
Ok(())
}
+}
+impl Draw for Line {
fn draw(
&self,
node: &Node,
@@ -354,8 +362,8 @@ pub struct Rect {
ry: Option<Length<Vertical>>,
}
-impl ElementTrait for Rect {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Rect {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value)?,
@@ -384,7 +392,9 @@ impl ElementTrait for Rect {
Ok(())
}
+}
+impl Draw for Rect {
fn draw(
&self,
node: &Node,
@@ -584,8 +594,8 @@ pub struct Circle {
r: Length<Both>,
}
-impl ElementTrait for Circle {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Circle {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "cx") => self.cx = attr.parse(value)?,
@@ -599,7 +609,9 @@ impl ElementTrait for Circle {
Ok(())
}
+}
+impl Draw for Circle {
fn draw(
&self,
node: &Node,
@@ -639,8 +651,8 @@ pub struct Ellipse {
ry: Length<Vertical>,
}
-impl ElementTrait for Ellipse {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Ellipse {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "cx") => self.cx = attr.parse(value)?,
@@ -659,7 +671,9 @@ impl ElementTrait for Ellipse {
Ok(())
}
+}
+impl Draw for Ellipse {
fn draw(
&self,
node: &Node,
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 1d13a56b..4614cfc9 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -9,7 +9,7 @@ use crate::coord_units::CoordUnits;
use crate::document::AcquiredNodes;
use crate::dpi::Dpi;
use crate::drawing_ctx::{ClipMode, DrawingCtx, ViewParams};
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{Draw, ElementResult, SetAttributes};
use crate::error::*;
use crate::length::*;
use crate::node::{CascadedValues, Node, NodeBorrow, NodeDraw};
@@ -22,7 +22,9 @@ use crate::viewbox::*;
#[derive(Default)]
pub struct Group();
-impl ElementTrait for Group {
+impl SetAttributes for Group {}
+
+impl Draw for Group {
fn draw(
&self,
node: &Node,
@@ -46,12 +48,16 @@ impl ElementTrait for Group {
#[derive(Default)]
pub struct NonRendering;
-impl ElementTrait for NonRendering {}
+impl SetAttributes for NonRendering {}
+
+impl Draw for NonRendering {}
#[derive(Default)]
pub struct Switch();
-impl ElementTrait for Switch {
+impl SetAttributes for Switch {}
+
+impl Draw for Switch {
fn draw(
&self,
node: &Node,
@@ -174,8 +180,8 @@ impl Svg {
}
}
-impl ElementTrait for Svg {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Svg {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "preserveAspectRatio") => {
@@ -199,7 +205,9 @@ impl ElementTrait for Svg {
Ok(())
}
+}
+impl Draw for Svg {
fn draw(
&self,
node: &Node,
@@ -291,8 +299,8 @@ impl Use {
}
}
-impl ElementTrait for Use {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Use {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!(xlink "href") => {
@@ -316,7 +324,9 @@ impl ElementTrait for Use {
Ok(())
}
+}
+impl Draw for Use {
fn draw(
&self,
node: &Node,
@@ -345,8 +355,8 @@ impl Symbol {
}
}
-impl ElementTrait for Symbol {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Symbol {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "preserveAspectRatio") => {
@@ -361,6 +371,8 @@ impl ElementTrait for Symbol {
}
}
+impl Draw for Symbol {}
+
coord_units!(ClipPathUnits, CoordUnits::UserSpaceOnUse);
#[derive(Default)]
@@ -374,8 +386,8 @@ impl ClipPath {
}
}
-impl ElementTrait for ClipPath {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for ClipPath {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "clipPathUnits") => self.units = attr.parse(value)?,
@@ -387,6 +399,8 @@ impl ElementTrait for ClipPath {
}
}
+impl Draw for ClipPath {}
+
coord_units!(MaskUnits, CoordUnits::ObjectBoundingBox);
coord_units!(MaskContentUnits, CoordUnits::UserSpaceOnUse);
@@ -434,8 +448,8 @@ impl Mask {
}
}
-impl ElementTrait for Mask {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Mask {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value)?,
@@ -458,13 +472,15 @@ impl ElementTrait for Mask {
}
}
+impl Draw for Mask {}
+
#[derive(Default)]
pub struct Link {
link: Option<String>,
}
-impl ElementTrait for Link {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Link {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!(xlink "href") => self.link = Some(value.to_owned()),
@@ -474,7 +490,9 @@ impl ElementTrait for Link {
Ok(())
}
+}
+impl Draw for Link {
fn draw(
&self,
node: &Node,
diff --git a/rsvg_internals/src/style.rs b/rsvg_internals/src/style.rs
index 1388ae03..3565da0a 100644
--- a/rsvg_internals/src/style.rs
+++ b/rsvg_internals/src/style.rs
@@ -2,7 +2,7 @@
use markup5ever::{expanded_name, local_name, namespace_url, ns};
-use crate::element::{ElementResult, ElementTrait};
+use crate::element::{Draw, ElementResult, SetAttributes};
use crate::error::*;
use crate::property_bag::PropertyBag;
@@ -50,8 +50,8 @@ impl Style {
}
}
-impl ElementTrait for Style {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Style {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
if attr.expanded() == expanded_name!("", "type") {
self.type_ = Some(StyleType::parse(value).attribute(attr)?);
@@ -62,6 +62,8 @@ impl ElementTrait for Style {
}
}
+impl Draw for Style {}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 9463ba99..1fc14009 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -8,7 +8,7 @@ use crate::allowed_url::Fragment;
use crate::bbox::BoundingBox;
use crate::document::AcquiredNodes;
use crate::drawing_ctx::DrawingCtx;
-use crate::element::{Element, ElementResult, ElementTrait};
+use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::float_eq_cairo::ApproxEqCairo;
use crate::font_props::FontWeightSpec;
@@ -596,8 +596,8 @@ impl Text {
}
}
-impl ElementTrait for Text {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for Text {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value)?,
@@ -610,7 +610,9 @@ impl ElementTrait for Text {
Ok(())
}
+}
+impl Draw for Text {
fn draw(
&self,
node: &Node,
@@ -715,8 +717,8 @@ fn extract_chars_children_to_chunks_recursively(
}
}
-impl ElementTrait for TRef {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for TRef {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!(xlink "href") => {
@@ -730,6 +732,8 @@ impl ElementTrait for TRef {
}
}
+impl Draw for TRef {}
+
#[derive(Default)]
pub struct TSpan {
x: Option<Length<Horizontal>>,
@@ -764,8 +768,8 @@ impl TSpan {
}
}
-impl ElementTrait for TSpan {
- fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
+impl SetAttributes for TSpan {
+ fn set_attributes(&mut self, pbag: &PropertyBag<'_>) -> ElementResult {
for (attr, value) in pbag.iter() {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value).map(Some)?,
@@ -780,6 +784,8 @@ impl ElementTrait for TSpan {
}
}
+impl Draw for TSpan {}
+
fn to_pango_units(v: f64) -> i32 {
(v * f64::from(pango::SCALE) + 0.5) as i32
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]