[librsvg: 21/95] NodeRect: parse attributes with the PHF
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 21/95] NodeRect: parse attributes with the PHF
- Date: Thu, 22 Feb 2018 03:14:54 +0000 (UTC)
commit d0b454b857c927f64c2dcf3701052da31841f15b
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Feb 13 13:56:33 2018 -0600
NodeRect: parse attributes with the PHF
rsvg-attributes.h | 2 ++
rust/build.rs | 2 ++
rust/src/shapes.rs | 28 +++++++++++++++++++++-------
3 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index f8b8de5e..003cda57 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -82,6 +82,8 @@ typedef enum {
RSVG_ATTRIBUTE_REQUIRED_EXTENSIONS,
RSVG_ATTRIBUTE_REQUIRED_FEATURES,
RSVG_ATTRIBUTE_RESULT,
+ RSVG_ATTRIBUTE_RX,
+ RSVG_ATTRIBUTE_RY,
RSVG_ATTRIBUTE_SCALE,
RSVG_ATTRIBUTE_SEED,
RSVG_ATTRIBUTE_SHAPE_RENDERING,
diff --git a/rust/build.rs b/rust/build.rs
index a7d208b5..a7e9f5ba 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -89,6 +89,8 @@ fn generate_phf_of_svg_attributes() {
( "requiredExtensions", "RequiredExtensions" ),
( "requiredFeatures", "RequiredFeatures" ),
( "result", "Result" ),
+ ( "rx", "Rx" ),
+ ( "ry", "Ry" ),
( "scale", "Scale" ),
( "seed", "Seed" ),
( "shape-rendering", "ShapeRendering" ),
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index b4f590bc..19777ea5 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -276,13 +276,27 @@ impl NodeRect {
impl NodeTrait for NodeRect {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
- self.x.set (property_bag::parse_or_default (pbag, "x", LengthDir::Horizontal, None)?);
- self.y.set (property_bag::parse_or_default (pbag, "y", LengthDir::Vertical, None)?);
- self.w.set (property_bag::parse_or_default (pbag, "width", LengthDir::Horizontal, None)?);
- self.h.set (property_bag::parse_or_default (pbag, "height", LengthDir::Vertical, None)?);
-
- self.rx.set (property_bag::parse_or_none (pbag, "rx", LengthDir::Horizontal, None)?);
- self.ry.set (property_bag::parse_or_none (pbag, "ry", LengthDir::Vertical, None)?);
+ for (key, value) in pbag.iter() {
+ if let Ok(attr) = Attribute::from_str(key) {
+ match attr {
+ Attribute::X => self.x.set (parse ("x", value, LengthDir::Horizontal, None)?),
+ Attribute::Y => self.y.set (parse ("y", value, LengthDir::Vertical, None)?),
+ Attribute::Width => self.w.set (parse ("width", value, LengthDir::Horizontal,
+ Some(RsvgLength::check_nonnegative))?),
+ Attribute::Height => self.h.set (parse ("height", value, LengthDir::Vertical,
+ Some(RsvgLength::check_nonnegative))?),
+
+ Attribute::Rx => self.rx.set (parse ("rx", value, LengthDir::Horizontal,
+ Some(RsvgLength::check_nonnegative))
+ .map(Some)?),
+ Attribute::Ry => self.ry.set (parse ("ry", value, LengthDir::Vertical,
+ Some(RsvgLength::check_nonnegative))
+ .map(Some)?),
+
+ _ => (),
+ }
+ }
+ }
Ok (())
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]