[librsvg] drawing_ctx::state_get_current_color() - Promote the u32 result to a full Color value
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] drawing_ctx::state_get_current_color() - Promote the u32 result to a full Color value
- Date: Wed, 31 May 2017 23:38:36 +0000 (UTC)
commit eafedf3c202e754fa4514e85c17d58497ba6796e
Author: Federico Mena Quintero <federico gnome org>
Date: Wed May 31 16:22:42 2017 -0500
drawing_ctx::state_get_current_color() - Promote the u32 result to a full Color value
Although we don't support "inherit" as a value for the "color"
property (i.e. what is used to specify currentColor), we'll support it
later --- this is embodied in the Color structure.
rust/src/color.rs | 12 ++++++++++++
rust/src/drawing_ctx.rs | 8 ++++----
2 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/rust/src/color.rs b/rust/src/color.rs
index 9a25005..61d6cca 100644
--- a/rust/src/color.rs
+++ b/rust/src/color.rs
@@ -115,6 +115,12 @@ impl From<cssparser::Color> for Color {
}
}
+impl From<u32> for Color {
+ fn from (argb: u32) -> Color {
+ Color::RGBA (rgba_from_argb (argb))
+ }
+}
+
impl From<Result<Color, AttributeError>> for ColorSpec {
fn from (result: Result<Color, AttributeError>) -> ColorSpec {
match result {
@@ -246,4 +252,10 @@ mod tests {
test_roundtrip ("#aabbccdd");
test_roundtrip ("papadzul");
}
+
+ #[test]
+ fn from_argb () {
+ assert_eq! (Color::from (0xaabbccdd),
+ Color::RGBA (cssparser::RGBA::new (0xbb, 0xcc, 0xdd, 0xaa)));
+ }
}
diff --git a/rust/src/drawing_ctx.rs b/rust/src/drawing_ctx.rs
index a332ca5..0e8e8ad 100644
--- a/rust/src/drawing_ctx.rs
+++ b/rust/src/drawing_ctx.rs
@@ -268,8 +268,8 @@ pub fn state_get_stop_opacity (state: *const RsvgState) -> Result<Option<Opacity
}
}
-pub fn state_get_current_color (state: *const RsvgState) -> u32 {
- unsafe {
- rsvg_state_get_current_color (state)
- }
+pub fn state_get_current_color (state: *const RsvgState) -> Color {
+ let argb = unsafe { rsvg_state_get_current_color (state) };
+
+ Color::from (argb)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]