[librsvg: 20/22] Make AcquiredNodes private; use DrawingCtx::acquire_node() everywhere instead
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 20/22] Make AcquiredNodes private; use DrawingCtx::acquire_node() everywhere instead
- Date: Wed, 2 Oct 2019 21:45:19 +0000 (UTC)
commit 78670b22cbe51980fe15ca59735d696729dcb2e6
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Oct 2 10:07:00 2019 -0500
Make AcquiredNodes private; use DrawingCtx::acquire_node() everywhere instead
Everything used to call draw_ctx.acquired_nodes().acquire(...); it is
shorter to do draw_ctx.acquire_node(...) now.
rsvg_internals/src/drawing_ctx.rs | 60 ++++++++++++++++++-------------------
rsvg_internals/src/filters/image.rs | 3 +-
rsvg_internals/src/gradient.rs | 2 +-
rsvg_internals/src/marker.rs | 2 +-
rsvg_internals/src/pattern.rs | 2 +-
rsvg_internals/src/structure.rs | 2 +-
rsvg_internals/src/text.rs | 2 +-
7 files changed, 35 insertions(+), 38 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index e9223b9a..b2c0c4af 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -330,8 +330,27 @@ impl DrawingCtx {
})
}
- pub fn acquired_nodes(&self) -> &AcquiredNodes {
- &self.acquired_nodes
+ // Use this function when looking up urls to other nodes, and when you expect
+ // the node to be of a particular type. This function does proper recursion
+ // checking and thereby avoids infinite loops.
+ //
+ // Nodes acquired by this function must be released in reverse
+ // acquiring order.
+ //
+ // Specify an empty slice for `node_types` if you want a node of any type.
+ //
+ // Malformed SVGs, for example, may reference a marker by its IRI, but
+ // the object referenced by the IRI is not a marker.
+ //
+ // 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 None the second time.
+ pub fn acquire_node(
+ &self,
+ fragment: &Fragment,
+ node_types: &[NodeType]
+ ) -> Result<AcquiredNode, AcquireError> {
+ self.acquired_nodes.acquire(fragment, node_types)
}
// Returns (clip_in_user_space, clip_in_object_space), both Option<RsvgNode>
@@ -341,9 +360,7 @@ impl DrawingCtx {
) -> (Option<RsvgNode>, Option<RsvgNode>) {
clip_uri
.and_then(|fragment| {
- self.acquired_nodes
- .acquire(fragment, &[NodeType::ClipPath])
- .ok()
+ self.acquire_node(fragment, &[NodeType::ClipPath]).ok()
})
.and_then(|acquired| {
let clip_node = acquired.get().clone();
@@ -472,9 +489,7 @@ impl DrawingCtx {
// Mask
if let Some(fragment) = mask {
- if let Ok(acquired) = dc
- .acquired_nodes
- .acquire(fragment, &[NodeType::Mask])
+ if let Ok(acquired) = dc.acquire_node(fragment, &[NodeType::Mask])
{
let mask_node = acquired.get();
@@ -555,9 +570,7 @@ impl DrawingCtx {
child_surface: &cairo::ImageSurface,
node_bbox: BoundingBox,
) -> Result<cairo::ImageSurface, RenderingError> {
- match self
- .acquired_nodes
- .acquire(filter_uri, &[NodeType::Filter])
+ match self.acquire_node(filter_uri, &[NodeType::Filter])
{
Ok(acquired) => {
let filter_node = acquired.get();
@@ -609,7 +622,7 @@ impl DrawingCtx {
}
fn acquire_paint_server(&self, fragment: &Fragment) -> Result<AcquiredNode, AcquireError> {
- self.acquired_nodes.acquire(
+ self.acquire_node(
fragment,
&[
NodeType::LinearGradient,
@@ -1090,13 +1103,13 @@ impl AcquiredNode {
}
}
-pub struct AcquiredNodes {
+struct AcquiredNodes {
svg: Rc<Svg>,
node_stack: Rc<RefCell<NodeStack>>,
}
impl AcquiredNodes {
- pub fn new(svg: Rc<Svg>) -> AcquiredNodes {
+ fn new(svg: Rc<Svg>) -> AcquiredNodes {
AcquiredNodes {
svg,
node_stack: Rc::new(RefCell::new(NodeStack::new())),
@@ -1125,22 +1138,7 @@ impl AcquiredNodes {
}
}
- // Use this function when looking up urls to other nodes, and when you expect
- // the node to be of a particular type. This function does proper recursion
- // checking and thereby avoids infinite loops.
- //
- // Nodes acquired by this function must be released in reverse
- // acquiring order.
- //
- // Specify an empty slice for `node_types` if you want a node of any type.
- //
- // Malformed SVGs, for example, may reference a marker by its IRI, but
- // the object referenced by the IRI is not a marker.
- //
- // 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 None the second time.
- pub fn acquire(
+ fn acquire(
&self,
fragment: &Fragment,
node_types: &[NodeType],
@@ -1163,7 +1161,7 @@ impl AcquiredNodes {
/// Keeps a stack of nodes and can check if a certain node is contained in the stack
///
/// Sometimes parts of the code cannot plainly use the implicit stack of acquired
-/// nodes as maintained by DrawingCtx::acquired_nodes, and they must keep their
+/// nodes as maintained by DrawingCtx::acquire_node(), and they must keep their
/// own stack of nodes to test for reference cycles. NodeStack can be used to do that.
pub struct NodeStack(Vec<RsvgNode>);
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index aee13153..a8d69cac 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -45,8 +45,7 @@ impl Image {
fragment: &Fragment,
) -> Result<ImageSurface, FilterError> {
let acquired_drawable = draw_ctx
- .acquired_nodes()
- .acquire(fragment, &[])
+ .acquire_node(fragment, &[])
.map_err(|_| FilterError::InvalidInput)?;
let drawable = acquired_drawable.get();
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index 71e65785..817607f4 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -781,7 +781,7 @@ fn acquire_gradient<'a>(
draw_ctx: &'a mut DrawingCtx,
fragment: &Fragment,
) -> Result<AcquiredNode, AcquireError> {
- draw_ctx.acquired_nodes().acquire(fragment, &[NodeType::LinearGradient, NodeType::RadialGradient])
+ draw_ctx.acquire_node(fragment, &[NodeType::LinearGradient, NodeType::RadialGradient])
}
#[cfg(test)]
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 94850fb2..54121013 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -588,7 +588,7 @@ fn emit_marker_by_name(
line_width: f64,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
- if let Ok(acquired) = draw_ctx.acquired_nodes().acquire(name, &[NodeType::Marker])
+ if let Ok(acquired) = draw_ctx.acquire_node(name, &[NodeType::Marker])
{
let node = acquired.get();
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index 44aa740b..58a98ef6 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -170,7 +170,7 @@ impl PaintSource for NodePattern {
while !pattern.is_resolved() {
if let Some(ref fragment) = fallback {
- match draw_ctx.acquired_nodes().acquire(&fragment, &[NodeType::Pattern]) {
+ match draw_ctx.acquire_node(&fragment, &[NodeType::Pattern]) {
Ok(acquired) => {
let acquired_node = acquired.get();
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index de66e30f..8771100d 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -315,7 +315,7 @@ impl NodeTrait for NodeUse {
let link = self.link.as_ref().unwrap();
- let child = if let Ok(acquired) = draw_ctx.acquired_nodes().acquire(link, &[]) {
+ let child = if let Ok(acquired) = draw_ctx.acquire_node(link, &[]) {
// 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 9870f724..5f8cece8 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -676,7 +676,7 @@ impl NodeTRef {
let link = self.link.as_ref().unwrap();
let values = cascaded.get();
- if let Ok(acquired) = draw_ctx.acquired_nodes().acquire(link, &[]) {
+ if let Ok(acquired) = draw_ctx.acquire_node(link, &[]) {
let c = acquired.get();
extract_chars_children_to_chunks_recursively(chunks, &c, values, depth);
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]