[librsvg: 14/27] Move resolve_color to paint_server.rs
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 14/27] Move resolve_color to paint_server.rs
- Date: Fri, 5 Mar 2021 23:36:27 +0000 (UTC)
commit 0a55cb96596c92e8cc7f27e32cb634f71841a8a3
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Mar 5 13:27:47 2021 -0600
Move resolve_color to paint_server.rs
src/drawing_ctx.rs | 27 +--------------------------
src/paint_server.rs | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 26 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 6065b781..ebf7f5df 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -23,7 +23,7 @@ use crate::float_eq_cairo::ApproxEqCairo;
use crate::gradient::{GradientVariant, SpreadMethod, UserSpaceGradient};
use crate::marker;
use crate::node::{CascadedValues, Node, NodeBorrow, NodeDraw};
-use crate::paint_server::{PaintServer, UserSpacePaintSource};
+use crate::paint_server::{resolve_color, PaintServer, UserSpacePaintSource};
use crate::path_builder::*;
use crate::pattern::UserSpacePattern;
use crate::properties::ComputedValues;
@@ -40,7 +40,6 @@ use crate::surface_utils::{
};
use crate::transform::Transform;
use crate::unit_interval::UnitInterval;
-use crate::util;
use crate::viewbox::ViewBox;
/// Holds values that are required to normalize `CssLength` values to a current viewport.
@@ -1721,30 +1720,6 @@ impl DrawingCtx {
}
}
-fn resolve_color(
- color: &cssparser::Color,
- opacity: UnitInterval,
- current_color: cssparser::RGBA,
-) -> cssparser::RGBA {
- let rgba = match *color {
- cssparser::Color::RGBA(rgba) => rgba,
- cssparser::Color::CurrentColor => current_color,
- };
-
- let UnitInterval(o) = opacity;
-
- let alpha = (f64::from(rgba.alpha) * o).round();
- let alpha = util::clamp(alpha, 0.0, 255.0);
-
- // For the following I'd prefer to use `cast::u8(alpha).unwrap()`
- // but the cast crate is erroneously returning Overflow for `u8(255.0)`:
- // https://github.com/japaric/cast.rs/issues/23
-
- let alpha = alpha as u8;
-
- cssparser::RGBA { alpha, ..rgba }
-}
-
#[derive(Debug)]
struct CompositingAffines {
pub outside_temporary_surface: Transform,
diff --git a/src/paint_server.rs b/src/paint_server.rs
index 5639ccc1..e4011c9a 100644
--- a/src/paint_server.rs
+++ b/src/paint_server.rs
@@ -14,6 +14,8 @@ use crate::node::NodeBorrow;
use crate::parsers::Parse;
use crate::pattern::{ResolvedPattern, UserSpacePattern};
use crate::properties::ComputedValues;
+use crate::unit_interval::UnitInterval;
+use crate::util;
#[derive(Debug, Clone, PartialEq)]
pub enum PaintServer {
@@ -169,6 +171,30 @@ impl PaintSource {
}
}
+pub fn resolve_color(
+ color: &cssparser::Color,
+ opacity: UnitInterval,
+ current_color: cssparser::RGBA,
+) -> cssparser::RGBA {
+ let rgba = match *color {
+ cssparser::Color::RGBA(rgba) => rgba,
+ cssparser::Color::CurrentColor => current_color,
+ };
+
+ let UnitInterval(o) = opacity;
+
+ let alpha = (f64::from(rgba.alpha) * o).round();
+ let alpha = util::clamp(alpha, 0.0, 255.0);
+
+ // For the following I'd prefer to use `cast::u8(alpha).unwrap()`
+ // but the cast crate is erroneously returning Overflow for `u8(255.0)`:
+ // https://github.com/japaric/cast.rs/issues/23
+
+ let alpha = alpha as u8;
+
+ cssparser::RGBA { alpha, ..rgba }
+}
+
#[cfg(test)]
mod tests {
use super::*;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]