[librsvg: 40/95] NodeMarker: Parse attributes using the PHF
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 40/95] NodeMarker: Parse attributes using the PHF
- Date: Thu, 22 Feb 2018 03:16:30 +0000 (UTC)
commit 5595f35ebb6b6df3b0028efa3fce9c0d172f1c7a
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 16 20:07:09 2018 -0600
NodeMarker: Parse attributes using the PHF
rsvg-attributes.h | 6 ++++++
rust/build.rs | 6 ++++++
rust/src/marker.rs | 50 +++++++++++++++++++++++++++++++++-----------------
3 files changed, 45 insertions(+), 17 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index e9b17b05..da31a16c 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -70,6 +70,9 @@ typedef enum {
RSVG_ATTRIBUTE_MARKER_END,
RSVG_ATTRIBUTE_MARKER_MID,
RSVG_ATTRIBUTE_MARKER_START,
+ RSVG_ATTRIBUTE_MARKER_HEIGHT,
+ RSVG_ATTRIBUTE_MARKER_UNITS,
+ RSVG_ATTRIBUTE_MARKER_WIDTH,
RSVG_ATTRIBUTE_MASK,
RSVG_ATTRIBUTE_MASK_CONTENT_UNITS,
RSVG_ATTRIBUTE_MASK_UNITS,
@@ -79,6 +82,7 @@ typedef enum {
RSVG_ATTRIBUTE_OPACITY,
RSVG_ATTRIBUTE_OPERATOR,
RSVG_ATTRIBUTE_ORDER,
+ RSVG_ATTRIBUTE_ORIENT,
RSVG_ATTRIBUTE_OVERFLOW,
RSVG_ATTRIBUTE_PARSE,
RSVG_ATTRIBUTE_PATH,
@@ -94,6 +98,8 @@ typedef enum {
RSVG_ATTRIBUTE_PRIMITIVE_UNITS,
RSVG_ATTRIBUTE_R,
RSVG_ATTRIBUTE_RADIUS,
+ RSVG_ATTRIBUTE_REF_X,
+ RSVG_ATTRIBUTE_REF_Y,
RSVG_ATTRIBUTE_REQUIRED_EXTENSIONS,
RSVG_ATTRIBUTE_REQUIRED_FEATURES,
RSVG_ATTRIBUTE_RESULT,
diff --git a/rust/build.rs b/rust/build.rs
index a583f45f..421f39b0 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -77,6 +77,9 @@ fn generate_phf_of_svg_attributes() {
( "marker-end", "MarkerEnd" ),
( "marker-mid", "MarkerMid" ),
( "marker-start", "MarkerStart" ),
+ ( "markerHeight", "MarkerHeight" ),
+ ( "markerUnits", "MarkerUnits" ),
+ ( "markerWidth", "MarkerWidth" ),
( "mask", "Mask" ),
( "maskContentUnits", "MaskContentUnits" ),
( "maskUnits", "MaskUnits" ),
@@ -86,6 +89,7 @@ fn generate_phf_of_svg_attributes() {
( "opacity", "Opacity" ),
( "operator", "Operator" ),
( "order", "Order" ),
+ ( "orient", "Orient" ),
( "overflow", "Overflow" ),
( "parse", "Parse" ),
( "path", "Path" ),
@@ -101,6 +105,8 @@ fn generate_phf_of_svg_attributes() {
( "primitiveUnits", "PrimitiveUnits" ),
( "r", "R" ),
( "radius", "Radius" ),
+ ( "refX", "RefX" ),
+ ( "refY", "RefY" ),
( "requiredExtensions", "RequiredExtensions" ),
( "requiredFeatures", "RequiredFeatures" ),
( "result", "Result" ),
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index 7dce4073..321484c3 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -2,10 +2,12 @@ use libc;
use std::cell::Cell;
use std::f64::consts::*;
+use std::str::FromStr;
use cairo::MatrixTrait;
use aspect_ratio::*;
+use attributes::Attribute;
use drawing_ctx;
use drawing_ctx::RsvgDrawingCtx;
use error::*;
@@ -14,9 +16,9 @@ use length::*;
use node::*;
use path_builder::*;
use parsers;
-use parsers::Parse;
+use parsers::{Parse, parse};
use parsers::ParseError;
-use property_bag::{self, PropertyBag};
+use property_bag::PropertyBag;
use util::*;
use viewbox::*;
@@ -191,25 +193,39 @@ impl NodeMarker {
impl NodeTrait for NodeMarker {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag) -> NodeResult {
- self.units.set (property_bag::parse_or_default (pbag, "markerUnits", (), None)?);
+ for (key, value) in pbag.iter() {
+ if let Ok(attr) = Attribute::from_str(key) {
+ match attr {
+ Attribute::MarkerUnits =>
+ self.units.set(parse("markerUnits", value, (), None)?),
- self.ref_x.set (property_bag::parse_or_default (pbag, "refX", LengthDir::Horizontal, None)?);
- self.ref_y.set (property_bag::parse_or_default (pbag, "refY", LengthDir::Vertical, None)?);
+ Attribute::RefX =>
+ self.ref_x.set(parse("refX", value, LengthDir::Horizontal, None)?),
- self.width.set (property_bag::parse_or_value (pbag, "markerWidth",
- LengthDir::Horizontal,
- NodeMarker::get_default_size (LengthDir::Horizontal),
- Some(RsvgLength::check_nonnegative))?);
+ Attribute::RefY =>
+ self.ref_y.set(parse("refY", value, LengthDir::Vertical, None)?),
- self.height.set (property_bag::parse_or_value (pbag, "markerHeight",
- LengthDir::Vertical,
- NodeMarker::get_default_size (LengthDir::Vertical),
- Some(RsvgLength::check_nonnegative))?);
+ Attribute::MarkerWidth =>
+ self.width.set(parse("markerWidth", value, LengthDir::Horizontal,
+ Some(RsvgLength::check_nonnegative))?),
- self.orient.set (property_bag::parse_or_default (pbag, "orient", (), None)?);
- self.aspect.set (property_bag::parse_or_default (pbag, "preserveAspectRatio", (), None)?);
- self.vbox.set (property_bag::parse_or_none (pbag, "viewBox", (), None)?);
- self.aspect.set (property_bag::parse_or_default (pbag, "preserveAspectRatio", (), None)?);
+ Attribute::MarkerHeight =>
+ self.height.set(parse("markerHeight", value, LengthDir::Vertical,
+ Some(RsvgLength::check_nonnegative))?),
+
+ Attribute::Orient =>
+ self.orient.set(parse("orient", value, (), None)?),
+
+ Attribute::PreserveAspectRatio =>
+ self.aspect.set(parse("preserveAspectRatio", value, (), None)?),
+
+ Attribute::ViewBox =>
+ self.vbox.set(Some(parse("viewBox", value, (), None)?)),
+
+ _ => (),
+ }
+ }
+ }
Ok (())
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]