[librsvg: 13/48] Port standard_element_end() to Rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 13/48] Port standard_element_end() to Rust
- Date: Sat, 17 Nov 2018 10:21:07 +0000 (UTC)
commit cb8e8e572601738ac7d287ae14ead3c7f1174d1a
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Sep 6 20:57:46 2018 -0500
Port standard_element_end() to Rust
librsvg/rsvg-load.c | 27 ++-------------------------
rsvg_internals/src/lib.rs | 3 +--
rsvg_internals/src/load.rs | 36 ------------------------------------
rsvg_internals/src/node.rs | 1 -
rsvg_internals/src/xml.rs | 41 ++++++++++++++++++++++++++++++++++++++---
5 files changed, 41 insertions(+), 67 deletions(-)
---
diff --git a/librsvg/rsvg-load.c b/librsvg/rsvg-load.c
index da9baeee..d36d7598 100644
--- a/librsvg/rsvg-load.c
+++ b/librsvg/rsvg-load.c
@@ -60,6 +60,7 @@ extern void rsvg_xml_state_pop_element_name(RsvgXmlState *xml);
extern gboolean rsvg_xml_state_topmost_element_name_is(RsvgXmlState *xml, const char *name);
extern void rsvg_xml_state_free_element_name_stack(RsvgXmlState *xml);
extern void rsvg_xml_state_standard_element_start(RsvgXmlState *xml, RsvgHandle *handle, const char *name,
RsvgPropertyBag atts);
+extern void rsvg_xml_state_standard_element_end(RsvgXmlState *xml, RsvgHandle *handle, const char *name);
/* Holds the XML parsing state */
typedef struct {
@@ -582,30 +583,6 @@ sax_start_element_cb (void *data, const xmlChar * name, const xmlChar ** atts)
rsvg_property_bag_free (bag);
}
-static void
-standard_element_end (RsvgLoad *load, const char *name)
-{
- RsvgNode *current_node;
-
- current_node = rsvg_xml_state_get_current_node (load->xml.rust_state);
-
- if (current_node) {
- rsvg_load_set_svg_node_atts (load->handle, current_node);
- }
-
- if (current_node && rsvg_xml_state_topmost_element_name_is (load->xml.rust_state, name)) {
- RsvgNode *parent;
-
- parent = rsvg_node_get_parent (current_node);
- rsvg_xml_state_set_current_node (load->xml.rust_state, parent);
- parent = rsvg_node_unref (parent);
-
- rsvg_xml_state_pop_element_name (load->xml.rust_state);
- }
-
- current_node = rsvg_node_unref (current_node);
-}
-
static void
sax_end_element_cb (void *data, const xmlChar * xmlname)
{
@@ -627,7 +604,7 @@ sax_end_element_cb (void *data, const xmlChar * xmlname)
load->xml.handler = NULL;
}
- standard_element_end (load, name);
+ rsvg_xml_state_standard_element_end (load->xml.rust_state, load->handle, name);
}
}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 22b75082..a7f8649a 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -44,8 +44,6 @@ pub use drawing_ctx::{
rsvg_drawing_ctx_new,
};
-pub use load::rsvg_load_set_svg_node_atts;
-
pub use node::{
rsvg_node_add_child,
rsvg_node_children_iter_begin,
@@ -86,6 +84,7 @@ pub use xml::{
rsvg_xml_state_push_element_name,
rsvg_xml_state_set_current_node,
rsvg_xml_state_set_root,
+ rsvg_xml_state_standard_element_end,
rsvg_xml_state_standard_element_start,
rsvg_xml_state_steal_tree,
rsvg_xml_state_topmost_element_name_is,
diff --git a/rsvg_internals/src/load.rs b/rsvg_internals/src/load.rs
index b7892f26..7682e954 100644
--- a/rsvg_internals/src/load.rs
+++ b/rsvg_internals/src/load.rs
@@ -22,7 +22,6 @@ use filters::{
turbulence::Turbulence,
};
use gradient::NodeGradient;
-use handle::RsvgHandle;
use image::NodeImage;
use link::NodeLink;
use marker::NodeMarker;
@@ -307,38 +306,3 @@ pub fn rsvg_load_new_node(
node
}
-
-pub fn rsvg_load_set_node_atts(
- handle: *const RsvgHandle,
- node: &RsvgNode,
- tag: &str,
- pbag: &PropertyBag,
-) {
- node.set_atts(node, handle, pbag);
-
- // The "svg" node is special; it will load its id/class
- // attributes until the end, when sax_end_element_cb() calls
- // rsvg_node_svg_apply_atts()
- if node.get_type() != NodeType::Svg {
- node.set_style(handle, pbag);
- }
-
- node.set_overridden_properties();
-}
-
-#[no_mangle]
-pub extern "C" fn rsvg_load_set_svg_node_atts(
- handle: *const RsvgHandle,
- raw_node: *const RsvgNode,
-) {
- assert!(!raw_node.is_null());
- let node: &RsvgNode = unsafe { &*raw_node };
-
- if node.get_type() != NodeType::Svg {
- return;
- }
-
- node.with_impl(|svg: &NodeSvg| {
- svg.set_delayed_style(node, handle);
- });
-}
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index a2d35446..789b6007 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -690,7 +690,6 @@ pub fn node_new(
element_name,
id,
class,
- rsvg_state_new(),
node_impl,
))
}
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 3fa36094..9dddce81 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -9,6 +9,7 @@ use handle::{self, RsvgHandle};
use load::rsvg_load_new_node;
use node::{box_node, Node, NodeType, RsvgNode};
use property_bag::PropertyBag;
+use structure::NodeSvg;
use tree::{RsvgTree, Tree};
use util::utf8_cstr;
@@ -104,15 +105,34 @@ impl XmlState {
new_node.set_atts(&new_node, handle, pbag);
- // The "svg" node is special; it will load its id/class
- // attributes until the end, when sax_end_element_cb() calls
- // rsvg_node_svg_apply_atts()
+ // The "svg" node is special; it will parse its style attributes
+ // until the end, in standard_element_end().
if new_node.get_type() != NodeType::Svg {
new_node.parse_style_attributes(handle, name, pbag);
}
new_node.set_overridden_properties();
}
+
+ pub fn standard_element_end(&mut self, handle: *const RsvgHandle, name: &str) {
+ if let Some(ref current_node) = self.current_node.clone() {
+ // The "svg" node is special; it parses its style attributes
+ // here, not during element creation.
+ if current_node.get_type() == NodeType::Svg {
+ current_node.with_impl(|svg: &NodeSvg| {
+ svg.parse_style_attributes(current_node, handle);
+ });
+ }
+
+ if self.topmost_element_name_is(name) {
+ let parent = current_node.get_parent();
+
+ self.set_current_node(parent);
+
+ self.pop_element_name();
+ }
+ }
+ }
}
#[no_mangle]
@@ -244,3 +264,18 @@ pub extern "C" fn rsvg_xml_state_standard_element_start(
xml.standard_element_start(handle, name, pbag);
}
+
+#[no_mangle]
+pub extern "C" fn rsvg_xml_state_standard_element_end(
+ xml: *mut RsvgXmlState,
+ handle: *const RsvgHandle,
+ name: *const libc::c_char,
+) {
+ assert!(!xml.is_null());
+ let xml = unsafe { &mut *(xml as *mut XmlState) };
+
+ assert!(!name.is_null());
+ let name = unsafe { utf8_cstr(name) };
+
+ xml.standard_element_end(handle, name);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]