[librsvg: 38/95] NodeImage: Parse attributes with the PHF
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 38/95] NodeImage: Parse attributes with the PHF
- Date: Thu, 22 Feb 2018 03:16:20 +0000 (UTC)
commit a25331fde6b6c1a381e3b6bd01b5811e18eedeb7
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 16 19:48:02 2018 -0600
NodeImage: Parse attributes with the PHF
rsvg-attributes.h | 1 +
rust/build.rs | 1 +
rust/src/image.rs | 73 +++++++++++++++++++++++++++++++------------------------
3 files changed, 43 insertions(+), 32 deletions(-)
---
diff --git a/rsvg-attributes.h b/rsvg-attributes.h
index d96ef203..b5098a43 100644
--- a/rsvg-attributes.h
+++ b/rsvg-attributes.h
@@ -79,6 +79,7 @@ typedef enum {
RSVG_ATTRIBUTE_ORDER,
RSVG_ATTRIBUTE_OVERFLOW,
RSVG_ATTRIBUTE_PARSE,
+ RSVG_ATTRIBUTE_PATH,
RSVG_ATTRIBUTE_PATTERN_CONTENT_UNITS,
RSVG_ATTRIBUTE_PATTERN_TRANSFORM,
RSVG_ATTRIBUTE_PATTERN_UNITS,
diff --git a/rust/build.rs b/rust/build.rs
index b8173f78..b9f5c13c 100644
--- a/rust/build.rs
+++ b/rust/build.rs
@@ -86,6 +86,7 @@ fn generate_phf_of_svg_attributes() {
( "order", "Order" ),
( "overflow", "Overflow" ),
( "parse", "Parse" ),
+ ( "path", "Path" ),
( "patternContentUnits", "PatternContentUnits" ),
( "patternTransform", "PatternTransform" ),
( "patternUnits", "PatternUnits" ),
diff --git a/rust/src/image.rs b/rust/src/image.rs
index 0f29ac01..ec49bd51 100644
--- a/rust/src/image.rs
+++ b/rust/src/image.rs
@@ -6,15 +6,18 @@ use glib::translate::*;
use glib_sys;
use std::cell::{Cell, RefCell};
use std::ptr;
+use std::str::FromStr;
use drawing_ctx;
use drawing_ctx::RsvgDrawingCtx;
use aspect_ratio::*;
+use attributes::Attribute;
use handle::RsvgHandle;
use length::*;
use node::*;
-use property_bag::{self, PropertyBag};
+use parsers::parse;
+use property_bag::PropertyBag;
struct NodeImage {
aspect: Cell<AspectRatio>,
@@ -40,37 +43,43 @@ impl NodeImage {
impl NodeTrait for NodeImage {
fn set_atts (&self, _: &RsvgNode, handle: *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,
- Some(RsvgLength::check_nonnegative))?);
- self.h.set (property_bag::parse_or_default (pbag, "height", LengthDir::Vertical,
- Some(RsvgLength::check_nonnegative))?);
- self.aspect.set (property_bag::parse_or_default (pbag, "preserveAspectRatio", (), None)?);
-
- let mut href = pbag.lookup("xlink:href");
-
- if href.is_none() {
- // "path" is used by some older adobe illustrator versions
- href = pbag.lookup("path");
- }
-
- if let Some(href) = href {
- extern "C" { fn rsvg_cairo_surface_new_from_href
- (handle: *const RsvgHandle,
- href: *const libc::c_char,
- error: *mut *mut glib_sys::GError) -> *mut cairo_sys::cairo_surface_t;
- }
-
- let mut error = ptr::null_mut();
-
- let raw_surface = unsafe { rsvg_cairo_surface_new_from_href (handle,
- href.to_glib_none().0,
- &mut error) };
- if !raw_surface.is_null() {
- *self.surface.borrow_mut() = Some(unsafe { cairo::ImageSurface::from_raw_full
(raw_surface).unwrap() });
- } else {
- let _: glib::Error = unsafe { from_glib_full(error) }; // FIXME: we should note that the
image couldn't be loaded
+ 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::PreserveAspectRatio =>
+ self.aspect.set(parse("preserveAspectRatio", value, (), None)?),
+
+ Attribute::XlinkHref |
+ Attribute::Path => {
+ // "path" is used by some older Adobe Illustrator versions
+
+ extern "C" { fn rsvg_cairo_surface_new_from_href
+ (handle: *const RsvgHandle,
+ href: *const libc::c_char,
+ error: *mut *mut glib_sys::GError) -> *mut cairo_sys::cairo_surface_t;
+ }
+
+ let mut error = ptr::null_mut();
+
+ let raw_surface = unsafe { rsvg_cairo_surface_new_from_href (handle,
+ value.to_glib_none().0,
+ &mut error) };
+ if !raw_surface.is_null() {
+ *self.surface.borrow_mut() = Some(unsafe { cairo::ImageSurface::from_raw_full
(raw_surface).unwrap() });
+ } else {
+ let _: glib::Error = unsafe { from_glib_full(error) }; // FIXME: we should note
that the image couldn't be loaded
+ }
+ },
+
+ _ => (),
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]