[librsvg: 14/20] feImage: shorten code by implementing Default and Clone for its parameters
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 14/20] feImage: shorten code by implementing Default and Clone for its parameters
- Date: Wed, 17 Mar 2021 19:08:06 +0000 (UTC)
commit 82461895c4d604f3c9be7bef7483ff1e54015fcc
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Mar 16 14:12:54 2021 -0600
feImage: shorten code by implementing Default and Clone for its parameters
src/filters/image.rs | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
---
diff --git a/src/filters/image.rs b/src/filters/image.rs
index 977d22a0..02e88b47 100644
--- a/src/filters/image.rs
+++ b/src/filters/image.rs
@@ -16,31 +16,19 @@ use super::context::{FilterContext, FilterOutput, FilterResult};
use super::{FilterEffect, FilterError, Primitive, PrimitiveParams, ResolvedPrimitive};
/// The `feImage` filter primitive.
-#[derive(Clone)]
+#[derive(Default)]
pub struct FeImage {
base: Primitive,
- aspect: AspectRatio,
- href: Option<String>,
+ params: Image,
}
/// Resolved `feImage` primitive for rendering.
+#[derive(Clone, Default)]
pub struct Image {
aspect: AspectRatio,
href: Option<String>,
}
-impl Default for FeImage {
- /// Constructs a new `FeImage` with empty properties.
- #[inline]
- fn default() -> FeImage {
- FeImage {
- base: Default::default(),
- aspect: AspectRatio::default(),
- href: None,
- }
- }
-}
-
impl Image {
/// Renders the filter if the source is an existing node.
fn render_node(
@@ -110,11 +98,13 @@ impl SetAttributes for FeImage {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "preserveAspectRatio") => self.aspect = attr.parse(value)?,
+ expanded_name!("", "preserveAspectRatio") => {
+ self.params.aspect = attr.parse(value)?
+ }
// "path" is used by some older Adobe Illustrator versions
ref a if is_href(a) || *a == expanded_name!("", "path") => {
- set_href(a, &mut self.href, value.to_string());
+ set_href(a, &mut self.params.href, value.to_string());
}
_ => (),
@@ -166,10 +156,7 @@ impl FilterEffect for FeImage {
fn resolve(&self, _node: &Node) -> Result<(Primitive, PrimitiveParams), FilterError> {
Ok((
self.base.clone(),
- PrimitiveParams::Image(Image {
- aspect: self.aspect.clone(),
- href: self.href.clone(),
- }),
+ PrimitiveParams::Image(self.params.clone()),
))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]