Use AttributeResultExt in pattern.rs

parent 61bac80c
......@@ -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
///
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment