[librsvg: 5/6] xml: use the descendants() iterato to set styles
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/6] xml: use the descendants() iterato to set styles
- Date: Sat, 29 Jun 2019 21:50:51 +0000 (UTC)
commit 735dcc5b0a086eefc2b0db07c50218d2fc1d3eee
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jun 29 22:05:33 2019 +0200
xml: use the descendants() iterato to set styles
No need anymore to do our own recursion. Note that the iterator
includes the root node itself.
rsvg_internals/src/xml.rs | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
---
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index e2f24c6b..b6e55895 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -114,9 +114,12 @@ impl XmlState {
match self.tree_root {
None => Err(LoadingError::SvgHasNoElements),
Some(ref root) if root.borrow().get_type() == NodeType::Svg => {
- let mut root = self.tree_root.take().unwrap();
+ let root = self.tree_root.take().unwrap();
+ let css_rules = self.css_rules.as_ref().unwrap();
- set_styles_recursively(&mut root, self.css_rules.as_ref().unwrap());
+ for mut node in root.descendants() {
+ node.borrow_mut().set_style(css_rules);
+ }
Ok(Svg::new(
root,
@@ -520,14 +523,6 @@ fn skip_namespace(s: &str) -> &str {
s.find(':').map_or(s, |pos| &s[pos + 1..])
}
-fn set_styles_recursively(node: &mut RsvgNode, css_rules: &CssRules) {
- node.borrow_mut().set_style(css_rules);
-
- for mut child in node.children() {
- set_styles_recursively(&mut child, css_rules);
- }
-}
-
// https://www.w3.org/TR/xml-stylesheet/
//
// The syntax for the xml-stylesheet processing instruction we support
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]