[librsvg: 29/95] Gradient: Move the GradientVariant defaults to functions instead of resolve_from_defaults()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 29/95] Gradient: Move the GradientVariant defaults to functions instead of resolve_from_defaults()
- Date: Thu, 22 Feb 2018 03:15:34 +0000 (UTC)
commit 8b1e5156e2403386986b4a14ba73fe8316fbabba
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 16 12:15:07 2018 -0600
Gradient: Move the GradientVariant defaults to functions instead of resolve_from_defaults()
rust/src/gradient.rs | 50 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/rust/src/gradient.rs b/rust/src/gradient.rs
index 6a7591b6..c7ec79c9 100644
--- a/rust/src/gradient.rs
+++ b/rust/src/gradient.rs
@@ -173,28 +173,46 @@ impl GradientVariant {
}
}
+ fn default_linear() -> Self {
+ // https://www.w3.org/TR/SVG/pservers.html#LinearGradients
+
+ GradientVariant::Linear {
+ x1: Some(RsvgLength::parse("0%", LengthDir::Horizontal).unwrap()),
+ y1: Some(RsvgLength::parse("0%", LengthDir::Vertical).unwrap()),
+ x2: Some(RsvgLength::parse("100%", LengthDir::Horizontal).unwrap()),
+ y2: Some(RsvgLength::parse("0%", LengthDir::Vertical).unwrap()),
+ }
+ }
+
+ fn default_radial() -> Self {
+ // https://www.w3.org/TR/SVG/pservers.html#RadialGradients
+
+ GradientVariant::Radial {
+ cx: Some(RsvgLength::parse("50%", LengthDir::Horizontal).unwrap()),
+ cy: Some(RsvgLength::parse("50%", LengthDir::Vertical).unwrap()),
+ r: Some(RsvgLength::parse("50%", LengthDir::Both).unwrap()),
+
+ fx: None,
+ fy: None,
+ }
+ }
+
fn resolve_from_defaults (&mut self) {
/* These are per the spec */
match *self {
- // https://www.w3.org/TR/SVG/pservers.html#LinearGradients
- GradientVariant::Linear { ref mut x1, ref mut y1, ref mut x2, ref mut y2 } => {
- fallback_to! (*x1, Some (RsvgLength::parse ("0%", LengthDir::Horizontal).unwrap ()));
- fallback_to! (*y1, Some (RsvgLength::parse ("0%", LengthDir::Vertical).unwrap ()));
- fallback_to! (*x2, Some (RsvgLength::parse ("100%", LengthDir::Horizontal).unwrap ()));
- fallback_to! (*y2, Some (RsvgLength::parse ("0%", LengthDir::Vertical).unwrap ()));
- },
+ GradientVariant::Linear { .. } =>
+ self.resolve_from_fallback(&GradientVariant::default_linear()),
- // https://www.w3.org/TR/SVG/pservers.html#RadialGradients
- GradientVariant::Radial { ref mut cx, ref mut cy, ref mut r, ref mut fx, ref mut fy } => {
- fallback_to! (*cx, Some (RsvgLength::parse ("50%", LengthDir::Horizontal).unwrap ()));
- fallback_to! (*cy, Some (RsvgLength::parse ("50%", LengthDir::Vertical).unwrap ()));
- fallback_to! (*r, Some (RsvgLength::parse ("50%", LengthDir::Both).unwrap ()));
+ GradientVariant::Radial { .. } => {
+ self.resolve_from_fallback(&GradientVariant::default_radial());
+ },
+ }
- /* fx and fy fall back to the presentational value of cx and cy */
- fallback_to! (*fx, *cx);
- fallback_to! (*fy, *cy);
- }
+ if let &mut GradientVariant::Radial { cx, cy, ref mut fx, ref mut fy, .. } = self {
+ // fx and fy fall back to the presentational value of cx and cy
+ fallback_to!(*fx, cx);
+ fallback_to!(*fy, cy);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]