Port standard_element_end() to Rust

parent 94155d9b
......@@ -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);
}
}
......
......@@ -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,
......
......@@ -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);
});
}
......@@ -690,7 +690,6 @@ pub fn node_new(
element_name,
id,
class,
rsvg_state_new(),
node_impl,
))
}
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment