[librsvg: 18/22] Remove the public AcquiredNodes::get_type(); use get_node_of_type() everywhere
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 18/22] Remove the public AcquiredNodes::get_type(); use get_node_of_type() everywhere
- Date: Wed, 2 Oct 2019 21:45:09 +0000 (UTC)
commit 3b0da95b8385d8c767bb8d9eaeaf8d31cb4e56bf
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Oct 2 09:54:27 2019 -0500
Remove the public AcquiredNodes::get_type(); use get_node_of_type() everywhere
rsvg_internals/src/drawing_ctx.rs | 75 ++++++++++++++++++++++---------------
rsvg_internals/src/filters/image.rs | 2 +-
rsvg_internals/src/gradient.rs | 11 +-----
rsvg_internals/src/structure.rs | 2 +-
rsvg_internals/src/text.rs | 2 +-
5 files changed, 49 insertions(+), 43 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index b5ee08ef..f3800d10 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -341,7 +341,9 @@ 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();
@@ -484,7 +486,11 @@ impl DrawingCtx {
.map(|_: ()| bbox)
});
} else {
- rsvg_log!("element {} references nonexistent mask \"{}\"", node, fragment);
+ rsvg_log!(
+ "element {} references nonexistent mask \"{}\"",
+ node,
+ fragment
+ );
}
} else {
// No mask, so composite the temporary surface
@@ -602,6 +608,17 @@ impl DrawingCtx {
);
}
+ fn acquire_paint_server(&self, fragment: &Fragment) -> Result<AcquiredNode, AcquireError> {
+ self.acquired_nodes.get_node_of_type(
+ fragment,
+ &[
+ NodeType::LinearGradient,
+ NodeType::RadialGradient,
+ NodeType::Pattern,
+ ],
+ )
+ }
+
pub fn set_source_paint_server(
&mut self,
ps: &PaintServer,
@@ -616,7 +633,7 @@ impl DrawingCtx {
} => {
let mut had_paint_server = false;
- if let Ok(acquired) = self.acquired_nodes.get_node(iri) {
+ if let Ok(acquired) = self.acquire_paint_server(iri) {
let node = acquired.get();
had_paint_server = match node.borrow().get_type() {
@@ -632,7 +649,7 @@ impl DrawingCtx {
.borrow()
.get_impl::<NodePattern>()
.resolve_fallbacks_and_set_pattern(&node, self, opacity, bbox)?,
- _ => false,
+ _ => unreachable!(),
}
}
@@ -1095,19 +1112,18 @@ impl AcquiredNodes {
// 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_node(&self, fragment: &Fragment) -> Result<AcquiredNode, AcquireError> {
- let node = self.svg.lookup(fragment)
- .map_err(|_| {
- // FIXME: callers shouldn't have to know that get_node() can initiate a file load.
- // Maybe we should have the following stages:
- // - load main SVG XML
- //
- // - load secondary SVG XML and other files like images;
- // all svg::Resources and svg::Images loaded
- //
- // - Now that all files are loaded, resolve URL references
- AcquireError::LinkNotFound(fragment.clone())
- })?;
+ fn lookup_node(&self, fragment: &Fragment) -> Result<AcquiredNode, AcquireError> {
+ let node = self.svg.lookup(fragment).map_err(|_| {
+ // FIXME: callers shouldn't have to know that get_node() can initiate a file load.
+ // Maybe we should have the following stages:
+ // - load main SVG XML
+ //
+ // - load secondary SVG XML and other files like images;
+ // all svg::Resources and svg::Images loaded
+ //
+ // - Now that all files are loaded, resolve URL references
+ AcquireError::LinkNotFound(fragment.clone())
+ })?;
if self.node_stack.borrow().contains(&node) {
Err(AcquireError::CircularReference(fragment.clone()))
@@ -1135,19 +1151,18 @@ impl AcquiredNodes {
fragment: &Fragment,
node_types: &[NodeType],
) -> Result<AcquiredNode, AcquireError> {
- self.get_node(fragment)
- .and_then(|acquired| {
- if node_types.len() == 0 {
- Ok(acquired)
- } else {
- 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()))
- }
- }
- })
+ let acquired = self.lookup_node(fragment)?;
+
+ if node_types.len() == 0 {
+ Ok(acquired)
+ } else {
+ 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/filters/image.rs b/rsvg_internals/src/filters/image.rs
index 98e064e7..86c563ef 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -46,7 +46,7 @@ impl Image {
) -> Result<ImageSurface, FilterError> {
let acquired_drawable = draw_ctx
.acquired_nodes()
- .get_node(fragment)
+ .get_node_of_type(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 ee386456..614050e3 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -781,16 +781,7 @@ fn acquire_gradient<'a>(
draw_ctx: &'a mut DrawingCtx,
fragment: &Fragment,
) -> Result<AcquiredNode, AcquireError> {
- draw_ctx.acquired_nodes().get_node(fragment)
- .and_then(|acquired| {
- let node_type = acquired.get().borrow().get_type();
-
- match node_type {
- NodeType::LinearGradient => Ok(acquired),
- NodeType::RadialGradient => Ok(acquired),
- _ => Err(AcquireError::InvalidLinkType(fragment.clone()))
- }
- })
+ draw_ctx.acquired_nodes().get_node_of_type(fragment, &[NodeType::LinearGradient,
NodeType::RadialGradient])
}
#[cfg(test)]
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 62489928..62224e14 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().get_node(link) {
+ let child = if let Ok(acquired) = draw_ctx.acquired_nodes().get_node_of_type(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 525cdb5f..a563a235 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().get_node(link) {
+ if let Ok(acquired) = draw_ctx.acquired_nodes().get_node_of_type(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]