diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-05-09 19:47:33 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2018-05-09 19:47:33 +0000 |
| commit | e312c345ba946b59dcd228d1e4d382b51aa37e9d (patch) | |
| tree | 4291cf591ca52682a00bc72341dc1d626058c6d0 /src/xml | |
| parent | Reset code to reaply (diff) | |
| download | inkscape-e312c345ba946b59dcd228d1e4d382b51aa37e9d.tar.gz inkscape-e312c345ba946b59dcd228d1e4d382b51aa37e9d.zip | |
Apply fixed
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/node.h | 19 | ||||
| -rw-r--r-- | src/xml/repr-io.cpp | 3 | ||||
| -rw-r--r-- | src/xml/simple-node.cpp | 92 | ||||
| -rw-r--r-- | src/xml/simple-node.h | 4 |
4 files changed, 112 insertions, 6 deletions
diff --git a/src/xml/node.h b/src/xml/node.h index 29cfdab46..8d9fc19e4 100644 --- a/src/xml/node.h +++ b/src/xml/node.h @@ -384,6 +384,20 @@ public: */ virtual void changeOrder(Node *child, Node *after)=0; + /** + * @brief Remove all elements that not in src node + * @param src The node to check for elemments into this node + * @param key The attribute to use as the identity attribute + */ + virtual void cleanOriginal(Node *src, gchar const *key)=0; + + + /** + * @brief Compare 2 nodes equality + * @param other The other node to compare + * @param recursive Recursive mode check + */ + virtual bool equal(Node const *other, bool recursive)=0; /** * @brief Merge all children of another node with the current * @@ -397,8 +411,11 @@ public: * * @param src The node to merge into this node * @param key The attribute to use as the identity attribute + * @param noid If true process noid items + * @param key If clean callback to cleanOriginal */ - virtual void mergeFrom(Node const *src, char const *key)=0; + + virtual void mergeFrom(Node const *src, char const *key, bool extension = false, bool clean = false)=0; /*@}*/ diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 2ff9d4776..4873fd4e9 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -873,6 +873,9 @@ static void sp_repr_write_stream_root_element(Node *repr, Writer &out, // Sort attributes in a canonical order (helps with "diffing" SVG files). bool sort = prefs->getBool("/options/svgoutput/sort_attributes"); + if (sort) { + sort = !prefs->getBool("/options/svgoutput/disable_optimizations"); + } if (sort) sp_attribute_sort_tree( repr ); Glib::QueryQuark xml_prefix=g_quark_from_static_string("xml"); diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp index 78fc52a27..a1a7127cc 100644 --- a/src/xml/simple-node.cpp +++ b/src/xml/simple-node.cpp @@ -315,7 +315,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const /*is_ // Check usefulness of attributes on elements in the svg namespace, optionally don't add them to tree. Glib::ustring element = g_quark_to_string(_name); - // g_message("setAttribute: %s: %s: %s", element.c_str(), name, value); + //g_message("setAttribute: %s: %s: %s", element.c_str(), name, value); gchar* cleaned_value = g_strdup( value ); // Only check elements in SVG name space and don't block setting attribute to NULL. @@ -645,28 +645,112 @@ Node *SimpleNode::root() { } } -void SimpleNode::mergeFrom(Node const *src, gchar const *key) { +void SimpleNode::cleanOriginal(Node *src, gchar const *key){ + std::vector<Node *> to_delete; + for ( Node *child = this->firstChild() ; child != NULL ; child = child->next() ) + { + gchar const *id = child->attribute(key); + if (id) { + Node *rch = sp_repr_lookup_child(src, key, id); + if (rch) { + child->cleanOriginal(rch, key); + } else { + to_delete.push_back(child); + } + } else { + to_delete.push_back(child); + } + } + for ( std::vector<Node *>::iterator i = to_delete.begin(); i != to_delete.end(); ++i) { + removeChild(*i); + } +} + +bool SimpleNode::equal(Node const *other, bool recursive) { + if(strcmp(name(),other->name())!= 0){ + return false; + } + if (!(strcmp("sodipodi:namedview", name()))) { + return true; + } + guint orig_length = 0; + guint other_length = 0; + + if(content() && other->content() && strcmp(content(), other->content()) != 0){ + return false; + } + for (List<AttributeRecord const> orig_attr = attributeList(); orig_attr; ++orig_attr) { + for (List<AttributeRecord const> other_attr = other->attributeList(); other_attr; ++other_attr) { + const gchar * key_orig = g_quark_to_string(orig_attr->key); + const gchar * key_other = g_quark_to_string(other_attr->key); + if (!strcmp(key_orig, key_other) && + !strcmp(orig_attr->value, other_attr->value)) + { + other_length++; + break; + } + } + orig_length++; + } + if (orig_length != other_length) { + return false; + } + if (recursive) { + //NOTE: for faster the childs need to be in the same order + Node const *other_child = other->firstChild(); + for ( Node *child = firstChild(); + child; + child = child->next()) + { + if (!child->equal(other_child, recursive)) { + return false; + } + other_child = other_child->next(); + if(!other_child) { + return false; + } + } + } + return true; +} + +void SimpleNode::mergeFrom(Node const *src, gchar const *key, bool extension, bool clean) { g_return_if_fail(src != NULL); g_return_if_fail(key != NULL); g_assert(src != this); setContent(src->content()); + if(_parent) { + setPosition(src->position()); + } + + if (clean) { + Node * srcp = const_cast<Node *>(src); + cleanOriginal(srcp, key); + } for ( Node const *child = src->firstChild() ; child != NULL ; child = child->next() ) { gchar const *id = child->attribute(key); if (id) { Node *rch=sp_repr_lookup_child(this, key, id); - if (rch) { - rch->mergeFrom(child, key); + if (rch && (!extension || rch->equal(child, false))) { + rch->mergeFrom(child, key, extension); } else { + if(rch) { + removeChild(rch); + } + guint pos = child->position(); rch = child->duplicate(_document); appendChild(rch); + rch->setPosition(pos); rch->release(); } } else { + guint pos = child->position(); Node *rch=child->duplicate(_document); appendChild(rch); + rch->setPosition(pos); rch->release(); } } diff --git a/src/xml/simple-node.h b/src/xml/simple-node.h index f2cfa953c..fd41e53a8 100644 --- a/src/xml/simple-node.h +++ b/src/xml/simple-node.h @@ -91,7 +91,9 @@ public: char const *content() const; void setContent(char const *value); - void mergeFrom(Node const *src, char const *key); + void cleanOriginal(Node *src, gchar const *key); + bool equal(Node const *other, bool recursive); + void mergeFrom(Node const *src, char const *key, bool extension = false, bool clean = false); Inkscape::Util::List<AttributeRecord const> attributeList() const { return _attributes; |
