[librsvg] Use helper functions get_acquired_href*() everywhere



commit bbf17977a271c7d39941aadf35eddc44cc8cb7c5
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Nov 29 11:09:04 2018 -0600

    Use helper functions get_acquired_href*() everywhere
    
    Now, DrawingCtx::get_acquired_node*() take a Fragment instead of a
    plain string for the element's name.  We'll gradually convert all
    callers to use Fragments instead of strings; to do this, we make
    everything use get_acquired_href*() instead, and we'll remove those
    helper functions eventually.

 rsvg_internals/src/drawing_ctx.rs   | 56 +++++++++++++++++++++++++++----------
 rsvg_internals/src/filters/image.rs |  2 +-
 rsvg_internals/src/gradient.rs      |  2 +-
 rsvg_internals/src/marker.rs        |  2 +-
 rsvg_internals/src/paint_server.rs  |  2 +-
 rsvg_internals/src/pattern.rs       |  2 +-
 rsvg_internals/src/structure.rs     |  2 +-
 rsvg_internals/src/text.rs          |  4 +--
 8 files changed, 49 insertions(+), 23 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 15d8f895..d35efa06 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, Href, RsvgDefs};
+use defs::{Defs, Fragment, Href, RsvgDefs};
 use error::RenderingError;
 use filters;
 use float_eq_cairo::ApproxEqCairo;
@@ -282,6 +282,38 @@ impl<'a> DrawingCtx<'a> {
         &self.bbox
     }
 
+    // This function will go away once all callers are converted to call
+    // get_acquired_node() with an actual Fragment.
+    pub fn get_acquired_href(&mut self, url: &str) -> Option<AcquiredNode> {
+        let href = Href::parse(url).ok()?;
+
+        let fragment = match href {
+            Href::WithFragment(f) => f,
+            _ => return None,
+        };
+
+        self.get_acquired_node(&fragment)
+    }
+
+    // This function will go away once all callers are converted to call
+    // get_acquired_node_of_type() with an actual Fragment.
+    pub fn get_acquired_href_of_type(
+        &mut self,
+        url: Option<&str>,
+        node_type: NodeType,
+    ) -> Option<AcquiredNode> {
+        url.and_then(|url| {
+            let href = Href::parse(url).ok()?;
+
+            let fragment = match href {
+                Href::WithFragment(f) => f,
+                _ => return None,
+            };
+
+            self.get_acquired_node_of_type(Some(&fragment), node_type)
+        })
+    }
+
     // Use this function when looking up urls to other nodes. This function
     // does proper recursion checking and thereby avoids infinite loops.
     //
