[librsvg/librsvg-2.44] Node: add an element_name field



commit b7b988644141420a7724ebbd31f079dcbdc7d091
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Sep 14 10:38:27 2018 -0500

    Node: add an element_name field
    
    Normally each node type corresponds to a single element name, so in
    theory we could derive the name from the NodeType.  However, we
    translate unknown element names to NodeDefs, so a NodeDefs may refer
    to not only <defs>.
    
    Here we add an element_name field to the Node struct, so each specific
    node may know to what SVG element it corresponds.

 rsvg_internals/src/load.rs |  7 ++++---
 rsvg_internals/src/node.rs | 16 ++++++++++++++++
 rsvg_internals/src/text.rs |  1 +
 3 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/rsvg_internals/src/load.rs b/rsvg_internals/src/load.rs
index 3d0b6ff5..18250e83 100644
--- a/rsvg_internals/src/load.rs
+++ b/rsvg_internals/src/load.rs
@@ -40,11 +40,12 @@ use util::utf8_cstr;
 macro_rules! node_create_fn {
     ($name:ident, $node_type:ident, $new_fn:expr) => {
         fn $name(
+            element_name: &str,
             id: Option<&str>,
             class: Option<&str>,
             parent: *const RsvgNode,
         ) -> *const RsvgNode {
-            boxed_node_new(NodeType::$node_type, parent, id, class, Box::new($new_fn()))
+            boxed_node_new(NodeType::$node_type, parent, element_name, id, class, Box::new($new_fn()))
         }
     };
 }
@@ -168,7 +169,7 @@ node_create_fn!(
 );
 node_create_fn!(create_use, Use, NodeUse::new);
 
-type NodeCreateFn = fn(Option<&str>, Option<&str>, *const RsvgNode) -> *const RsvgNode;
+type NodeCreateFn = fn(&str, Option<&str>, Option<&str>, *const RsvgNode) -> *const RsvgNode;
 
 lazy_static! {
     // Lines in comments are elements that we don't support.
@@ -301,7 +302,7 @@ pub extern "C" fn rsvg_load_new_node(
         class = None;
     };
 
-    let node = create_fn(id, class, parent);
+    let node = create_fn(name, id, class, parent);
     assert!(!node.is_null());
 
     if id.is_some() {
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 187e72b9..8ed0f88b 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -162,6 +162,7 @@ pub type NodeResult = Result<(), NodeError>;
 pub struct Node {
     node_type: NodeType,
     parent: Option<Weak<Node>>, // optional; weak ref to parent
+    element_name: String,       // we may want to intern these someday
     id: Option<String>,         // id attribute from XML element
     class: Option<String>,      // class attribute from XML element
     first_child: RefCell<Option<Rc<Node>>>,
@@ -243,6 +244,7 @@ impl Node {
     pub fn new(
         node_type: NodeType,
         parent: Option<Weak<Node>>,
+        element_name: &str,
         id: Option<&str>,
         class: Option<&str>,
         node_impl: Box<NodeTrait>,
@@ -250,6 +252,7 @@ impl Node {
         Node {
             node_type,
             parent,
+            element_name: element_name.to_string(),
             id: id.map(str::to_string),
             class: class.map(str::to_string),
             first_child: RefCell::new(None),
@@ -673,6 +676,7 @@ pub fn node_ptr_to_weak(raw_parent: *const RsvgNode) -> Option<Weak<Node>> {
 pub fn boxed_node_new(
     node_type: NodeType,
     raw_parent: *const RsvgNode,
+    element_name: &str,
     id: Option<&str>,
     class: Option<&str>,
     node_impl: Box<NodeTrait>,
@@ -680,6 +684,7 @@ pub fn boxed_node_new(
     box_node(Rc::new(Node::new(
         node_type,
         node_ptr_to_weak(raw_parent),
+        element_name,
         id,
         class,
         node_impl,
@@ -861,6 +866,7 @@ mod tests {
         let node = Rc::new(Node::new(
             NodeType::Path,
             None,
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -886,6 +892,7 @@ mod tests {
         let node = Rc::new(Node::new(
             NodeType::Path,
             None,
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -908,6 +915,7 @@ mod tests {
         let node = Rc::new(Node::new(
             NodeType::Path,
             None,
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -921,6 +929,7 @@ mod tests {
         let node = Rc::new(Node::new(
             NodeType::Path,
             None,
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -929,6 +938,7 @@ mod tests {
         let child = Rc::new(Node::new(
             NodeType::Path,
             Some(Rc::downgrade(&node)),
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -945,6 +955,7 @@ mod tests {
         let node = Rc::new(Node::new(
             NodeType::Path,
             None,
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -953,6 +964,7 @@ mod tests {
         let child = Rc::new(Node::new(
             NodeType::Path,
             Some(Rc::downgrade(&node)),
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -961,6 +973,7 @@ mod tests {
         let second_child = Rc::new(Node::new(
             NodeType::Path,
             Some(Rc::downgrade(&node)),
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -990,6 +1003,7 @@ mod tests {
         let node = Rc::new(Node::new(
             NodeType::Path,
             None,
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -998,6 +1012,7 @@ mod tests {
         let child = Rc::new(Node::new(
             NodeType::Path,
             Some(Rc::downgrade(&node)),
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
@@ -1006,6 +1021,7 @@ mod tests {
         let second_child = Rc::new(Node::new(
             NodeType::Path,
             Some(Rc::downgrade(&node)),
+            "path",
             None,
             None,
             Box::new(TestNodeImpl {}),
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 168255cc..fe46d0ad 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -756,6 +756,7 @@ pub extern "C" fn rsvg_node_chars_new(raw_parent: *const RsvgNode) -> *const Rsv
     boxed_node_new(
         NodeType::Chars,
         raw_parent,
+        "rsvg_chars",
         None,
         None,
         Box::new(NodeChars::new()),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]