[librsvg: 36/95] NodeStop: parse attributes with the PHF
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 36/95] NodeStop: parse attributes with the PHF
- Date: Thu, 22 Feb 2018 03:16:10 +0000 (UTC)
commit 15c1d55e8c6f3ef9cb32ec18210657c67af62a8a
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 16 19:17:59 2018 -0600
NodeStop: parse attributes with the PHF
rust/src/stop.rs | 46 +++++++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/rust/src/stop.rs b/rust/src/stop.rs
index 1091a643..ed58d4d1 100644
--- a/rust/src/stop.rs
+++ b/rust/src/stop.rs
@@ -3,7 +3,9 @@ use cssparser;
use glib::translate::*;
use std::cell::Cell;
+use std::str::FromStr;
+use attributes::Attribute;
use color::*;
use drawing_ctx;
use drawing_ctx::*;
@@ -12,7 +14,8 @@ use handle::RsvgHandle;
use length::*;
use node::*;
use opacity::*;
-use property_bag::{self, PropertyBag};
+use parsers::parse;
+use property_bag::PropertyBag;
use state::RsvgState;
pub struct NodeStop {
@@ -60,24 +63,33 @@ fn validate_offset(length: RsvgLength) -> Result<RsvgLength, AttributeError> {
impl NodeTrait for NodeStop {
fn set_atts (&self, node: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
- let length = property_bag::parse_or_default (pbag, "offset", LengthDir::Both,
- Some(validate_offset))?;
- assert! (length.unit == LengthUnit::Default || length.unit == LengthUnit::Percent);
- self.offset.set (length.length);
-
let state = node.get_state ();
- // FIXME: this is the only place where rsvg_parse_style() and
- // rsvg_parse_presentation_attributes() are called outside of the
- // rsvg-base.c machinery. That one indirectly calls them via
- // rsvg_parse_style_attrs().
- //
- // Should we resolve the stop-color / stop-opacity at
- // rendering time?
-
- if let Some (v) = pbag.lookup("style") {
- unsafe {
- rsvg_parse_style (state, v.to_glib_none ().0);
+ for (key, value) in pbag.iter() {
+ if let Ok(attr) = Attribute::from_str(key) {
+ match attr {
+ Attribute::Offset => {
+ let length = parse("offset", value, LengthDir::Both, Some(validate_offset))?;
+ assert! (length.unit == LengthUnit::Default || length.unit == LengthUnit::Percent);
+ self.offset.set (length.length);
+ },
+
+ Attribute::Style => {
+ // FIXME: this is the only place where rsvg_parse_style() and
+ // rsvg_parse_presentation_attributes() are called outside of the
+ // rsvg-base.c machinery. That one indirectly calls them via
+ // rsvg_parse_style_attrs().
+ //
+ // Should we resolve the stop-color / stop-opacity at
+ // rendering time?
+
+ unsafe {
+ rsvg_parse_style (state, value.to_glib_none ().0);
+ }
+ },
+
+ _ => (),
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]