From bf7c3e8d98b557cb64447804399797d93e1cedc0 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 19 Sep 2012 10:52:19 +0900 Subject: Fix for 643150 : Auto-palette swatches duplicated on copy and paste (bzr r11677) --- src/document.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 9efd9d923..e28356969 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1453,10 +1453,33 @@ void SPDocument::importDefs(SPDocument *source) prevent_id_clashes(source, this); for (Inkscape::XML::Node *def = defs->firstChild() ; def ; def = def->next()) { - Inkscape::XML::Node * dup = def->duplicate(this->getReprDoc()); - target_defs->appendChild(dup); - Inkscape::GC::release(dup); + + // Prevent duplicates of solid swatches by checking if equivalent swatch already exists + gboolean duplicate = false; + SPObject *src = source->getObjectByRepr(def); + if (src && SP_IS_GRADIENT(src)) { + SPGradient *gr = SP_GRADIENT(src); + if (gr->isSolid() || gr->getVector()->isSolid()) { + for (SPObject *trg = this->getDefs()->firstChild() ; trg ; trg = trg->getNext()) { + if (trg && SP_IS_GRADIENT(trg) && src != trg) { + if (gr->isEquivalent(SP_GRADIENT(trg))) { + // Change object references to the existing equivalent gradient + change_def_references(src, trg); + duplicate = true; + break; + } + } + } + } + } + + if (!duplicate) { + Inkscape::XML::Node * dup = def->duplicate(this->getReprDoc()); + target_defs->appendChild(dup); + Inkscape::GC::release(dup); + } } + } /* -- cgit v1.2.3