@@ -291,15 +323,8 @@ impl<'a> DrawingCtx<'a> {
     // Note that if you acquire a node, you have to release it before trying to
     // 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> {
-        let href = Href::parse(url).ok()?;
-
-        let fragment = match href {
-            Href::WithFragment(f) => f,
-            _ => return None,
-        };
-
-        if let Some(node) = self.defs.borrow_mut().lookup(self.handle, &fragment) {
+    pub fn get_acquired_node(&mut self, fragment: &Fragment) -> Option<AcquiredNode> {
+        if let Some(node) = self.defs.borrow_mut().lookup(self.handle, fragment) {
             if !self.acquired_nodes_contains(node) {
                 self.acquired_nodes.borrow_mut().push(node.clone());
                 let acq = AcquiredNode(self.acquired_nodes.clone(), node.clone());
@@ -334,10 +359,11 @@ impl<'a> DrawingCtx<'a> {
     // FIXME: return a Result<AcquiredNode, RenderingError::InvalidReference>
     pub fn get_acquired_node_of_type(
         &mut self,
-        url: Option<&str>,
+        fragment: Option<&Fragment>,
         node_type: NodeType,
     ) -> Option<AcquiredNode> {
-        url.and_then(move |url| self.get_acquired_node(url))
+        fragment
+            .and_then(move |fragment| self.get_acquired_node(fragment))
             .and_then(|acquired| {
                 if acquired.get().get_type() == node_type {
                     Some(acquired)
@@ -377,7 +403,7 @@ impl<'a> DrawingCtx<'a> {
             let affine = original_cr.get_matrix();
 
             let (acquired_clip, clip_units) = {
-                if let Some(acquired) = self.get_acquired_node_of_type(clip_uri, NodeType::ClipPath)
+                if let Some(acquired) = self.get_acquired_href_of_type(clip_uri, NodeType::ClipPath)
                 {
                     let ClipPathUnits(units) = acquired
                         .get()
@@ -463,7 +489,7 @@ impl<'a> DrawingCtx<'a> {
 
                 if let Some(mask) = mask {
                     if let Some(acquired) =
-                        self.get_acquired_node_of_type(Some(mask), NodeType::Mask)
+                        self.get_acquired_href_of_type(Some(mask), NodeType::Mask)
                     {
                         let node = acquired.get();
 
@@ -505,7 +531,7 @@ impl<'a> DrawingCtx<'a> {
     ) -> Result<cairo::ImageSurface, RenderingError> {
         let output = self.surfaces_stack.pop().unwrap();
 
-        match self.get_acquired_node_of_type(Some(filter_uri), NodeType::Filter) {
+        match self.get_acquired_href_of_type(Some(filter_uri), NodeType::Filter) {
             Some(acquired) => {
                 let filter_node = acquired.get();
 
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index 65d00939..3f331383 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -57,7 +57,7 @@ impl Image {
         };
 
         let acquired_drawable = draw_ctx
-            .get_acquired_node(&url)
+            .get_acquired_href(&url)
             .ok_or(FilterError::InvalidInput)?;
         let drawable = acquired_drawable.get();
 
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index 31738fd4..a4533039 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -431,7 +431,7 @@ impl Gradient {
 }
 
 fn acquire_gradient<'a>(draw_ctx: &'a mut DrawingCtx<'_>, name: &str) -> Option<AcquiredNode> {
-    if let Some(acquired) = draw_ctx.get_acquired_node(name) {
+    if let Some(acquired) = draw_ctx.get_acquired_href(name) {
         let node_type = acquired.get().get_type();
 
         if node_type == NodeType::LinearGradient || node_type == NodeType::RadialGradient {
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index ddc4624e..b1d594b9 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -641,7 +641,7 @@ fn emit_marker_by_name(
     line_width: f64,
     clipping: bool,
 ) -> Result<(), RenderingError> {
-    if let Some(acquired) = draw_ctx.get_acquired_node_of_type(Some(name), NodeType::Marker) {
+    if let Some(acquired) = draw_ctx.get_acquired_href_of_type(Some(name), NodeType::Marker) {
         let node = acquired.get();
 
         node.with_impl(|marker: &NodeMarker| {
diff --git a/rsvg_internals/src/paint_server.rs b/rsvg_internals/src/paint_server.rs
index 7919c1f7..9b0e764a 100644
--- a/rsvg_internals/src/paint_server.rs
+++ b/rsvg_internals/src/paint_server.rs
@@ -120,7 +120,7 @@ pub fn set_source_paint_server(
         } => {
             had_paint_server = false;
 
-            if let Some(acquired) = draw_ctx.get_acquired_node(iri.as_str()) {
+            if let Some(acquired) = draw_ctx.get_acquired_href(iri.as_str()) {
                 let node = acquired.get();
 
                 if node.get_type() == NodeType::LinearGradient
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index bf562cd4..c7f2b435 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -249,7 +249,7 @@ impl PaintSource<Pattern> for NodePattern {
         let mut stack = NodeStack::new();
 
         while !result.is_resolved() {
-            if let Some(acquired) = draw_ctx.get_acquired_node_of_type(
+            if let Some(acquired) = draw_ctx.get_acquired_href_of_type(
                 result.fallback.as_ref().map(String::as_ref),
                 NodeType::Pattern,
             ) {
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 7b2be1c7..f3c72181 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -298,7 +298,7 @@ impl NodeTrait for NodeUse {
 
         let uri = link.as_ref().unwrap();
 
-        let child = if let Some(acquired) = draw_ctx.get_acquired_node(uri) {
+        let child = if let Some(acquired) = draw_ctx.get_acquired_href(uri) {
             // Here we clone the acquired child, so that we can drop the AcquiredNode as
             // early as possible.  This is so that the child's drawing method will be able
             // to re-acquire the child for other purposes.
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index cd33a7df..80197017 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -253,7 +253,7 @@ impl NodeTRef {
 
         let url = l.as_ref().unwrap();
 
-        let done = if let Some(acquired) = draw_ctx.get_acquired_node(url) {
+        let done = if let Some(acquired) = draw_ctx.get_acquired_href(url) {
             let c = acquired.get();
             measure_children(&c, cascaded, draw_ctx, length, true)
         } else {
@@ -285,7 +285,7 @@ impl NodeTRef {
 
         let url = l.as_ref().unwrap();
 
-        if let Some(acquired) = draw_ctx.get_acquired_node(url) {
+        if let Some(acquired) = draw_ctx.get_acquired_href(url) {
             let c = acquired.get();
             render_children(&c, cascaded, draw_ctx, x, y, true, clipping)?;
         } else {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]