[librsvg: 16/95] Process the d attribute of NodePath with the PHF



commit f08c159459d856632c4fc1ff113091abeac921b2
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Feb 12 19:18:13 2018 -0600

    Process the d attribute of NodePath with the PHF

 rsvg-attributes.h  |  1 +
 rust/build.rs      |  1 +
 rust/src/shapes.rs | 20 +++++++++++++-------
 3 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index 32fd1e16..4ec73e56 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -19,6 +19,7 @@ typedef enum {
        RSVG_ATTRIBUTE_CLIP_RULE,
        RSVG_ATTRIBUTE_COLOR,
        RSVG_ATTRIBUTE_COMP_OP,
+       RSVG_ATTRIBUTE_D,
        RSVG_ATTRIBUTE_DIFFUSE_CONSTANT,
        RSVG_ATTRIBUTE_DIRECTION,
        RSVG_ATTRIBUTE_DISPLAY,
diff --git a/rust/build.rs b/rust/build.rs
index f4ae2eb5..8121bfd2 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -26,6 +26,7 @@ fn generate_phf_of_svg_attributes() {
         ( "clip-rule",          "ClipRule" ),
         ( "color",              "Color" ),
         ( "comp-op",            "CompOp" ),
+        ( "d",                  "D" ),
         ( "diffuseConstant",    "DiffuseConstant" ),
         ( "direction",          "Direction" ),
         ( "display",            "Display" ),
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index e0d1535a..0d27bf6c 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -2,7 +2,9 @@ use libc;
 
 use std::cell::RefCell;
 use std::cell::Cell;
+use std::str::FromStr;
 
+use attributes::Attribute;
 use drawing_ctx;
 use drawing_ctx::*;
 use error::*;
@@ -88,15 +90,19 @@ impl NodePath {
 
 impl NodeTrait for NodePath {
     fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
-        if let Some (value) = pbag.lookup("d") {
-            let mut builder = RsvgPathBuilder::new ();
+        for (key, value) in pbag.iter() {
+            if let Ok(attr) = Attribute::from_str(key) {
+                if attr == Attribute::D {
+                    let mut builder = RsvgPathBuilder::new ();
 
-            if path_parser::parse_path_into_builder (&value, &mut builder).is_err() {
-                // FIXME: we don't propagate errors upstream, but creating a partial
-                // path is OK per the spec
-            }
+                    if path_parser::parse_path_into_builder (&value, &mut builder).is_err() {
+                        // FIXME: we don't propagate errors upstream, but creating a partial
+                        // path is OK per the spec
+                    }
 
-            *self.builder.borrow_mut() = Some(builder);
+                    *self.builder.borrow_mut() = Some(builder);
+                }
+            }
         }
 
         Ok (())


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