[librsvg: 39/95] NodeImage: Parse atttributes with the PHF
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 39/95] NodeImage: Parse atttributes with the PHF
- Date: Thu, 22 Feb 2018 03:16:25 +0000 (UTC)
commit 10e260e1a7f2d13b9da2e544ae151a36cb48a2d2
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 16 19:56:56 2018 -0600
NodeImage: Parse atttributes with the PHF
rsvg-attributes.h | 2 ++
rust/build.rs | 2 ++
rust/src/mask.rs | 46 ++++++++++++++++++++++++----------------------
3 files changed, 28 insertions(+), 22 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index b5098a43..e9b17b05 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -71,6 +71,8 @@ typedef enum {
RSVG_ATTRIBUTE_MARKER_MID,
RSVG_ATTRIBUTE_MARKER_START,
RSVG_ATTRIBUTE_MASK,
+ RSVG_ATTRIBUTE_MASK_CONTENT_UNITS,
+ RSVG_ATTRIBUTE_MASK_UNITS,
RSVG_ATTRIBUTE_MODE,
RSVG_ATTRIBUTE_NUM_OCTAVES,
RSVG_ATTRIBUTE_OFFSET,
diff --git a/rust/build.rs b/rust/build.rs
index b9f5c13c..a583f45f 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -78,6 +78,8 @@ fn generate_phf_of_svg_attributes() {
( "marker-mid", "MarkerMid" ),
( "marker-start", "MarkerStart" ),
( "mask", "Mask" ),
+ ( "maskContentUnits", "MaskContentUnits" ),
+ ( "maskUnits", "MaskUnits" ),
( "mode", "Mode" ),
( "numOctaves", "NumOctaves" ),
( "offset", "Offset" ),
diff --git a/rust/src/mask.rs b/rust/src/mask.rs
index 54a525a3..2fefcc55 100644
--- a/rust/src/mask.rs
+++ b/rust/src/mask.rs
@@ -1,13 +1,15 @@
use libc;
use std::cell::Cell;
+use std::str::FromStr;
+use attributes::Attribute;
use coord_units::CoordUnits;
use drawing_ctx::RsvgDrawingCtx;
use handle::RsvgHandle;
use length::{RsvgLength, LengthDir};
use node::{NodeResult, NodeTrait, NodeType, RsvgCNodeImpl, RsvgNode, boxed_node_new};
-use parsers::Parse;
-use property_bag::{self, PropertyBag};
+use parsers::{Parse, parse};
+use property_bag::PropertyBag;
coord_units!(MaskUnits, CoordUnits::ObjectBoundingBox);
coord_units!(MaskContentUnits, CoordUnits::UserSpaceOnUse);
@@ -47,26 +49,26 @@ impl NodeMask {
impl NodeTrait for NodeMask {
fn set_atts(&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
- self.x.set(property_bag::parse_or_value(pbag, "x",
- LengthDir::Horizontal,
- NodeMask::get_default_pos(LengthDir::Horizontal),
- None)?);
- self.y.set(property_bag::parse_or_value(pbag, "y",
- LengthDir::Vertical,
- NodeMask::get_default_pos(LengthDir::Vertical),
- None)?);
-
- self.width.set (property_bag::parse_or_value (pbag, "width",
- LengthDir::Horizontal,
- NodeMask::get_default_size(LengthDir::Horizontal),
- Some(RsvgLength::check_nonnegative))?);
- self.height.set (property_bag::parse_or_value (pbag, "height",
- LengthDir::Vertical,
- NodeMask::get_default_size(LengthDir::Vertical),
- Some(RsvgLength::check_nonnegative))?);
-
- self.units.set(property_bag::parse_or_default(pbag, "maskUnits", (), None)?);
- self.content_units.set(property_bag::parse_or_default(pbag, "maskContentUnits", (), 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.width.set(parse("width", value, LengthDir::Horizontal,
+ Some(RsvgLength::check_nonnegative))?),
+ Attribute::Height => self.height.set(parse("height", value, LengthDir::Vertical,
+ Some(RsvgLength::check_nonnegative))?),
+
+ Attribute::MaskUnits =>
+ self.units.set(parse("maskUnits", value, (), None)?),
+
+ Attribute::MaskContentUnits =>
+ self.content_units.set(parse("maskContentUnits", value, (), None)?),
+
+ _ => (),
+ }
+ }
+ }
Ok(())
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]