summaryrefslogtreecommitdiffstats
path: root/src/document.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/document.cpp')
-rw-r--r--src/document.cpp29
1 files changed, 26 insertions, 3 deletions
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);
+ }
}
+
}
/*