[librsvg] Use AttributeResultExt in pattern.rs
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Use AttributeResultExt in pattern.rs
- Date: Fri, 30 Nov 2018 00:31:56 +0000 (UTC)
commit 36dac5dd0cc40c76cda7d2f1689d431af8351c48
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Nov 29 17:55:26 2018 -0600
Use AttributeResultExt in pattern.rs
rsvg_internals/src/defs.rs | 16 ++++++++++++++++
rsvg_internals/src/pattern.rs | 16 +++++++++-------
2 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index d536b704..96651304 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -6,8 +6,10 @@ use std::ptr;
use std::rc::Rc;
use allowed_url::AllowedUrl;
+use error::ValueErrorKind;
use handle::{self, RsvgHandle};
use node::{Node, RsvgNode};
+use parsers::ParseError;
use util::rsvg_g_warning;
use util::utf8_cstr;
@@ -141,6 +143,20 @@ pub enum HrefError {
FragmentRequired,
}
+impl From<HrefError> for ValueErrorKind {
+ fn from(e: HrefError) -> ValueErrorKind {
+ match e {
+ HrefError::ParseError => ValueErrorKind::Parse(ParseError::new("url parse error")),
+ HrefError::FragmentForbidden => {
+ ValueErrorKind::Value("fragment identifier not allowed".to_string())
+ }
+ HrefError::FragmentRequired => {
+ ValueErrorKind::Value("fragment identifier required".to_string())
+ }
+ }
+ }
+}
+
impl Href {
/// Parses a string into an Href, or returns an error
///
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index c7f2b435..f599b0e0 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -9,8 +9,9 @@ use aspect_ratio::*;
use attributes::Attribute;
use bbox::*;
use coord_units::CoordUnits;
+use defs::Fragment;
use drawing_ctx::{DrawingCtx, NodeStack};
-use error::RenderingError;
+use error::{AttributeResultExt, RenderingError};
use float_eq_cairo::ApproxEqCairo;
use handle::RsvgHandle;
use length::*;
@@ -36,7 +37,7 @@ pub struct Pattern {
pub vbox: Option<Option<ViewBox>>,
pub preserve_aspect_ratio: Option<AspectRatio>,
pub affine: Option<cairo::Matrix>,
- pub fallback: Option<String>,
+ pub fallback: Option<Fragment>,
pub x: Option<Length>,
pub y: Option<Length>,
pub width: Option<Length>,
@@ -204,7 +205,9 @@ impl NodeTrait for NodePattern {
p.affine = Some(parse("patternTransform", value, ())?)
}
- Attribute::XlinkHref => p.fallback = Some(value.to_owned()),
+ Attribute::XlinkHref => {
+ p.fallback = Some(Fragment::parse(value).attribute(Attribute::XlinkHref)?);
+ }
Attribute::X => p.x = Some(parse("x", value, LengthDir::Horizontal)?),
@@ -249,10 +252,9 @@ impl PaintSource<Pattern> for NodePattern {
let mut stack = NodeStack::new();
while !result.is_resolved() {
- if let Some(acquired) = draw_ctx.get_acquired_href_of_type(
- result.fallback.as_ref().map(String::as_ref),
- NodeType::Pattern,
- ) {
+ if let Some(acquired) =
+ draw_ctx.get_acquired_node_of_type(result.fallback.as_ref(), NodeType::Pattern)
+ {
let node = acquired.get();
if stack.contains(node) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]