From: mental Date: Tue, 20 Mar 2007 22:54:29 +0000 (+0000) Subject: plumb XML::Document parameter into duplication, courtesy of bryce X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7333a6d3d0e1b6b738726a859e5875d5d97b27d9;p=inkscape.git plumb XML::Document parameter into duplication, courtesy of bryce --- diff --git a/src/dialogs/stroke-style.cpp b/src/dialogs/stroke-style.cpp index 7894a89b8..e1640e6af 100644 --- a/src/dialogs/stroke-style.cpp +++ b/src/dialogs/stroke-style.cpp @@ -585,7 +585,8 @@ sp_marker_prev_new(unsigned psize, gchar const *mname, return NULL; // Create a copy repr of the marker with id="sample" - Inkscape::XML::Node *mrepr = SP_OBJECT_REPR (marker)->duplicate(); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(sandbox); + Inkscape::XML::Node *mrepr = SP_OBJECT_REPR (marker)->duplicate(xml_doc); mrepr->setAttribute("id", "sample"); // Replace the old sample in the sandbox by the new one diff --git a/src/dialogs/xml-tree.cpp b/src/dialogs/xml-tree.cpp index 9ad3c0586..dd5371460 100644 --- a/src/dialogs/xml-tree.cpp +++ b/src/dialogs/xml-tree.cpp @@ -1407,7 +1407,7 @@ void cmd_duplicate_node(GtkObject *object, gpointer data) g_assert(selected_repr != NULL); Inkscape::XML::Node *parent = sp_repr_parent(selected_repr); - Inkscape::XML::Node *dup = selected_repr->duplicate(); + Inkscape::XML::Node *dup = selected_repr->duplicate(parent->document()); parent->addChild(dup, selected_repr); sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR, diff --git a/src/document.cpp b/src/document.cpp index c6dc66a51..e66089fed 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -279,7 +279,7 @@ sp_document_create(Inkscape::XML::Document *rdoc, rnew->setAttribute("id", "base"); } else { // otherwise, take from preferences - rnew = r->duplicate(); + rnew = r->duplicate(rroot->document()); } // insert into the document rroot->addChild(rnew, NULL); diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index af70a04f0..96e4bd855 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -861,7 +861,7 @@ Script::copy_doc (Inkscape::XML::Node * oldroot, Inkscape::XML::Node * newroot) child = child->next()) { if (!strcmp("sodipodi:namedview", child->name())) continue; - oldroot->appendChild(child->duplicate()); + oldroot->appendChild(child->duplicate(newroot->document())); } /** \todo Restore correct layer */ diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 5d8c9a82d..3989f9427 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -83,7 +83,7 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View for (int i = 0; i < steps; i++) { double offset = (width / (float)(steps - 1) * (float)i) - (width / 2.0); - new_items[i] = (SP_OBJECT_REPR(spitem))->duplicate(); + new_items[i] = (SP_OBJECT_REPR(spitem))->duplicate(xml_doc); SPCSSAttr * css = sp_repr_css_attr(new_items[i], "style"); sp_repr_css_set_property(css, "opacity", opacity_string); diff --git a/src/file.cpp b/src/file.cpp index c5347a66e..639ba3913 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -757,13 +757,14 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri, SPObject *defs = SP_DOCUMENT_DEFS(doc); Inkscape::IO::fixupHrefs(doc, in_doc->base, true); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::XML::Node *last_def = SP_OBJECT_REPR(in_defs)->lastChild(); for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child)) { // FIXME: in case of id conflict, newly added thing will be re-ided and thus likely break a reference to it from imported stuff - SP_OBJECT_REPR(in_defs)->addChild(SP_OBJECT_REPR(child)->duplicate(), last_def); + SP_OBJECT_REPR(in_defs)->addChild(SP_OBJECT_REPR(child)->duplicate(xml_doc), last_def); } guint items_count = 0; @@ -784,7 +785,7 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri, for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) { if (SP_IS_ITEM(child)) { - Inkscape::XML::Node *newchild = SP_OBJECT_REPR(child)->duplicate(); + Inkscape::XML::Node *newchild = SP_OBJECT_REPR(child)->duplicate(xml_doc); // convert layers to groups; FIXME: add "preserve layers" mode where each layer // from impot is copied to the same-named layer in host @@ -808,7 +809,7 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri, // just add one item for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) { if (SP_IS_ITEM(child)) { - Inkscape::XML::Node *newitem = SP_OBJECT_REPR(child)->duplicate(); + Inkscape::XML::Node *newitem = SP_OBJECT_REPR(child)->duplicate(xml_doc); newitem->setAttribute("inkscape:groupmode", NULL); if (desktop) { diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 82a88faa3..0a312193d 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -234,11 +234,12 @@ SPGradient * sp_gradient_fork_vector_if_necessary (SPGradient *gr) { if (SP_OBJECT_HREFCOUNT(gr) > 1) { - SPDocument *document = SP_OBJECT_DOCUMENT(gr); + SPDocument *doc = SP_OBJECT_DOCUMENT(gr); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); - Inkscape::XML::Node *repr = SP_OBJECT_REPR (gr)->duplicate(); - SP_OBJECT_REPR (SP_DOCUMENT_DEFS (document))->addChild(repr, NULL); - SPGradient *gr_new = (SPGradient *) document->getObjectByRepr(repr); + Inkscape::XML::Node *repr = SP_OBJECT_REPR (gr)->duplicate(xml_doc); + SP_OBJECT_REPR (SP_DOCUMENT_DEFS (doc))->addChild(repr, NULL); + SPGradient *gr_new = (SPGradient *) doc->getObjectByRepr(repr); gr_new = sp_gradient_ensure_vector_normalized (gr_new); Inkscape::GC::release(repr); return gr_new; @@ -695,7 +696,8 @@ sp_item_gradient_reverse_vector (SPItem *item, bool fill_or_stroke) GSList *child_copies = NULL; for (GSList *i = child_reprs; i != NULL; i = i->next) { Inkscape::XML::Node *repr = (Inkscape::XML::Node *) i->data; - child_copies = g_slist_append (child_copies, repr->duplicate()); + Inkscape::XML::Document *xml_doc = SP_OBJECT_REPR(vector)->document(); + child_copies = g_slist_append (child_copies, repr->duplicate(xml_doc)); } diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index 42b4df578..77947394d 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -286,7 +286,7 @@ sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item, N } Inkscape::XML::Node *new_stop_repr = NULL; - new_stop_repr = SP_OBJECT_REPR(prev_stop)->duplicate(); + new_stop_repr = SP_OBJECT_REPR(prev_stop)->duplicate(SP_OBJECT_REPR(vector)->document()); SP_OBJECT_REPR(vector)->addChild(new_stop_repr, SP_OBJECT_REPR(prev_stop)); SPStop *newstop = (SPStop *) SP_OBJECT_DOCUMENT(vector)->getObjectByRepr(new_stop_repr); diff --git a/src/helper/stock-items.cpp b/src/helper/stock-items.cpp index 0e035e832..575197fee 100644 --- a/src/helper/stock-items.cpp +++ b/src/helper/stock-items.cpp @@ -70,7 +70,8 @@ static SPObject * sp_marker_load_from_svg(gchar const *name, SPDocument *current SPObject *object = doc->getObjectById(name); if (object && SP_IS_MARKER(object)) { SPDefs *defs= (SPDefs *) SP_DOCUMENT_DEFS(current_doc); - Inkscape::XML::Node *mark_repr = SP_OBJECT_REPR(object)->duplicate(); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(current_doc); + Inkscape::XML::Node *mark_repr = SP_OBJECT_REPR(object)->duplicate(xml_doc); SP_OBJECT_REPR(defs)->addChild(mark_repr, NULL); SPObject *cloned_item = current_doc->getObjectByRepr(mark_repr); Inkscape::GC::release(mark_repr); @@ -113,7 +114,8 @@ sp_pattern_load_from_svg(gchar const *name, SPDocument *current_doc) SPObject *object = doc->getObjectById(name); if (object && SP_IS_PATTERN(object)) { SPDefs *defs= (SPDefs *) SP_DOCUMENT_DEFS(current_doc); - Inkscape::XML::Node *pat_repr = SP_OBJECT_REPR(object)->duplicate(); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(current_doc); + Inkscape::XML::Node *pat_repr = SP_OBJECT_REPR(object)->duplicate(xml_doc); SP_OBJECT_REPR(defs)->addChild(pat_repr, NULL); Inkscape::GC::release(pat_repr); return object; @@ -155,7 +157,8 @@ sp_gradient_load_from_svg(gchar const *name, SPDocument *current_doc) SPObject *object = doc->getObjectById(name); if (object && SP_IS_GRADIENT(object)) { SPDefs *defs= (SPDefs *) SP_DOCUMENT_DEFS(current_doc); - Inkscape::XML::Node *pat_repr = SP_OBJECT_REPR(object)->duplicate(); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(current_doc); + Inkscape::XML::Node *pat_repr = SP_OBJECT_REPR(object)->duplicate(xml_doc); SP_OBJECT_REPR(defs)->addChild(pat_repr, NULL); Inkscape::GC::release(pat_repr); return object; diff --git a/src/interface.cpp b/src/interface.cpp index c7608f53a..ac8967513 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -974,11 +974,13 @@ sp_ui_drag_data_received(GtkWidget *widget, guint event_time, gpointer user_data) { + SPDocument *doc = SP_ACTIVE_DOCUMENT; + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + switch (info) { #if ENABLE_MAGIC_COLORS case APP_X_INKY_COLOR: { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; int destX = 0; int destY = 0; gtk_widget_translate_coordinates( widget, &(desktop->canvas->widget), x, y, &destX, &destY ); @@ -1039,7 +1041,6 @@ sp_ui_drag_data_received(GtkWidget *widget, sp_desktop_apply_css_recursive( item, css, true ); item->updateRepr(); - SPDocument *doc = SP_ACTIVE_DOCUMENT; sp_document_done( doc , SP_VERB_NONE, _("Drop color")); @@ -1054,7 +1055,6 @@ sp_ui_drag_data_received(GtkWidget *widget, case APP_X_COLOR: { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; int destX = 0; int destY = 0; gtk_widget_translate_coordinates( widget, &(desktop->canvas->widget), x, y, &destX, &destY ); @@ -1081,7 +1081,6 @@ sp_ui_drag_data_received(GtkWidget *widget, sp_desktop_apply_css_recursive( item, css, true ); item->updateRepr(); - SPDocument *doc = SP_ACTIVE_DOCUMENT; sp_document_done( doc , SP_VERB_NONE, _("Drop color")); } @@ -1093,8 +1092,6 @@ sp_ui_drag_data_received(GtkWidget *widget, case SVG_XML_DATA: { gchar *svgdata = (gchar *)data->data; - SPDocument *doc = SP_ACTIVE_DOCUMENT; - Inkscape::XML::Document *rnewdoc = sp_repr_read_mem(svgdata, data->length, SP_SVG_NS_URI); if (rnewdoc == NULL) { @@ -1108,14 +1105,14 @@ sp_ui_drag_data_received(GtkWidget *widget, Inkscape::XML::Node *newgroup = rnewdoc->createElement("svg:g"); newgroup->setAttribute("style", style); + Inkscape::XML::Document * xml_doc = sp_document_repr_doc(doc); for (Inkscape::XML::Node *child = repr->firstChild(); child != NULL; child = child->next()) { - Inkscape::XML::Node *newchild = child->duplicate(); + Inkscape::XML::Node *newchild = child->duplicate(xml_doc); newgroup->appendChild(newchild); } Inkscape::GC::release(rnewdoc); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // Add it to the current layer // Greg's edits to add intelligent positioning of svg drops @@ -1159,7 +1156,6 @@ sp_ui_drag_data_received(GtkWidget *widget, Base64OutputStream b64out(outs); b64out.setColumnWidth(0); - SPDocument *doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::XML::Node *newImage = xml_doc->createElement("svg:image"); @@ -1194,8 +1190,6 @@ sp_ui_drag_data_received(GtkWidget *widget, } } - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - // Add it to the current layer desktop->currentLayer()->appendChildRepr(newImage); diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h index 16ee1b7ff..26d79396e 100644 --- a/src/jabber_whiteboard/inkboard-document.h +++ b/src/jabber_whiteboard/inkboard-document.h @@ -130,7 +130,7 @@ protected: _initBindings(); } - XML::SimpleNode* _duplicate() const + XML::SimpleNode* _duplicate(XML::Document* xml_doc) const { return new InkboardDocument(*this); } diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 0437414a8..8e6783f20 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -526,7 +526,7 @@ static void stamp_repr(Inkscape::NodePath::Path *np) g_assert(np); Inkscape::XML::Node *old_repr = SP_OBJECT(np->path)->repr; - Inkscape::XML::Node *new_repr = old_repr->duplicate(); + Inkscape::XML::Node *new_repr = old_repr->duplicate(old_repr->document()); // remember the position of the item gint pos = old_repr->position(); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 1fe70b896..f8548cdc4 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -72,26 +72,29 @@ #include "helper/units.h" #include "sp-item.h" #include "unit-constants.h" +#include "xml/simple-document.h" + using NR::X; using NR::Y; #include "selection-chemistry.h" /* fixme: find a better place */ +Inkscape::XML::Document *clipboard_document = NULL; GSList *clipboard = NULL; GSList *defs_clipboard = NULL; SPCSSAttr *style_clipboard = NULL; NR::Maybe size_clipboard; -static void sp_copy_stuff_used_by_item(GSList **defs_clip, SPItem *item, const GSList *items); +static void sp_copy_stuff_used_by_item(GSList **defs_clip, SPItem *item, const GSList *items, Inkscape::XML::Document* xml_doc); /** * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t', * then prepends the copy to 'clip'. */ -void sp_selection_copy_one (Inkscape::XML::Node *repr, NR::Matrix full_t, GSList **clip) +void sp_selection_copy_one (Inkscape::XML::Node *repr, NR::Matrix full_t, GSList **clip, Inkscape::XML::Document* xml_doc) { - Inkscape::XML::Node *copy = repr->duplicate(); + Inkscape::XML::Node *copy = repr->duplicate(xml_doc); // copy complete inherited style SPCSSAttr *css = sp_repr_css_attr_inherited(repr, "style"); @@ -108,13 +111,13 @@ void sp_selection_copy_one (Inkscape::XML::Node *repr, NR::Matrix full_t, GSList *clip = g_slist_prepend(*clip, copy); } -void sp_selection_copy_impl (const GSList *items, GSList **clip, GSList **defs_clip, SPCSSAttr **style_clip) +void sp_selection_copy_impl (const GSList *items, GSList **clip, GSList **defs_clip, SPCSSAttr **style_clip, Inkscape::XML::Document* xml_doc) { // Copy stuff referenced by all items to defs_clip: if (defs_clip) { for (GSList *i = (GSList *) items; i != NULL; i = i->next) { - sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (i->data), items); + sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (i->data), items, xml_doc); } *defs_clip = g_slist_reverse(*defs_clip); } @@ -132,7 +135,7 @@ void sp_selection_copy_impl (const GSList *items, GSList **clip, GSList **defs_c // Copy item reprs: for (GSList *i = (GSList *) sorted_items; i != NULL; i = i->next) { - sp_selection_copy_one (SP_OBJECT_REPR (i->data), sp_item_i2doc_affine(SP_ITEM (i->data)), clip); + sp_selection_copy_one (SP_OBJECT_REPR (i->data), sp_item_i2doc_affine(SP_ITEM (i->data)), clip, xml_doc); } *clip = g_slist_reverse(*clip); @@ -156,22 +159,24 @@ paste_defs (GSList **defs_clip, SPDocument *doc) Inkscape::XML::Node *repr = (Inkscape::XML::Node *) gl->data; gchar const *id = repr->attribute("id"); if (!id || !doc->getObjectById(id)) { - Inkscape::XML::Node *copy = repr->duplicate(); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + Inkscape::XML::Node *copy = repr->duplicate(xml_doc); SP_OBJECT_REPR(defs)->addChild(copy, NULL); Inkscape::GC::release(copy); } } } -GSList *sp_selection_paste_impl (SPDocument *document, SPObject *parent, GSList **clip, GSList **defs_clip) +GSList *sp_selection_paste_impl (SPDocument *doc, SPObject *parent, GSList **clip, GSList **defs_clip) { - paste_defs (defs_clip, document); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + paste_defs (defs_clip, doc); GSList *copied = NULL; // add objects to document for (GSList *l = *clip; l != NULL; l = l->next) { Inkscape::XML::Node *repr = (Inkscape::XML::Node *) l->data; - Inkscape::XML::Node *copy = repr->duplicate(); + Inkscape::XML::Node *copy = repr->duplicate(xml_doc); // premultiply the item transform by the accumulated parent transform in the paste layer NR::Matrix local = sp_item_i2doc_affine(SP_ITEM(parent)); @@ -253,6 +258,7 @@ void sp_selection_duplicate() if (desktop == NULL) return; + Inkscape::XML::Document* xml_doc = sp_document_repr_doc(desktop->doc()); Inkscape::Selection *selection = sp_desktop_selection(desktop); // check if something is selected @@ -272,7 +278,7 @@ void sp_selection_duplicate() while (reprs) { Inkscape::XML::Node *parent = ((Inkscape::XML::Node *) reprs->data)->parent(); - Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) reprs->data)->duplicate(); + Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) reprs->data)->duplicate(xml_doc); parent->appendChild(copy); @@ -424,8 +430,8 @@ void sp_selection_group() if (desktop == NULL) return; - SPDocument *document = sp_desktop_document (desktop); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); + SPDocument *doc = sp_desktop_document (desktop); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -453,7 +459,7 @@ void sp_selection_group() Inkscape::XML::Node *current = (Inkscape::XML::Node *) p->data; if (current->parent() == topmost_parent) { - Inkscape::XML::Node *spnew = current->duplicate(); + Inkscape::XML::Node *spnew = current->duplicate(xml_doc); sp_repr_unparent(current); group->appendChild(spnew); Inkscape::GC::release(spnew); @@ -467,7 +473,7 @@ void sp_selection_group() NR::Matrix item_t (NR::identity()); if (t_str) sp_svg_transform_read(t_str, &item_t); - item_t *= sp_item_i2doc_affine(SP_ITEM(document->getObjectByRepr(current->parent()))); + item_t *= sp_item_i2doc_affine(SP_ITEM(doc->getObjectByRepr(current->parent()))); //FIXME: when moving both clone and original from a transformed group (either by //grouping into another parent, or by cut/paste) the transform from the original's //parent becomes embedded into original itself, and this affects its clones. Fix @@ -475,17 +481,17 @@ void sp_selection_group() //then, if this is clone, looking up its original in that array and pre-multiplying //it by the inverse of that original's transform diff. - sp_selection_copy_one (current, item_t, &temp_clip); + sp_selection_copy_one (current, item_t, &temp_clip, xml_doc); sp_repr_unparent(current); // paste into topmost_parent (temporarily) - GSList *copied = sp_selection_paste_impl (document, document->getObjectByRepr(topmost_parent), &temp_clip, NULL); + GSList *copied = sp_selection_paste_impl (doc, doc->getObjectByRepr(topmost_parent), &temp_clip, NULL); if (temp_clip) g_slist_free (temp_clip); if (copied) { // if success, // take pasted object (now in topmost_parent) Inkscape::XML::Node *in_topmost = (Inkscape::XML::Node *) copied->data; // make a copy - Inkscape::XML::Node *spnew = in_topmost->duplicate(); + Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc); // remove pasted sp_repr_unparent(in_topmost); // put its copy into group @@ -576,7 +582,7 @@ sp_item_list_common_parent_group(const GSList *items) return NULL; } SPObject *parent = SP_OBJECT_PARENT(items->data); - /* Strictly speaking this CAN happen, if user selects from XML editor */ + /* Strictly speaking this CAN happen, if user selects from Inkscape::XML editor */ if (!SP_IS_GROUP(parent)) { return NULL; } @@ -844,78 +850,78 @@ void sp_selection_cut() sp_selection_delete(); } -void sp_copy_gradient (GSList **defs_clip, SPGradient *gradient) +void sp_copy_gradient (GSList **defs_clip, SPGradient *gradient, Inkscape::XML::Document* xml_doc) { SPGradient *ref = gradient; while (ref) { // climb up the refs, copying each one in the chain - Inkscape::XML::Node *grad_repr = SP_OBJECT_REPR(ref)->duplicate(); + Inkscape::XML::Node *grad_repr = SP_OBJECT_REPR(ref)->duplicate(xml_doc); *defs_clip = g_slist_prepend (*defs_clip, grad_repr); ref = ref->ref->getObject(); } } -void sp_copy_pattern (GSList **defs_clip, SPPattern *pattern) +void sp_copy_pattern (GSList **defs_clip, SPPattern *pattern, Inkscape::XML::Document* xml_doc) { SPPattern *ref = pattern; while (ref) { // climb up the refs, copying each one in the chain - Inkscape::XML::Node *pattern_repr = SP_OBJECT_REPR(ref)->duplicate(); + Inkscape::XML::Node *pattern_repr = SP_OBJECT_REPR(ref)->duplicate(xml_doc); *defs_clip = g_slist_prepend (*defs_clip, pattern_repr); // items in the pattern may also use gradients and other patterns, so we need to recurse here as well for (SPObject *child = sp_object_first_child(SP_OBJECT(ref)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) { if (!SP_IS_ITEM (child)) continue; - sp_copy_stuff_used_by_item (defs_clip, (SPItem *) child, NULL); + sp_copy_stuff_used_by_item (defs_clip, (SPItem *) child, NULL, xml_doc); } ref = ref->ref->getObject(); } } -void sp_copy_single (GSList **defs_clip, SPObject *thing) +void sp_copy_single (GSList **defs_clip, SPObject *thing, Inkscape::XML::Document* xml_doc) { - Inkscape::XML::Node *duplicate_repr = SP_OBJECT_REPR(thing)->duplicate(); + Inkscape::XML::Node *duplicate_repr = SP_OBJECT_REPR(thing)->duplicate(xml_doc); *defs_clip = g_slist_prepend (*defs_clip, duplicate_repr); } -void sp_copy_textpath_path (GSList **defs_clip, SPTextPath *tp, const GSList *items) +void sp_copy_textpath_path (GSList **defs_clip, SPTextPath *tp, const GSList *items, Inkscape::XML::Document* xml_doc) { SPItem *path = sp_textpath_get_path_item (tp); if (!path) return; if (items && g_slist_find ((GSList *) items, path)) // do not copy it to defs if it is already in the list of items copied return; - Inkscape::XML::Node *repr = SP_OBJECT_REPR(path)->duplicate(); + Inkscape::XML::Node *repr = SP_OBJECT_REPR(path)->duplicate(xml_doc); *defs_clip = g_slist_prepend (*defs_clip, repr); } /** * Copies things like patterns, markers, gradients, etc. */ -void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, const GSList *items) +void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, const GSList *items, Inkscape::XML::Document* xml_doc) { SPStyle *style = SP_OBJECT_STYLE (item); if (style && (style->fill.type == SP_PAINT_TYPE_PAINTSERVER)) { SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item); if (SP_IS_LINEARGRADIENT (server) || SP_IS_RADIALGRADIENT (server)) - sp_copy_gradient (defs_clip, SP_GRADIENT(server)); + sp_copy_gradient (defs_clip, SP_GRADIENT(server), xml_doc); if (SP_IS_PATTERN (server)) - sp_copy_pattern (defs_clip, SP_PATTERN(server)); + sp_copy_pattern (defs_clip, SP_PATTERN(server), xml_doc); } if (style && (style->stroke.type == SP_PAINT_TYPE_PAINTSERVER)) { SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER(item); if (SP_IS_LINEARGRADIENT (server) || SP_IS_RADIALGRADIENT (server)) - sp_copy_gradient (defs_clip, SP_GRADIENT(server)); + sp_copy_gradient (defs_clip, SP_GRADIENT(server), xml_doc); if (SP_IS_PATTERN (server)) - sp_copy_pattern (defs_clip, SP_PATTERN(server)); + sp_copy_pattern (defs_clip, SP_PATTERN(server), xml_doc); } // For shapes, copy all of the shape's markers into defs_clip @@ -923,40 +929,40 @@ void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, const GSList SPShape *shape = SP_SHAPE (item); for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) { if (shape->marker[i]) { - sp_copy_single (defs_clip, SP_OBJECT (shape->marker[i])); + sp_copy_single (defs_clip, SP_OBJECT (shape->marker[i]), xml_doc); } } } if (SP_IS_TEXT_TEXTPATH (item)) { - sp_copy_textpath_path (defs_clip, SP_TEXTPATH(sp_object_first_child(SP_OBJECT(item))), items); + sp_copy_textpath_path (defs_clip, SP_TEXTPATH(sp_object_first_child(SP_OBJECT(item))), items, xml_doc); } if (item->clip_ref->getObject()) { - sp_copy_single (defs_clip, item->clip_ref->getObject()); + sp_copy_single (defs_clip, item->clip_ref->getObject(), xml_doc); } if (item->mask_ref->getObject()) { SPObject *mask = item->mask_ref->getObject(); - sp_copy_single (defs_clip, mask); + sp_copy_single (defs_clip, mask, xml_doc); // recurse into the mask for its gradients etc. for (SPObject *o = SP_OBJECT(mask)->children; o != NULL; o = o->next) { if (SP_IS_ITEM(o)) - sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (o), items); + sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (o), items, xml_doc); } } if (style->filter.filter) { SPObject *filter = style->filter.filter; if (SP_IS_FILTER(filter)) { - sp_copy_single (defs_clip, filter); + sp_copy_single (defs_clip, filter, xml_doc); } } // recurse for (SPObject *o = SP_OBJECT(item)->children; o != NULL; o = o->next) { if (SP_IS_ITEM(o)) - sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (o), items); + sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (o), items, xml_doc); } } @@ -1007,6 +1013,10 @@ void sp_selection_copy() if (desktop == NULL) return; + if (!clipboard_document) { + clipboard_document = new Inkscape::XML::SimpleDocument(); + } + Inkscape::Selection *selection = sp_desktop_selection(desktop); if (tools_isactive (desktop, TOOLS_DROPPER)) { @@ -1023,7 +1033,7 @@ void sp_selection_copy() const GSList *items = g_slist_copy ((GSList *) selection->itemList()); // 0. Copy text to system clipboard - // FIXME: for non-texts, put serialized XML as text to the clipboard; + // FIXME: for non-texts, put serialized Inkscape::XML as text to the clipboard; //for this sp_repr_write_stream needs to be rewritten with iostream instead of FILE Glib::ustring text; if (tools_isactive (desktop, TOOLS_TEXT)) { @@ -1069,7 +1079,7 @@ void sp_selection_copy() clipboard = g_slist_remove(clipboard, clipboard->data); } - sp_selection_copy_impl (items, &clipboard, &defs_clipboard, &style_clipboard); + sp_selection_copy_impl (items, &clipboard, &defs_clipboard, &style_clipboard, clipboard_document); if (tools_isactive (desktop, TOOLS_TEXT)) { // take style from cursor/text selection, overwriting the style just set by copy_impl SPStyle *const query = sp_style_new(); @@ -1270,7 +1280,7 @@ void sp_selection_to_next_layer () SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); if (next) { GSList *temp_clip = NULL; - sp_selection_copy_impl (items, &temp_clip, NULL, NULL); // we're in the same doc, so no need to copy defs + sp_selection_copy_impl (items, &temp_clip, NULL, NULL, sp_document_repr_doc(dt->doc())); // we're in the same doc, so no need to copy defs sp_selection_delete_impl (items); next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers GSList *copied; @@ -1315,7 +1325,7 @@ void sp_selection_to_prev_layer () SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); if (next) { GSList *temp_clip = NULL; - sp_selection_copy_impl (items, &temp_clip, NULL, NULL); // we're in the same doc, so no need to copy defs + sp_selection_copy_impl (items, &temp_clip, NULL, NULL, sp_document_repr_doc(dt->doc())); // we're in the same doc, so no need to copy defs sp_selection_delete_impl (items); next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers GSList *copied; @@ -2189,8 +2199,8 @@ sp_selection_tile(bool apply) if (desktop == NULL) return; - SPDocument *document = sp_desktop_document(desktop); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document); + SPDocument *doc = sp_desktop_document(desktop); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -2200,14 +2210,14 @@ sp_selection_tile(bool apply) return; } - sp_document_ensure_up_to_date(document); + sp_document_ensure_up_to_date(doc); NR::Maybe r = selection->bounds(); if ( !r || r->isEmpty() ) { return; } // calculate the transform to be applied to objects to move them to 0,0 - NR::Point move_p = NR::Point(0, sp_document_height(document)) - (r->min() + NR::Point (0, r->extent(NR::Y))); + NR::Point move_p = NR::Point(0, sp_document_height(doc)) - (r->min() + NR::Point (0, r->extent(NR::Y))); move_p[NR::Y] = -move_p[NR::Y]; NR::Matrix move = NR::Matrix (NR::translate (move_p)); @@ -2226,7 +2236,7 @@ sp_selection_tile(bool apply) // create a list of duplicates GSList *repr_copies = NULL; for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(); + Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc); repr_copies = g_slist_prepend (repr_copies, dup); } @@ -2246,7 +2256,7 @@ sp_selection_tile(bool apply) int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED); prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED); - const gchar *pat_id = pattern_tile (repr_copies, bounds, document, + const gchar *pat_id = pattern_tile (repr_copies, bounds, doc, NR::Matrix(NR::translate(desktop->dt2doc(NR::Point(r->min()[NR::X], r->max()[NR::Y])))) * parent_transform.inverse(), parent_transform * move); // restore compensation setting @@ -2277,7 +2287,7 @@ sp_selection_tile(bool apply) g_slist_free (items); - sp_document_done (document, SP_VERB_EDIT_TILE, + sp_document_done (doc, SP_VERB_EDIT_TILE, _("Objects to pattern")); } @@ -2288,7 +2298,8 @@ sp_selection_untile() if (desktop == NULL) return; - SPDocument *document = sp_desktop_document(desktop); + SPDocument *doc = sp_desktop_document(desktop); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -2326,14 +2337,14 @@ sp_selection_untile() pat_transform *= item->transform; for (SPObject *child = sp_object_first_child(SP_OBJECT(pattern)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) { - Inkscape::XML::Node *copy = SP_OBJECT_REPR(child)->duplicate(); + Inkscape::XML::Node *copy = SP_OBJECT_REPR(child)->duplicate(xml_doc); SPItem *i = SP_ITEM (desktop->currentLayer()->appendChildRepr(copy)); // FIXME: relink clones to the new canvas objects // use SPObject::setid when mental finishes it to steal ids of // this is needed to make sure the new item has curve (simply requestDisplayUpdate does not work) - sp_document_ensure_up_to_date (document); + sp_document_ensure_up_to_date (doc); NR::Matrix transform( i->transform * pat_transform ); sp_item_write_transform(i, SP_OBJECT_REPR(i), transform); @@ -2622,7 +2633,8 @@ sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer) if (desktop == NULL) return; - SPDocument *document = sp_desktop_document(desktop); + SPDocument *doc = sp_desktop_document(desktop); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -2644,7 +2656,7 @@ sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer) } // /END FIXME - sp_document_ensure_up_to_date(document); + sp_document_ensure_up_to_date(doc); GSList *items = g_slist_copy((GSList *) selection->itemList()); @@ -2662,7 +2674,7 @@ sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer) apply_to_items = g_slist_prepend (apply_to_items, desktop->currentLayer()); for (GSList *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(); + Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc); mask_items = g_slist_prepend (mask_items, dup); if (remove_original) { @@ -2673,7 +2685,7 @@ sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer) } else if (!topmost) { // topmost item is used as a mask, which is applied to other items in a selection GSList *i = items; - Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(); + Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc); mask_items = g_slist_prepend (mask_items, dup); if (remove_original) { @@ -2690,7 +2702,7 @@ sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer) apply_to_items = g_slist_prepend (apply_to_items, i->data); } - Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(); + Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc); mask_items = g_slist_prepend (mask_items, dup); if (remove_original) { @@ -2711,15 +2723,15 @@ sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer) GSList *mask_items_dup = NULL; for (GSList *mask_item = mask_items; NULL != mask_item; mask_item = mask_item->next) { - Inkscape::XML::Node *dup = reinterpret_cast(mask_item->data)->duplicate(); + Inkscape::XML::Node *dup = reinterpret_cast(mask_item->data)->duplicate(xml_doc); mask_items_dup = g_slist_prepend (mask_items_dup, dup); } const gchar *mask_id = NULL; if (apply_clip_path) { - mask_id = sp_clippath_create(mask_items_dup, document, &maskTransform); + mask_id = sp_clippath_create(mask_items_dup, doc, &maskTransform); } else { - mask_id = sp_mask_create(mask_items_dup, document, &maskTransform); + mask_id = sp_mask_create(mask_items_dup, doc, &maskTransform); } g_slist_free (mask_items_dup); @@ -2738,9 +2750,9 @@ sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer) g_slist_free (items_to_delete); if (apply_clip_path) - sp_document_done (document, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path")); + sp_document_done (doc, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path")); else - sp_document_done (document, SP_VERB_OBJECT_SET_MASK, _("Set mask")); + sp_document_done (doc, SP_VERB_OBJECT_SET_MASK, _("Set mask")); } void sp_selection_unset_mask(bool apply_clip_path) { @@ -2748,7 +2760,8 @@ void sp_selection_unset_mask(bool apply_clip_path) { if (desktop == NULL) return; - SPDocument *document = sp_desktop_document(desktop); + SPDocument *doc = sp_desktop_document(desktop); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::Selection *selection = sp_desktop_selection(desktop); // check if something is selected @@ -2758,7 +2771,7 @@ void sp_selection_unset_mask(bool apply_clip_path) { } bool remove_original = prefs_get_int_attribute ("options.maskobject", "remove", 1); - sp_document_ensure_up_to_date(document); + sp_document_ensure_up_to_date(doc); gchar const* attributeName = apply_clip_path ? "clip-path" : "mask"; std::map referenced_objects; @@ -2788,7 +2801,7 @@ void sp_selection_unset_mask(bool apply_clip_path) { SPObject *obj = (*it).first; GSList *items_to_move = NULL; for (SPObject *child = sp_object_first_child(obj) ; child != NULL; child = SP_OBJECT_NEXT(child) ) { - Inkscape::XML::Node *copy = SP_OBJECT_REPR(child)->duplicate(); + Inkscape::XML::Node *copy = SP_OBJECT_REPR(child)->duplicate(xml_doc); items_to_move = g_slist_prepend (items_to_move, copy); } @@ -2821,9 +2834,9 @@ void sp_selection_unset_mask(bool apply_clip_path) { } if (apply_clip_path) - sp_document_done (document, SP_VERB_OBJECT_UNSET_CLIPPATH, _("Release clipping path")); + sp_document_done (doc, SP_VERB_OBJECT_UNSET_CLIPPATH, _("Release clipping path")); else - sp_document_done (document, SP_VERB_OBJECT_UNSET_MASK, _("Release mask")); + sp_document_done (doc, SP_VERB_OBJECT_UNSET_MASK, _("Release mask")); } void fit_canvas_to_selection(SPDesktop *desktop) { diff --git a/src/seltrans.cpp b/src/seltrans.cpp index b127e1657..150a67c30 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -461,7 +461,7 @@ void Inkscape::SelTrans::stamp() // remember parent Inkscape::XML::Node *parent = sp_repr_parent(original_repr); - Inkscape::XML::Node *copy_repr = original_repr->duplicate(); + Inkscape::XML::Node *copy_repr = original_repr->duplicate(parent->document()); // add the new repr to the parent parent->appendChild(copy_repr); diff --git a/src/sp-feblend.cpp b/src/sp-feblend.cpp index c901d6073..7192f3bc6 100644 --- a/src/sp-feblend.cpp +++ b/src/sp-feblend.cpp @@ -150,7 +150,7 @@ sp_feBlend_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-fecolormatrix.cpp b/src/sp-fecolormatrix.cpp index f224e9c3c..3ee184a72 100644 --- a/src/sp-fecolormatrix.cpp +++ b/src/sp-fecolormatrix.cpp @@ -150,7 +150,7 @@ sp_feColorMatrix_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-fecomponenttransfer.cpp b/src/sp-fecomponenttransfer.cpp index 6c228c3fb..941431f6d 100644 --- a/src/sp-fecomponenttransfer.cpp +++ b/src/sp-fecomponenttransfer.cpp @@ -150,7 +150,7 @@ sp_feComponentTransfer_write(SPObject *object, Inkscape::XML::Node *repr, guint // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-fecomposite.cpp b/src/sp-fecomposite.cpp index ed127e723..cb65cc812 100644 --- a/src/sp-fecomposite.cpp +++ b/src/sp-fecomposite.cpp @@ -150,7 +150,7 @@ sp_feComposite_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-feconvolvematrix.cpp b/src/sp-feconvolvematrix.cpp index b02f75fd1..0a255b067 100644 --- a/src/sp-feconvolvematrix.cpp +++ b/src/sp-feconvolvematrix.cpp @@ -150,7 +150,7 @@ sp_feConvolveMatrix_write(SPObject *object, Inkscape::XML::Node *repr, guint fla // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-fediffuselighting.cpp b/src/sp-fediffuselighting.cpp index beb2d6f14..e9720ab16 100644 --- a/src/sp-fediffuselighting.cpp +++ b/src/sp-fediffuselighting.cpp @@ -150,7 +150,7 @@ sp_feDiffuseLighting_write(SPObject *object, Inkscape::XML::Node *repr, guint fl // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-fedisplacementmap.cpp b/src/sp-fedisplacementmap.cpp index d651a3ab5..138ae6e0e 100644 --- a/src/sp-fedisplacementmap.cpp +++ b/src/sp-fedisplacementmap.cpp @@ -150,7 +150,7 @@ sp_feDisplacementMap_write(SPObject *object, Inkscape::XML::Node *repr, guint fl // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-feflood.cpp b/src/sp-feflood.cpp index 843f49da5..5f4050a26 100644 --- a/src/sp-feflood.cpp +++ b/src/sp-feflood.cpp @@ -150,7 +150,7 @@ sp_feFlood_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-feimage.cpp b/src/sp-feimage.cpp index aeacdcef2..e1bbe86cf 100644 --- a/src/sp-feimage.cpp +++ b/src/sp-feimage.cpp @@ -151,7 +151,7 @@ sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-femerge.cpp b/src/sp-femerge.cpp index 64c01432c..4436c7d1e 100644 --- a/src/sp-femerge.cpp +++ b/src/sp-femerge.cpp @@ -150,7 +150,7 @@ sp_feMerge_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-femorphology.cpp b/src/sp-femorphology.cpp index eed1f7602..cdfd0bd38 100644 --- a/src/sp-femorphology.cpp +++ b/src/sp-femorphology.cpp @@ -150,7 +150,7 @@ sp_feMorphology_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-feoffset.cpp b/src/sp-feoffset.cpp index b766f5224..72f352a72 100644 --- a/src/sp-feoffset.cpp +++ b/src/sp-feoffset.cpp @@ -150,7 +150,7 @@ sp_feOffset_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-fespecularlighting.cpp b/src/sp-fespecularlighting.cpp index b1ef987e1..ce251b6fa 100644 --- a/src/sp-fespecularlighting.cpp +++ b/src/sp-fespecularlighting.cpp @@ -150,7 +150,7 @@ sp_feSpecularLighting_write(SPObject *object, Inkscape::XML::Node *repr, guint f // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-fetile.cpp b/src/sp-fetile.cpp index 7d33cd502..bb6893cbc 100644 --- a/src/sp-fetile.cpp +++ b/src/sp-fetile.cpp @@ -150,7 +150,7 @@ sp_feTile_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-feturbulence.cpp b/src/sp-feturbulence.cpp index 033dfd7e4..ab46433d1 100644 --- a/src/sp-feturbulence.cpp +++ b/src/sp-feturbulence.cpp @@ -150,7 +150,7 @@ sp_feTurbulence_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-filter-primitive.cpp b/src/sp-filter-primitive.cpp index c0027e7c3..7be694980 100644 --- a/src/sp-filter-primitive.cpp +++ b/src/sp-filter-primitive.cpp @@ -151,7 +151,8 @@ sp_filter_primitive_write(SPObject *object, Inkscape::XML::Node *repr, guint fla // is this sane? //repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + /// \todo FIXME: Plumb an appropriate XML::Document into this + repr = SP_OBJECT_REPR(object)->duplicate(NULL); } } diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 729e13d4a..ef5d71483 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -269,7 +269,7 @@ sp_filter_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) SPFilter *filter = SP_FILTER(object); if (!repr) { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } if ((flags & SP_OBJECT_WRITE_ALL) || filter->filterUnits_set) { diff --git a/src/sp-gaussian-blur.cpp b/src/sp-gaussian-blur.cpp index 63680a10b..0fcc6d779 100644 --- a/src/sp-gaussian-blur.cpp +++ b/src/sp-gaussian-blur.cpp @@ -157,7 +157,7 @@ sp_gaussianBlur_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? // repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index f73bc2600..d4fa9536d 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -364,7 +364,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) child->updateRepr(); - Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(); + Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document()); // Merging transform NR::Matrix ctrans; @@ -394,7 +394,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) items = g_slist_prepend (items, nrepr); } else { - Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(); + Inkscape::XML::Node *nrepr = SP_OBJECT_REPR (child)->duplicate(prepr->document()); objects = g_slist_prepend (objects, nrepr); } } diff --git a/src/sp-metadata.cpp b/src/sp-metadata.cpp index 0f4b1fb1d..275a5be1d 100644 --- a/src/sp-metadata.cpp +++ b/src/sp-metadata.cpp @@ -192,7 +192,7 @@ sp_metadata_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) if (repr) { repr->mergeFrom(SP_OBJECT_REPR (object), "id"); } else { - repr = SP_OBJECT_REPR (object)->duplicate(); + repr = SP_OBJECT_REPR (object)->duplicate(repr->document()); } } diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 75bb35cd5..c2b8aba10 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -652,7 +652,8 @@ static Inkscape::XML::Node *sp_namedview_write(SPObject *object, Inkscape::XML:: if (repr) { repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + /// \todo FIXME: Plumb an appropriate XML::Document into this + repr = SP_OBJECT_REPR(object)->duplicate(NULL); } } diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 5dbc4101e..f969fe842 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1113,7 +1113,7 @@ static Inkscape::XML::Node * sp_object_private_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) { if (!repr && (flags & SP_OBJECT_WRITE_BUILD)) { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); if (!( flags & SP_OBJECT_WRITE_EXT )) { repr->setAttribute("inkscape:collect", NULL); } @@ -1189,6 +1189,10 @@ SPObject::updateRepr(unsigned int flags) { } } +/** Used both to create reprs in the original document, and to create + * reprs in another document (e.g. a temporary document used when + * saving as "Plain SVG" + */ Inkscape::XML::Node * SPObject::updateRepr(Inkscape::XML::Node *repr, unsigned int flags) { if (SP_OBJECT_IS_CLONED(this)) { @@ -1204,9 +1208,10 @@ SPObject::updateRepr(Inkscape::XML::Node *repr, unsigned int flags) { g_warning("Class %s does not implement ::write", G_OBJECT_TYPE_NAME(this)); if (!repr) { if (flags & SP_OBJECT_WRITE_BUILD) { - repr = SP_OBJECT_REPR(this)->duplicate(); + /// \todo FIXME: Plumb an appropriate XML::Document into this + repr = SP_OBJECT_REPR(this)->duplicate(NULL); } - /// \todo fixme: else probably error (Lauris) */ + /// \todo FIXME: else probably error (Lauris) */ } else { repr->mergeFrom(SP_OBJECT_REPR(this), "id"); } diff --git a/src/sp-skeleton.cpp b/src/sp-skeleton.cpp index f45ff1fda..e9f69e266 100644 --- a/src/sp-skeleton.cpp +++ b/src/sp-skeleton.cpp @@ -191,7 +191,7 @@ sp_skeleton_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) // is this sane? repr->mergeFrom(SP_OBJECT_REPR(object), "id"); } else { - repr = SP_OBJECT_REPR(object)->duplicate(); + repr = SP_OBJECT_REPR(object)->duplicate(repr->document()); } } diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index 3339b2377..0b8f97da1 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -576,7 +576,7 @@ sp_textpath_to_text(SPObject *tp) for ( GSList *i = tp_reprs ; i ; i = i->next ) { // make a copy of each textpath child - Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(); + Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(SP_OBJECT_REPR(text)->document()); // remove the old repr from under textpath SP_OBJECT_REPR(tp)->removeChild((Inkscape::XML::Node *) i->data); // put its copy into under textPath diff --git a/src/sp-use.cpp b/src/sp-use.cpp index 5b2ed9e23..8aa8d3090 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -665,11 +665,11 @@ sp_use_unlink(SPUse *use) if (SP_IS_SYMBOL(orig)) { // make a group, copy children copy = xml_doc->createElement("svg:g"); for (Inkscape::XML::Node *child = SP_OBJECT_REPR(orig)->firstChild() ; child != NULL; child = child->next()) { - Inkscape::XML::Node *newchild = child->duplicate(); + Inkscape::XML::Node *newchild = child->duplicate(copy->document()); copy->appendChild(newchild); } } else { // just copy - copy = SP_OBJECT_REPR(orig)->duplicate(); + copy = SP_OBJECT_REPR(orig)->duplicate(copy->document()); } // Add the duplicate repr just after the existing one. diff --git a/src/splivarot.cpp b/src/splivarot.cpp index f2a115f43..3035cb1a7 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -823,7 +823,7 @@ sp_selected_path_outline() tr = marker_item->transform * marker->c2p * tr * transform; if (SP_OBJECT_REPR(marker_item)) { - Inkscape::XML::Node *m_repr = SP_OBJECT_REPR(marker_item)->duplicate(); + Inkscape::XML::Node *m_repr = SP_OBJECT_REPR(marker_item)->duplicate(xml_doc); g_repr->appendChild(m_repr); SPItem *marker_item = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(m_repr); sp_item_write_transform(marker_item, m_repr, tr); diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 79d5e3a2d..485325859 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -165,8 +165,8 @@ text_put_on_path() SP_OBJECT_REPR(text)->addChild(textpath, NULL); for ( GSList *i = text_reprs ; i ; i = i->next ) { - // make a copy of each text child - Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(); + // Make a copy of each text child + Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(xml_doc); // We cannot have multiline in textpath, so remove line attrs from tspans if (!strcmp(copy->name(), "svg:tspan")) { copy->setAttribute("sodipodi:role", NULL); @@ -346,7 +346,7 @@ text_flow_into_shape() } else { // reflow an already flowed text, preserving paras for (SPObject *o = SP_OBJECT(text)->children; o != NULL; o = o->next) { if (SP_IS_FLOWPARA(o)) { - Inkscape::XML::Node *para_repr = SP_OBJECT_REPR(o)->duplicate(); + Inkscape::XML::Node *para_repr = SP_OBJECT_REPR(o)->duplicate(xml_doc); root_repr->appendChild(para_repr); object = doc->getObjectByRepr(para_repr); g_return_if_fail(SP_IS_FLOWPARA(object)); diff --git a/src/ui/context-menu.cpp b/src/ui/context-menu.cpp index b701adc2b..71e174fb6 100644 --- a/src/ui/context-menu.cpp +++ b/src/ui/context-menu.cpp @@ -167,7 +167,7 @@ sp_item_create_link(GtkMenuItem *menuitem, SPItem *item) g_return_if_fail(SP_IS_ANCHOR(object)); const char *id = SP_OBJECT_REPR(item)->attribute("id"); - Inkscape::XML::Node *child = SP_OBJECT_REPR(item)->duplicate(); + Inkscape::XML::Node *child = SP_OBJECT_REPR(item)->duplicate(xml_doc); SP_OBJECT(item)->deleteObject(false); repr->addChild(child, NULL); child->setAttribute("id", id); diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index 68d69f3f9..88a04bd7a 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -305,13 +305,14 @@ sp_gradient_selector_add_vector_clicked (GtkWidget *w, SPGradientSelector *sel) SPDocument *doc; SPGradient *gr; Inkscape::XML::Node *repr; + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); doc = sp_gradient_vector_selector_get_document (SP_GRADIENT_VECTOR_SELECTOR (sel->vectors)); if (!doc) return; gr = sp_gradient_vector_selector_get_gradient (SP_GRADIENT_VECTOR_SELECTOR (sel->vectors)); if (gr) { - repr = SP_OBJECT_REPR (gr)->duplicate(); + repr = SP_OBJECT_REPR (gr)->duplicate(xml_doc); } else { Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::XML::Node *stop; diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 5a0b5c35e..f1c4e3500 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -488,7 +488,7 @@ verify_grad(SPGradient *gradient) } if (i < 2) { sp_repr_set_css_double(SP_OBJECT_REPR(stop), "offset", 0.0); - Inkscape::XML::Node *child = SP_OBJECT_REPR(stop)->duplicate(); + Inkscape::XML::Node *child = SP_OBJECT_REPR(stop)->duplicate(SP_OBJECT_REPR(gradient)->document()); sp_repr_set_css_double(child, "offset", 1.0); SP_OBJECT_REPR(gradient)->addChild(child, SP_OBJECT_REPR (stop)); } @@ -701,11 +701,11 @@ sp_grd_ed_add_stop (GtkWidget *widget, GtkWidget *vb) } if (next != NULL) { - new_stop_repr = SP_OBJECT_REPR(stop)->duplicate(); + new_stop_repr = SP_OBJECT_REPR(stop)->duplicate(SP_OBJECT_REPR(gradient)->document()); SP_OBJECT_REPR(gradient)->addChild(new_stop_repr, SP_OBJECT_REPR(stop)); } else { next = stop; - new_stop_repr = SP_OBJECT_REPR(sp_prev_stop(stop, gradient))->duplicate(); + new_stop_repr = SP_OBJECT_REPR(sp_prev_stop(stop, gradient))->duplicate(SP_OBJECT_REPR(gradient)->document()); SP_OBJECT_REPR(gradient)->addChild(new_stop_repr, SP_OBJECT_REPR(sp_prev_stop(stop, gradient))); } diff --git a/src/xml/comment-node.h b/src/xml/comment-node.h index c439d0d54..b804a00d9 100644 --- a/src/xml/comment-node.h +++ b/src/xml/comment-node.h @@ -32,7 +32,7 @@ struct CommentNode : public SimpleNode { Inkscape::XML::NodeType type() const { return Inkscape::XML::COMMENT_NODE; } protected: - SimpleNode *_duplicate() const { return new CommentNode(*this); } + SimpleNode *_duplicate(Document* doc) const { return new CommentNode(*this); } }; } diff --git a/src/xml/element-node.h b/src/xml/element-node.h index b9b7a4034..4bac55f83 100644 --- a/src/xml/element-node.h +++ b/src/xml/element-node.h @@ -29,7 +29,7 @@ public: Inkscape::XML::NodeType type() const { return Inkscape::XML::ELEMENT_NODE; } protected: - SimpleNode *_duplicate() const { return new ElementNode(*this); } + SimpleNode *_duplicate(Document* doc) const { return new ElementNode(*this); } }; } diff --git a/src/xml/node.h b/src/xml/node.h index 7e27f1ff6..0b22b169e 100644 --- a/src/xml/node.h +++ b/src/xml/node.h @@ -51,7 +51,7 @@ public: virtual Document *document()=0; virtual Document const *document() const=0; - virtual Node *duplicate() const=0; + virtual Node *duplicate(Document *doc) const=0; virtual Node *root()=0; virtual Node const *root() const=0; diff --git a/src/xml/repr-css.cpp b/src/xml/repr-css.cpp index 8540ff9f0..e2954ddf3 100644 --- a/src/xml/repr-css.cpp +++ b/src/xml/repr-css.cpp @@ -17,6 +17,7 @@ using Inkscape::XML::AttributeRecord; using Inkscape::XML::SimpleNode; using Inkscape::XML::Node; using Inkscape::XML::NodeType; +using Inkscape::XML::Document; struct SPCSSAttrImpl : public SimpleNode, public SPCSSAttr { public: @@ -25,7 +26,7 @@ public: NodeType type() const { return Inkscape::XML::ELEMENT_NODE; } protected: - SimpleNode *_duplicate() const { return new SPCSSAttrImpl(*this); } + SimpleNode *_duplicate(Document* doc) const { return new SPCSSAttrImpl(*this); } }; static void sp_repr_css_add_components(SPCSSAttr *css, Node *repr, gchar const *attr); diff --git a/src/xml/simple-document.h b/src/xml/simple-document.h index 11d0ef4a2..ab563139d 100644 --- a/src/xml/simple-document.h +++ b/src/xml/simple-document.h @@ -73,7 +73,10 @@ protected: _initBindings(); } - SimpleNode *_duplicate() const { return new SimpleDocument(*this); } + SimpleNode *_duplicate(Document* doc) const + { + return new SimpleDocument(*this); + } private: void _initBindings(); diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp index f439243cd..c8b0828c4 100644 --- a/src/xml/simple-node.cpp +++ b/src/xml/simple-node.cpp @@ -174,7 +174,6 @@ SimpleNode::SimpleNode(SimpleNode const &node) _child_count(node._child_count), _cached_positions_valid(node._cached_positions_valid) { - _document = NULL; _document = NULL; _parent = _next = NULL; _first_child = _last_child = NULL; @@ -182,7 +181,7 @@ SimpleNode::SimpleNode(SimpleNode const &node) for ( Node *child = node._first_child ; child != NULL ; child = child->next() ) { - Node *child_copy=child->duplicate(); + Node *child_copy=child->duplicate(NULL); // FIXME child_copy->_setParent(this); if (_last_child) { @@ -591,12 +590,12 @@ void SimpleNode::mergeFrom(Node const *src, gchar const *key) { if (rch) { rch->mergeFrom(child, key); } else { - rch = child->duplicate(); + rch = child->duplicate(_document); appendChild(rch); rch->release(); } } else { - Node *rch=child->duplicate(); + Node *rch=child->duplicate(_document); appendChild(rch); rch->release(); } diff --git a/src/xml/simple-node.h b/src/xml/simple-node.h index 3a25bc86c..c843dadc5 100644 --- a/src/xml/simple-node.h +++ b/src/xml/simple-node.h @@ -39,7 +39,7 @@ public: return const_cast(this)->document(); } - Node *duplicate() const { return _duplicate(); } + Node *duplicate(Document* doc) const { return _duplicate(doc); } Node *root(); Node const *root() const { @@ -107,7 +107,7 @@ protected: SimpleNode(int code); SimpleNode(SimpleNode const &repr); - virtual SimpleNode *_duplicate() const=0; + virtual SimpleNode *_duplicate(Document *doc) const=0; public: // ideally these should be protected somehow... void _setParent(Node *parent) { _parent = parent; } diff --git a/src/xml/text-node.h b/src/xml/text-node.h index bd6095f3b..36f638ad9 100644 --- a/src/xml/text-node.h +++ b/src/xml/text-node.h @@ -32,7 +32,7 @@ struct TextNode : public SimpleNode { Inkscape::XML::NodeType type() const { return Inkscape::XML::TEXT_NODE; } protected: - SimpleNode *_duplicate() const { return new TextNode(*this); } + SimpleNode *_duplicate(Document* doc) const { return new TextNode(*this); } }; }