[librsvg: 20/95] NodeLine: parse attributes with the PHF
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 20/95] NodeLine: parse attributes with the PHF
- Date: Thu, 22 Feb 2018 03:14:49 +0000 (UTC)
commit 008646b350ebde346cd036c2c7e6fcc4daa9fef9
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Feb 13 10:09:14 2018 -0600
NodeLine: parse attributes with the PHF
rsvg-attributes.h | 4 ++++
rust/build.rs | 4 ++++
rust/src/shapes.rs | 17 ++++++++++++-----
3 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index a59ee10d..f8b8de5e 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -118,6 +118,10 @@ typedef enum {
RSVG_ATTRIBUTE_WIDTH,
RSVG_ATTRIBUTE_WRITING_MODE,
RSVG_ATTRIBUTE_X,
+ RSVG_ATTRIBUTE_X1,
+ RSVG_ATTRIBUTE_Y1,
+ RSVG_ATTRIBUTE_X2,
+ RSVG_ATTRIBUTE_Y2,
RSVG_ATTRIBUTE_X_CHANNEL_SELECTOR,
RSVG_ATTRIBUTE_XLINK_HREF,
RSVG_ATTRIBUTE_XML_LANG,
diff --git a/rust/build.rs b/rust/build.rs
index 509932b5..a7d208b5 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -125,6 +125,10 @@ fn generate_phf_of_svg_attributes() {
( "width", "Width" ),
( "writing-mode", "WritingMode" ),
( "x", "X" ),
+ ( "x1", "X1" ),
+ ( "y1", "Y1" ),
+ ( "x2", "X2" ),
+ ( "y2", "Y2" ),
( "xChannelSelector", "XChannelSelector" ),
( "xlink:href", "XlinkHref" ),
( "xml:lang", "XmlLang" ),
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 90874cd0..b4f590bc 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -12,7 +12,7 @@ use handle::RsvgHandle;
use length::*;
use marker;
use node::*;
-use parsers;
+use parsers::{self, parse};
use path_builder::*;
use path_parser;
use property_bag::{self, PropertyBag};
@@ -212,10 +212,17 @@ impl NodeLine {
impl NodeTrait for NodeLine {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
- self.x1.set (property_bag::parse_or_default (pbag, "x1", LengthDir::Horizontal, None)?);
- self.y1.set (property_bag::parse_or_default (pbag, "y1", LengthDir::Vertical, None)?);
- self.x2.set (property_bag::parse_or_default (pbag, "x2", LengthDir::Horizontal, None)?);
- self.y2.set (property_bag::parse_or_default (pbag, "y2", LengthDir::Vertical, None)?);
+ for (key, value) in pbag.iter() {
+ if let Ok(attr) = Attribute::from_str(key) {
+ match attr {
+ Attribute::X1 => self.x1.set(parse("x1", value, LengthDir::Horizontal, None)?),
+ Attribute::Y1 => self.y1.set(parse("y1", value, LengthDir::Vertical, None)?),
+ Attribute::X2 => self.x2.set(parse("x2", value, LengthDir::Horizontal, None)?),
+ Attribute::Y2 => self.y2.set(parse("y2", value, LengthDir::Vertical, None)?),
+ _ => ()
+ }
+ }
+ }
Ok (())
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]