[librsvg] Split the scary Node.set_style() into three smaller functions
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Split the scary Node.set_style() into three smaller functions
- Date: Fri, 21 Sep 2018 12:38:45 +0000 (UTC)
commit bfc7194f2321327d9228260a5a9907a6a48336e2
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Sep 14 09:56:35 2018 -0500
Split the scary Node.set_style() into three smaller functions
rsvg_internals/src/node.rs | 52 ++++++++++++++++++++++++++++------------------
1 file changed, 32 insertions(+), 20 deletions(-)
---
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 3bbfaafc..480d8579 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -414,29 +414,30 @@ impl Node {
Ok(())
}
- // Sets the node's state from the style-related attributes in the pbag. Also applies
- // CSS rules in our limited way based on the node's tag/class/id.
- pub fn set_style(&self, handle: *const RsvgHandle, tag: &str, pbag: &PropertyBag<'_>) {
- {
- let mut state = self.state.borrow_mut();
- match state.parse_presentation_attributes(pbag) {
- Ok(_) => (),
- Err(e) => {
- // FIXME: we'll ignore errors here for now.
- // If we return, we expose buggy handling of the enable-background
- // property; we are not parsing it correctly. This causes
- // tests/fixtures/reftests/bugs/587721-text-transform.svg to fail
- // because it has enable-background="new 0 0 1179.75118 687.74173"
- // in the toplevel svg element.
- //
- // self.set_error(e);
- // return;
-
- rsvg_log!("(attribute error: {})", e);
- }
+ /// Hands the pbag to the node's state, to apply the presentation attributes
+ fn set_presentation_attributes(&self, pbag: &PropertyBag<'_>) {
+ let mut state = self.state.borrow_mut();
+ match state.parse_presentation_attributes(pbag) {
+ Ok(_) => (),
+ Err(e) => {
+ // FIXME: we'll ignore errors here for now.
+ //
+ // If we set the node to be in error, we expose buggy handling of the
+ // enable-background property; we are not parsing it correctly. This
+ // causes tests/fixtures/reftests/bugs/587721-text-transform.svg to fail
+ // because it has enable-background="new 0 0 1179.75118 687.74173" in the
+ // toplevel svg element.
+ //
+ // self.set_error(e);
+ // return;
+
+ rsvg_log!("(attribute error: {})", e);
}
}
+ }
+ /// Implements a very limited CSS selection engine
+ fn set_css_styles(&self, handle: *const RsvgHandle, tag: &str) {
// Try to properly support all of the following, including inheritance:
// *
// #id
@@ -508,7 +509,10 @@ impl Node {
rsvg_lookup_apply_css_style(handle, target.to_glib_none().0, state_ptr);
}
}
+ }
+ /// Looks for the "style" attribute in the pbag, and applies CSS styles from it
+ fn set_style_attribute(&self, pbag: &PropertyBag<'_>) {
for (_key, attr, value) in pbag.iter() {
match attr {
Attribute::Style => {
@@ -524,6 +528,14 @@ impl Node {
}
}
+ // Sets the node's state from the style-related attributes in the pbag. Also applies
+ // CSS rules in our limited way based on the node's tag/class/id.
+ pub fn set_style(&self, handle: *const RsvgHandle, tag: &str, pbag: &PropertyBag<'_>) {
+ self.set_presentation_attributes(pbag);
+ self.set_css_styles(handle, tag);
+ self.set_style_attribute(pbag);
+ }
+
pub fn set_overridden_properties(&self) {
let mut state = self.state.borrow_mut();
self.node_impl.set_overridden_properties(&mut state);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]