[librsvg] Defs::lookup() - Take a Reference, not a plain href
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Defs::lookup() - Take a Reference, not a plain href
- Date: Thu, 29 Nov 2018 18:05:14 +0000 (UTC)
commit 383a44d0ff974b6e8f2ae17f6650e8992674224c
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Nov 28 12:59:19 2018 -0600
Defs::lookup() - Take a Reference, not a plain href
rsvg_internals/src/defs.rs | 31 ++++++++++++++++++-------------
rsvg_internals/src/drawing_ctx.rs | 6 ++++--
2 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index a5549354..d75b8d39 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -33,20 +33,20 @@ impl Defs {
/// This may return a node within the same RSVG handle, or a node in a secondary RSVG
/// handle that is referenced by the current one. If the element's id is not found,
/// returns `None`.
- pub fn lookup(&mut self, handle: *const RsvgHandle, name: &str) -> Option<&Rc<Node>> {
- if let Ok(reference) = Reference::parse(name) {
- match reference {
- Reference::PlainUri(_) => None,
- Reference::FragmentId(fragment) => self.nodes.get(&fragment),
- Reference::UriWithFragmentId(href, fragment) => {
- match self.get_extern_handle(handle, &href) {
- Ok(extern_handle) => handle::get_defs(extern_handle).nodes.get(&fragment),
- Err(()) => None,
- }
+ pub fn lookup(
+ &mut self,
+ handle: *const RsvgHandle,
+ reference: &Reference,
+ ) -> Option<&Rc<Node>> {
+ match reference {
+ Reference::PlainUri(_) => None,
+ Reference::FragmentId(ref fragment) => self.nodes.get(fragment),
+ Reference::UriWithFragmentId(ref href, ref fragment) => {
+ match self.get_extern_handle(handle, href) {
+ Ok(extern_handle) => handle::get_defs(extern_handle).nodes.get(fragment),
+ Err(()) => None,
}
}
- } else {
- None
}
}
@@ -167,7 +167,12 @@ pub extern "C" fn rsvg_defs_lookup(
let defs = unsafe { &mut *(defs as *mut Defs) };
let name = unsafe { utf8_cstr(name) };
- match defs.lookup(handle, name) {
+ let r = Reference::parse(name);
+ if r.is_err() {
+ return ptr::null();
+ }
+
+ match defs.lookup(handle, &r.unwrap()) {
Some(n) => n as *const RsvgNode,
None => ptr::null(),
}
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 447b8eb7..c90df1b5 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -13,7 +13,7 @@ use std::rc::{Rc, Weak};
use bbox::BoundingBox;
use clip_path::{ClipPathUnits, NodeClipPath};
use coord_units::CoordUnits;
-use defs::{Defs, RsvgDefs};
+use defs::{Defs, Reference, RsvgDefs};
use error::RenderingError;
use filters;
use float_eq_cairo::ApproxEqCairo;
@@ -292,7 +292,9 @@ impl<'a> DrawingCtx<'a> {
// acquire it again. If you acquire a node "#foo" and don't release it before
// trying to acquire "foo" again, you will obtain a %NULL the second time.
pub fn get_acquired_node(&mut self, url: &str) -> Option<AcquiredNode> {
- if let Some(node) = self.defs.borrow_mut().lookup(self.handle, url) {
+ let reference = Reference::parse(url).ok()?;
+
+ if let Some(node) = self.defs.borrow_mut().lookup(self.handle, &reference) {
if !self.acquired_nodes_contains(node) {
self.acquired_nodes.borrow_mut().push(node.clone());
let acq = AcquiredNode(self.acquired_nodes.clone(), node.clone());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]