[librsvg: 22/95] NodeCircle: parse attributes with the PHF



commit 0642702ecedaf6713e8f0f99005a290ad3813fba
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Feb 16 09:21:07 2018 -0600

    NodeCircle: parse attributes with the PHF

 rsvg-attributes.h  |  3 +++
 rust/build.rs      |  3 +++
 rust/src/shapes.rs | 15 +++++++++++----
 3 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index 003cda57..87c92cf3 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -19,6 +19,8 @@ typedef enum {
        RSVG_ATTRIBUTE_CLIP_RULE,
        RSVG_ATTRIBUTE_COLOR,
        RSVG_ATTRIBUTE_COMP_OP,
+       RSVG_ATTRIBUTE_CX,
+       RSVG_ATTRIBUTE_CY,
        RSVG_ATTRIBUTE_D,
        RSVG_ATTRIBUTE_DIFFUSE_CONSTANT,
        RSVG_ATTRIBUTE_DIRECTION,
@@ -78,6 +80,7 @@ typedef enum {
        RSVG_ATTRIBUTE_POINTS_AT_Z,
        RSVG_ATTRIBUTE_PRESERVE_ALPHA,
        RSVG_ATTRIBUTE_PRIMITIVE_UNITS,
+    RSVG_ATTRIBUTE_R,
        RSVG_ATTRIBUTE_RADIUS,
        RSVG_ATTRIBUTE_REQUIRED_EXTENSIONS,
        RSVG_ATTRIBUTE_REQUIRED_FEATURES,
diff --git a/rust/build.rs b/rust/build.rs
index a7e9f5ba..899cacdc 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -26,6 +26,8 @@ fn generate_phf_of_svg_attributes() {
         ( "clip-rule",          "ClipRule" ),
         ( "color",              "Color" ),
         ( "comp-op",            "CompOp" ),
+        ( "cx",                 "Cx" ),
+        ( "cy",                 "Cy" ),
         ( "d",                  "D" ),
         ( "diffuseConstant",    "DiffuseConstant" ),
         ( "direction",          "Direction" ),
@@ -85,6 +87,7 @@ fn generate_phf_of_svg_attributes() {
         ( "pointsAtZ",          "PointsAtZ" ),
         ( "preserveAlpha",      "PreserveAlpha" ),
         ( "primitiveUnits",     "PrimitiveUnits" ),
+        ( "r",                  "R" ),
         ( "radius",             "Radius" ),
         ( "requiredExtensions", "RequiredExtensions" ),
         ( "requiredFeatures",   "RequiredFeatures" ),
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 19777ea5..a91b01aa 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -465,11 +465,18 @@ impl NodeCircle {
 
 impl NodeTrait for NodeCircle {
     fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
-        self.cx.set (property_bag::parse_or_default (pbag, "cx", LengthDir::Horizontal, None)?);
-        self.cy.set (property_bag::parse_or_default (pbag, "cy", LengthDir::Vertical, None)?);
+        for (key, value) in pbag.iter() {
+            if let Ok(attr) = Attribute::from_str(key) {
+                match attr {
+                    Attribute::Cx => self.cx.set(parse("cx", value, LengthDir::Horizontal, None)?),
+                    Attribute::Cy => self.cy.set(parse("cy", value, LengthDir::Vertical, None)?),
+                    Attribute::R  => self.r.set (parse("r",  value, LengthDir::Both,
+                                                       Some(RsvgLength::check_nonnegative))?),
 
-        self.r.set  (property_bag::parse_or_default (pbag, "r", LengthDir::Both,
-                                                     Some(RsvgLength::check_nonnegative))?);
+                    _ => (),
+                }
+            }
+        }
 
         Ok (())
     }


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