summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-10-08 13:50:02 +0000
committertavmjong-free <tavmjong@free.fr>2014-10-08 13:50:02 +0000
commit2d1ff6f2eb9798e2f1f24caa5af6b4e2cdde1df7 (patch)
tree0767640fd5c726d9e7c428957d981e1220266eac /src/extension
parentSome template cleanup... (diff)
downloadinkscape-2d1ff6f2eb9798e2f1f24caa5af6b4e2cdde1df7.tar.gz
inkscape-2d1ff6f2eb9798e2f1f24caa5af6b4e2cdde1df7.zip
Allow <sodipodi:namedview> attributes to be set by scripts.
This is a bit of a hack... Why does <sodipode:namedview> need special treatment? (bzr r13341.1.258)
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/implementation/script.cpp98
1 files changed, 66 insertions, 32 deletions
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index cac11031f..377b872bc 100644
--- a/src/extension/implementation/script.cpp
+++ b/src/extension/implementation/script.cpp
@@ -726,12 +726,12 @@ void Script::effect(Inkscape::Extension::Effect *module,
vd->emitReconstructionStart();
copy_doc(vd->rroot, mydoc->rroot);
vd->emitReconstructionFinish();
- SPObject *layer = NULL;
-
+
// Getting the named view from the document generated by the extension
SPNamedView *nv = sp_document_namedview(mydoc, NULL);
//Check if it has a default layer set up
+ SPObject *layer = NULL;
if ( nv != NULL)
{
if( nv->default_layer_id != 0 ) {
@@ -760,19 +760,21 @@ void Script::effect(Inkscape::Extension::Effect *module,
/**
- \brief A function to take all the svg elements from one document
- and put them in another.
- \param oldroot The root node of the document to be replaced
- \param newroot The root node of the document to replace it with
-
- This function first deletes all of the data in the old document. It
- does this by creating a list of what needs to be deleted, and then
- goes through the list. This two pass approach removes issues with
- the list being change while parsing through it. Lots of nasty bugs.
-
- Then, it goes through the new document, duplicating all of the
- elements and putting them into the old document. The copy
- is then complete.
+ \brief A function to replace all the elements in an old document
+ by those from a new document.
+ document and repinserts them into an emptied old document.
+ \param oldroot The root node of the old (destination) document.
+ \param newroot The root node of the new (source) document.
+
+ This function first deletes all the elements in the old document by
+ making two pass, the first to create a list of the old elements and
+ the second to actually delete them. This two pass approach removes issues
+ with the list being change while parsing through it... lots of nasty bugs.
+
+ Then, it copies all the element in the new document into the old document.
+
+ Finally, it replaces the attributes in the root element of the old document
+ by the attributes in root of the new document.
*/
void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot)
{
@@ -781,9 +783,19 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr
g_warning("Error on copy_doc: NULL pointer input.");
return;
}
+
+ // For copying attributes in root and in namedview
+ using Inkscape::Util::List;
+ using Inkscape::XML::AttributeRecord;
+
+ // Question: Why is the "sodipodi:namedview" special? Treating it as a normal
+ // elmement results in crashes.
+
std::vector<Inkscape::XML::Node *> delete_list;
Inkscape::XML::Node * oldroot_namedview = NULL;
+ Inkscape::XML::Node * newroot_namedview = NULL;
+ // Make list
for (Inkscape::XML::Node * child = oldroot->firstChild();
child != NULL;
child = child->next()) {
@@ -798,14 +810,18 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr
delete_list.push_back(child);
}
}
+
+ // Unparent (delete)
for (unsigned int i = 0; i < delete_list.size(); i++) {
sp_repr_unparent(delete_list[i]);
}
+ // Copy
for (Inkscape::XML::Node * child = newroot->firstChild();
child != NULL;
child = child->next()) {
if (!strcmp("sodipodi:namedview", child->name())) {
+ newroot_namedview = child;
if (oldroot_namedview != NULL) {
for (Inkscape::XML::Node * newroot_namedview_child = child->firstChild();
newroot_namedview_child != NULL;
@@ -818,26 +834,44 @@ void Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newr
}
}
- {
- using Inkscape::Util::List;
- using Inkscape::XML::AttributeRecord;
- std::vector<gchar const *> attribs;
+ std::vector<gchar const *> attribs;
- // Make a list of all attributes of the old root node.
- for (List<AttributeRecord const> iter = oldroot->attributeList(); iter; ++iter) {
- attribs.push_back(g_quark_to_string(iter->key));
- }
+ // Must explicitly copy root attributes.
- // Delete the attributes of the old root nodes.
- for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) {
- oldroot->setAttribute(*it, NULL);
- }
+ // Make a list of all attributes of the old root node.
+ for (List<AttributeRecord const> iter = oldroot->attributeList(); iter; ++iter) {
+ attribs.push_back(g_quark_to_string(iter->key));
+ }
- // Set the new attributes.
- for (List<AttributeRecord const> iter = newroot->attributeList(); iter; ++iter) {
- gchar const *name = g_quark_to_string(iter->key);
- oldroot->setAttribute(name, newroot->attribute(name));
- }
+ // Delete the attributes of the old root node.
+ for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) {
+ oldroot->setAttribute(*it, NULL);
+ }
+
+ // Set the new attributes.
+ for (List<AttributeRecord const> iter = newroot->attributeList(); iter; ++iter) {
+ gchar const *name = g_quark_to_string(iter->key);
+ oldroot->setAttribute(name, newroot->attribute(name));
+ }
+
+ attribs.clear();
+
+ // Must explicitly copy namedview attributes.
+
+ // Make a list of all attributes of the old namedview node.
+ for (List<AttributeRecord const> iter = oldroot_namedview->attributeList(); iter; ++iter) {
+ attribs.push_back(g_quark_to_string(iter->key));
+ }
+
+ // Delete the attributes of the old namedview node.
+ for (std::vector<gchar const *>::const_iterator it = attribs.begin(); it != attribs.end(); ++it) {
+ oldroot_namedview->setAttribute(*it, NULL);
+ }
+
+ // Set the new attributes.
+ for (List<AttributeRecord const> iter = newroot_namedview->attributeList(); iter; ++iter) {
+ gchar const *name = g_quark_to_string(iter->key);
+ oldroot_namedview->setAttribute(name, newroot_namedview->attribute(name));
}
/** \todo Restore correct layer */