diff options
| author | Stefano Facchini <stefano.facchini@gmail.com> | 2017-09-23 08:23:47 +0000 |
|---|---|---|
| committer | Stefano Facchini <stefano.facchini@gmail.com> | 2017-09-24 11:26:11 +0000 |
| commit | f81751abb770d0367d6c515cdcb56a7954714eab (patch) | |
| tree | 22c103a78ba9e19a7e1a437d5b2e4852d1d8ab39 /src | |
| parent | Remove unused parameter in SPItem::doWriteTransform (diff) | |
| download | inkscape-f81751abb770d0367d6c515cdcb56a7954714eab.tar.gz inkscape-f81751abb770d0367d6c515cdcb56a7954714eab.zip | |
Transform duplicate object only when clipping or masking
Diffstat (limited to 'src')
| -rw-r--r-- | src/selection-chemistry.cpp | 37 | ||||
| -rw-r--r-- | src/sp-clippath.cpp | 9 | ||||
| -rw-r--r-- | src/sp-clippath.h | 2 | ||||
| -rw-r--r-- | src/sp-mask.cpp | 9 | ||||
| -rw-r--r-- | src/sp-mask.h | 2 |
5 files changed, 27 insertions, 32 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index b13af6bac..7dfe74752 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3871,11 +3871,10 @@ void ObjectSet::setClipGroup() clone->setAttribute("inkscape:transform-center-x", inner->attribute("inkscape:transform-center-x"), false); clone->setAttribute("inkscape:transform-center-y", inner->attribute("inkscape:transform-center-y"), false); - const Geom::Affine maskTransform(Geom::Affine::identity()); std::vector<Inkscape::XML::Node*> templist; templist.push_back(clone); // add the new clone to the top of the original's parent - gchar const *mask_id = SPClipPath::create(templist, doc, &maskTransform); + gchar const *mask_id = SPClipPath::create(templist, doc); outer->setAttribute("clip-path", g_strdup_printf("url(#%s)", mask_id)); @@ -3933,7 +3932,7 @@ void ObjectSet::setClipGroup() clear(); // create a list of duplicates - std::vector<Inkscape::XML::Node*> mask_items; + std::vector<std::pair<Inkscape::XML::Node*, Geom::Affine>> mask_items; std::vector<SPItem*> apply_to_items; std::vector<SPItem*> items_to_delete; std::vector<SPItem*> items_to_select; @@ -3953,12 +3952,8 @@ void ObjectSet::setClipGroup() || (topmost && !apply_to_layer && *i == items_.back()) || apply_to_layer){ - Geom::Affine oldtr=(*i)->transform; - oldtr *= SP_ITEM((*i)->parent)->i2doc_affine().inverse(); - (*i)->doWriteTransform((*i)->i2doc_affine()); Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); - (*i)->doWriteTransform(oldtr); - mask_items.push_back(dup); + mask_items.push_back(std::make_pair(dup, (*i)->i2doc_affine())); if (remove_original) { items_to_delete.push_back(*i); @@ -4003,11 +3998,15 @@ void ObjectSet::setClipGroup() gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; for (std::vector<SPItem*>::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); ++i) { SPItem *item = reinterpret_cast<SPItem *>(*i); - // inverted object transform should be applied to a mask object, - // as mask is calculated in user space (after applying transform) + std::vector<Inkscape::XML::Node*> mask_items_dup; - for(std::vector<Inkscape::XML::Node*>::const_iterator it=mask_items.begin();it!=mask_items.end();++it) - mask_items_dup.push_back((*it)->duplicate(xml_doc)); + std::map<Inkscape::XML::Node*, Geom::Affine> dup_transf; + for (auto it = mask_items.begin(); it != mask_items.end(); ++it) { + Inkscape::XML::Node *dup = ((*it).first)->duplicate(xml_doc); + mask_items_dup.push_back(dup); + dup_transf[dup] = (*it).second; + } + Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr(); // Node to apply mask to Inkscape::XML::Node *apply_mask_to = current; @@ -4033,13 +4032,19 @@ void ObjectSet::setClipGroup() Inkscape::GC::release(group); } - Geom::Affine maskTransform(item->i2doc_affine().inverse()); - gchar const *mask_id = NULL; if (apply_clip_path) { - mask_id = SPClipPath::create(mask_items_dup, doc, &maskTransform); + mask_id = SPClipPath::create(mask_items_dup, doc); } else { - mask_id = sp_mask_create(mask_items_dup, doc, &maskTransform); + mask_id = sp_mask_create(mask_items_dup, doc); + } + + // inverted object transform should be applied to a mask object, + // as mask is calculated in user space (after applying transform) + for (auto it = mask_items_dup.begin(); it != mask_items_dup.end(); ++it) { + SPItem *clip_item = SP_ITEM(doc->getObjectByRepr(*it)); + clip_item->doWriteTransform(dup_transf[*it]); + clip_item->doWriteTransform(clip_item->transform * item->i2doc_affine().inverse()); } apply_mask_to->setAttribute(attributeName, Glib::ustring("url(#") + mask_id + ')'); diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp index 52c043aee..a56dfd85a 100644 --- a/src/sp-clippath.cpp +++ b/src/sp-clippath.cpp @@ -292,7 +292,7 @@ sp_clippath_view_list_remove(SPClipPathView *list, SPClipPathView *view) } // Create a mask element (using passed elements), add it to <defs> -const gchar *SPClipPath::create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform) +const gchar *SPClipPath::create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document) { Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -306,12 +306,7 @@ const gchar *SPClipPath::create (std::vector<Inkscape::XML::Node*> &reprs, SPDoc for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); ++it) { Inkscape::XML::Node *node = (*it); - SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node)); - - if (NULL != applyTransform) { - Geom::Affine transform (item->transform * (*applyTransform)); - item->doWriteTransform(transform); - } + clip_path_object->appendChildRepr(node); } Inkscape::GC::release(repr); diff --git a/src/sp-clippath.h b/src/sp-clippath.h index 129f3b7f3..87b5be92c 100644 --- a/src/sp-clippath.h +++ b/src/sp-clippath.h @@ -43,7 +43,7 @@ public: unsigned int clipPathUnits : 1; SPClipPathView *display; - static char const *create(std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform); + static char const *create(std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document); //static GType sp_clippath_get_type(void); Inkscape::DrawingItem *show(Inkscape::Drawing &drawing, unsigned int key); diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index d2d4801f9..0597d29f7 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -191,7 +191,7 @@ Inkscape::XML::Node* SPMask::write(Inkscape::XML::Document* xml_doc, Inkscape::X // Create a mask element (using passed elements), add it to <defs> const gchar * -sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform) +sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document) { Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); @@ -205,12 +205,7 @@ sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); ++it) { Inkscape::XML::Node *node = (*it); - SPItem *item = SP_ITEM(mask_object->appendChildRepr(node)); - - if (NULL != applyTransform) { - Geom::Affine transform (item->transform * (*applyTransform)); - item->doWriteTransform(transform); - } + mask_object->appendChildRepr(node); } if (repr != defsrepr->lastChild()) diff --git a/src/sp-mask.h b/src/sp-mask.h index 19786b1fd..02d37b82b 100644 --- a/src/sp-mask.h +++ b/src/sp-mask.h @@ -108,6 +108,6 @@ protected: } }; -const char *sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, Geom::Affine const* applyTransform); +const char *sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document); #endif // SEEN_SP_MASK_H |
