[librsvg: 20/27] Resolve a gradient's stop_color and stop_opacity when the initial gradient is built
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 20/27] Resolve a gradient's stop_color and stop_opacity when the initial gradient is built
- Date: Fri, 5 Mar 2021 23:36:27 +0000 (UTC)
commit cfcbba9a2139b2c02a237c7c941eef9473c044d9
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Mar 5 14:21:02 2021 -0600
Resolve a gradient's stop_color and stop_opacity when the initial gradient is built
Instead of doing it in drawing_ctx at rendering time.
src/drawing_ctx.rs | 3 +--
src/gradient.rs | 31 ++++++++++---------------------
src/paint_server.rs | 2 +-
3 files changed, 12 insertions(+), 24 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 6e0347a1..7a916d40 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1004,14 +1004,13 @@ impl DrawingCtx {
for stop in &gradient.stops {
let UnitInterval(stop_offset) = stop.offset;
let UnitInterval(o) = opacity;
- let UnitInterval(stop_opacity) = stop.opacity;
g.add_color_stop_rgba(
stop_offset,
f64::from(stop.rgba.red_f32()),
f64::from(stop.rgba.green_f32()),
f64::from(stop.rgba.blue_f32()),
- f64::from(stop.rgba.alpha_f32()) * stop_opacity * o,
+ f64::from(stop.rgba.alpha_f32()) * o,
);
}
diff --git a/src/gradient.rs b/src/gradient.rs
index 31a3bc11..f31d9ac6 100644
--- a/src/gradient.rs
+++ b/src/gradient.rs
@@ -15,9 +15,9 @@ use crate::error::*;
use crate::href::{is_href, set_href};
use crate::length::*;
use crate::node::{CascadedValues, Node, NodeBorrow};
+use crate::paint_server::resolve_color;
use crate::parsers::{Parse, ParseValue};
use crate::properties::ComputedValues;
-use crate::property_defs::StopColor;
use crate::transform::Transform;
use crate::unit_interval::UnitInterval;
use crate::xml::Attributes;
@@ -28,11 +28,8 @@ pub struct ColorStop {
/// <stop offset="..."/>
pub offset: UnitInterval,
- /// <stop stop-color="..."/>
+ /// <stop stop-color="..." stop-opacity="..."/>
pub rgba: cssparser::RGBA,
-
- /// <stop stop-opacity="..."/>
- pub opacity: UnitInterval,
}
// gradientUnits attribute; its default is objectBoundingBox
@@ -406,12 +403,7 @@ impl UnresolvedGradient {
}
/// Helper for add_color_stops_from_node()
- fn add_color_stop(
- &mut self,
- offset: UnitInterval,
- rgba: cssparser::RGBA,
- opacity: UnitInterval,
- ) {
+ fn add_color_stop(&mut self, offset: UnitInterval, rgba: cssparser::RGBA) {
if self.stops.is_none() {
self.stops = Some(Vec::<ColorStop>::new());
}
@@ -429,11 +421,7 @@ impl UnresolvedGradient {
last_offset
};
- stops.push(ColorStop {
- offset,
- rgba,
- opacity,
- });
+ stops.push(ColorStop { offset, rgba });
} else {
unreachable!();
}
@@ -456,12 +444,13 @@ impl UnresolvedGradient {
} else {
let cascaded = CascadedValues::new_from_node(&child);
let values = cascaded.get();
- let rgba = match values.stop_color() {
- StopColor(cssparser::Color::CurrentColor) => values.color().0,
- StopColor(cssparser::Color::RGBA(ref rgba)) => *rgba,
- };
+ let rgba = resolve_color(
+ &values.stop_color().0,
+ values.stop_opacity().0,
+ values.color().0,
+ );
- self.add_color_stop(stop.offset, rgba, values.stop_opacity().0);
+ self.add_color_stop(stop.offset, rgba);
}
}
}
diff --git a/src/paint_server.rs b/src/paint_server.rs
index 3895608b..724c1531 100644
--- a/src/paint_server.rs
+++ b/src/paint_server.rs
@@ -194,7 +194,7 @@ impl PaintSource {
}
}
-fn resolve_color(
+pub fn resolve_color(
color: &cssparser::Color,
opacity: UnitInterval,
current_color: cssparser::RGBA,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]