[librsvg: 28/95] GradientCommon: put the defaults in impl Default, not in resolve_from_defaults()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 28/95] GradientCommon: put the defaults in impl Default, not in resolve_from_defaults()
- Date: Thu, 22 Feb 2018 03:15:29 +0000 (UTC)
commit fdc8e812aa27fbb6c2c93dedbd12a2a095c8bfa4
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 16 11:33:02 2018 -0600
GradientCommon: put the defaults in impl Default, not in resolve_from_defaults()
rust/src/gradient.rs | 36 ++++++++++++++----------------------
1 file changed, 14 insertions(+), 22 deletions(-)
---
diff --git a/rust/src/gradient.rs b/rust/src/gradient.rs
index eb49ed04..6a7591b6 100644
--- a/rust/src/gradient.rs
+++ b/rust/src/gradient.rs
@@ -69,9 +69,9 @@ struct Gradient {
impl Default for GradientCommon {
fn default () -> GradientCommon {
GradientCommon {
- units: None,
- affine: None,
- spread: None,
+ units: Some(GradientUnits::default()),
+ affine: Some(cairo::Matrix::identity()),
+ spread: Some(PaintServerSpread::default()),
fallback: None,
stops: None,
}
@@ -113,19 +113,11 @@ impl GradientCommon {
fn is_resolved (&self) -> bool {
self.units.is_some() &&
self.affine.is_some () &&
- self.spread.is_some () &&
- self.stops.is_some ()
+ self.spread.is_some ()
}
fn resolve_from_defaults (&mut self) {
- /* These are per the spec */
-
- fallback_to! (self.units, Some (GradientUnits::default ()));
- fallback_to! (self.affine, Some (cairo::Matrix::identity ()));
- fallback_to! (self.spread, Some (PaintServerSpread::default ()));
- fallback_to! (self.stops, Some (Vec::<ColorStop>::new ())); // empty array of color stops
-
- self.fallback = None;
+ self.resolve_from_fallback(&GradientCommon::default());
}
fn resolve_from_fallback (&mut self, fallback: &GradientCommon) {
@@ -272,15 +264,15 @@ impl Gradient {
fn add_color_stops_to_pattern (&self,
pattern: &mut cairo::Gradient,
opacity: u8) {
- let stops = self.common.stops.as_ref ().unwrap ();
-
- for stop in stops {
- let rgba = stop.rgba;
- pattern.add_color_stop_rgba (stop.offset,
- (f64::from((rgba >> 24) & 0xff)) / 255.0,
- (f64::from((rgba >> 16) & 0xff)) / 255.0,
- (f64::from((rgba >> 8) & 0xff)) / 255.0,
- f64::from(((rgba >> 0) & 0xff) * u32::from(opacity)) / 255.0 /
255.0);
+ if let Some(stops) = self.common.stops.as_ref () {
+ for stop in stops {
+ let rgba = stop.rgba;
+ pattern.add_color_stop_rgba (stop.offset,
+ (f64::from((rgba >> 24) & 0xff)) / 255.0,
+ (f64::from((rgba >> 16) & 0xff)) / 255.0,
+ (f64::from((rgba >> 8) & 0xff)) / 255.0,
+ f64::from(((rgba >> 0) & 0xff) * u32::from(opacity)) / 255.0 /
255.0);
+ }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]