NodeTRef: use a Fragment for the link, not a String

parent 3c37a0c6
...@@ -2,8 +2,9 @@ use pango::{self, ContextExt, LayoutExt}; ...@@ -2,8 +2,9 @@ use pango::{self, ContextExt, LayoutExt};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use attributes::Attribute; use attributes::Attribute;
use defs::Fragment;
use drawing_ctx::DrawingCtx; use drawing_ctx::DrawingCtx;
use error::RenderingError; use error::{AttributeResultExt, RenderingError};
use font_props::FontWeightSpec; use font_props::FontWeightSpec;
use handle::RsvgHandle; use handle::RsvgHandle;
use length::*; use length::*;
...@@ -228,7 +229,7 @@ impl NodeTrait for NodeText { ...@@ -228,7 +229,7 @@ impl NodeTrait for NodeText {
} }
pub struct NodeTRef { pub struct NodeTRef {
link: RefCell<Option<String>>, link: RefCell<Option<Fragment>>,
} }
impl NodeTRef { impl NodeTRef {
...@@ -245,22 +246,22 @@ impl NodeTRef { ...@@ -245,22 +246,22 @@ impl NodeTRef {
draw_ctx: &mut DrawingCtx<'_>, draw_ctx: &mut DrawingCtx<'_>,
length: &mut f64, length: &mut f64,
) -> bool { ) -> bool {
let l = self.link.borrow(); let link = self.link.borrow();
if l.is_none() { if link.is_none() {
return false; return false;
} }
let url = l.as_ref().unwrap(); let link = link.as_ref().unwrap();
let done = if let Some(acquired) = draw_ctx.get_acquired_href(url) { let done = if let Some(acquired) = draw_ctx.get_acquired_node(link) {
let c = acquired.get(); let c = acquired.get();
measure_children(&c, cascaded, draw_ctx, length, true) measure_children(&c, cascaded, draw_ctx, length, true)
} else { } else {
rsvg_log!( rsvg_log!(
"element {} references a nonexistent text source \"{}\"", "element {} references a nonexistent text source \"{}\"",
node.get_human_readable_name(), node.get_human_readable_name(),
url, link,
); );
false false
}; };
...@@ -277,22 +278,22 @@ impl NodeTRef { ...@@ -277,22 +278,22 @@ impl NodeTRef {
y: &mut f64, y: &mut f64,
clipping: bool, clipping: bool,
) -> Result<(), RenderingError> { ) -> Result<(), RenderingError> {
let l = self.link.borrow(); let link = self.link.borrow();
if l.is_none() { if link.is_none() {
return Ok(()); return Ok(());
} }
let url = l.as_ref().unwrap(); let link = link.as_ref().unwrap();
if let Some(acquired) = draw_ctx.get_acquired_href(url) { if let Some(acquired) = draw_ctx.get_acquired_node(link) {
let c = acquired.get(); let c = acquired.get();
render_children(&c, cascaded, draw_ctx, x, y, true, clipping)?; render_children(&c, cascaded, draw_ctx, x, y, true, clipping)?;
} else { } else {
rsvg_log!( rsvg_log!(
"element {} references a nonexistent text source \"{}\"", "element {} references a nonexistent text source \"{}\"",
node.get_human_readable_name(), node.get_human_readable_name(),
url, link,
); );
} }
...@@ -304,7 +305,10 @@ impl NodeTrait for NodeTRef { ...@@ -304,7 +305,10 @@ impl NodeTrait for NodeTRef {
fn set_atts(&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag<'_>) -> NodeResult { fn set_atts(&self, _: &RsvgNode, _: *const RsvgHandle, pbag: &PropertyBag<'_>) -> NodeResult {
for (_key, attr, value) in pbag.iter() { for (_key, attr, value) in pbag.iter() {
match attr { match attr {
Attribute::XlinkHref => *self.link.borrow_mut() = Some(value.to_owned()), Attribute::XlinkHref => {
*self.link.borrow_mut() =
Some(Fragment::parse(value).attribute(Attribute::XlinkHref)?)
}
_ => (), _ => (),
} }
} }
......
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