[librsvg: 37/95] NodeClipPath: parse attributes using the PHF



commit 75fd6ecf652292f0d3370cac3ed06e891a971f51
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Feb 16 19:23:30 2018 -0600

    NodeClipPath: parse attributes using the PHF

 rsvg-attributes.h     |  1 +
 rust/build.rs         |  1 +
 rust/src/clip_path.rs | 16 ++++++++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index 85b8bfc7..d96ef203 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -17,6 +17,7 @@ typedef enum {
     RSVG_ATTRIBUTE_CLASS,
     RSVG_ATTRIBUTE_CLIP_PATH,
     RSVG_ATTRIBUTE_CLIP_RULE,
+    RSVG_ATTRIBUTE_CLIP_PATH_UNITS,
     RSVG_ATTRIBUTE_COLOR,
     RSVG_ATTRIBUTE_COMP_OP,
     RSVG_ATTRIBUTE_CX,
diff --git a/rust/build.rs b/rust/build.rs
index 22594f46..b8173f78 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -24,6 +24,7 @@ fn generate_phf_of_svg_attributes() {
         ( "class",              "Class" ),
         ( "clip-path",          "ClipPath" ),
         ( "clip-rule",          "ClipRule" ),
+        ( "clipPathUnits",      "ClipPathUnits" ),
         ( "color",              "Color" ),
         ( "comp-op",            "CompOp" ),
         ( "cx",                 "Cx" ),
diff --git a/rust/src/clip_path.rs b/rust/src/clip_path.rs
index a2993d48..878010a4 100644
--- a/rust/src/clip_path.rs
+++ b/rust/src/clip_path.rs
@@ -1,11 +1,14 @@
 use libc;
 use std::cell::Cell;
+use std::str::FromStr;
 
+use attributes::Attribute;
 use drawing_ctx::RsvgDrawingCtx;
 use handle::RsvgHandle;
 use node::{NodeResult, NodeTrait, NodeType, RsvgCNodeImpl, RsvgNode, boxed_node_new};
 use coord_units::CoordUnits;
-use property_bag::{self, PropertyBag};
+use parsers::parse;
+use property_bag::PropertyBag;
 
 coord_units!(ClipPathUnits, CoordUnits::UserSpaceOnUse);
 
@@ -23,7 +26,16 @@ impl NodeClipPath {
 
 impl NodeTrait for NodeClipPath {
     fn set_atts(&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
-        self.units.set(property_bag::parse_or_default(pbag, "clipPathUnits", (), None)?);
+        for (key, value) in pbag.iter() {
+            if let Ok(attr) = Attribute::from_str(key) {
+                match attr {
+                    Attribute::ClipPathUnits =>
+                        self.units.set(parse("clipPathUnits", value, (), None)?),
+
+                    _ => (),
+                }
+            }
+        }
 
         Ok(())
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]