[librsvg: 17/22] Make get_node_of_type() take a slice of valid types, instead of a single one
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 17/22] Make get_node_of_type() take a slice of valid types, instead of a single one
- Date: Wed, 2 Oct 2019 21:45:04 +0000 (UTC)
commit 878b08ef0d678b99ff4667104e20917b9a7d17f8
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Oct 2 09:40:46 2019 -0500
Make get_node_of_type() take a slice of valid types, instead of a single one
We'll remove get_node() then.
rsvg_internals/src/drawing_ctx.rs | 19 +++++++++++++------
rsvg_internals/src/marker.rs | 2 +-
rsvg_internals/src/pattern.rs | 2 +-
3 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 7e76ba06..b5ee08ef 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -341,7 +341,7 @@ impl DrawingCtx {
) -> (Option<RsvgNode>, Option<RsvgNode>) {
clip_uri
.and_then(|fragment| {
- self.acquired_nodes.get_node_of_type(fragment, NodeType::ClipPath).ok()
+ self.acquired_nodes.get_node_of_type(fragment, &[NodeType::ClipPath]).ok()
})
.and_then(|acquired| {
let clip_node = acquired.get().clone();
@@ -472,7 +472,7 @@ impl DrawingCtx {
if let Some(fragment) = mask {
if let Ok(acquired) = dc
.acquired_nodes
- .get_node_of_type(fragment, NodeType::Mask)
+ .get_node_of_type(fragment, &[NodeType::Mask])
{
let mask_node = acquired.get();
@@ -551,7 +551,7 @@ impl DrawingCtx {
) -> Result<cairo::ImageSurface, RenderingError> {
match self
.acquired_nodes
- .get_node_of_type(filter_uri, NodeType::Filter)
+ .get_node_of_type(filter_uri, &[NodeType::Filter])
{
Ok(acquired) => {
let filter_node = acquired.get();
@@ -1122,6 +1122,8 @@ impl AcquiredNodes {
// the node to be of a particular type. This function does proper recursion
// checking and thereby avoids infinite loops.
//
+ // 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.
//
@@ -1131,14 +1133,19 @@ impl AcquiredNodes {
pub fn get_node_of_type(
&self,
fragment: &Fragment,
- node_type: NodeType,
+ node_types: &[NodeType],
) -> Result<AcquiredNode, AcquireError> {
self.get_node(fragment)
.and_then(|acquired| {
- if acquired.get().borrow().get_type() == node_type {
+ if node_types.len() == 0 {
Ok(acquired)
} else {
- Err(AcquireError::InvalidLinkType(fragment.clone()))
+ let acquired_type = acquired.get().borrow().get_type();
+ if node_types.iter().find(|&&t| t == acquired_type).is_some() {
+ Ok(acquired)
+ } else {
+ Err(AcquireError::InvalidLinkType(fragment.clone()))
+ }
}
})
}
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 18c9c70b..090df1e9 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -590,7 +590,7 @@ fn emit_marker_by_name(
) -> Result<BoundingBox, RenderingError> {
if let Ok(acquired) = draw_ctx
.acquired_nodes()
- .get_node_of_type(name, NodeType::Marker)
+ .get_node_of_type(name, &[NodeType::Marker])
{
let node = acquired.get();
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index e1ec12bb..c237095e 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().get_node_of_type(&fragment, NodeType::Pattern) {
+ match draw_ctx.acquired_nodes().get_node_of_type(&fragment, &[NodeType::Pattern]) {
Ok(acquired) => {
let acquired_node = acquired.get();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]