From a113f4663e5f155386a5b3b8f1b1f19f4d61145b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Tue, 5 Sep 2017 01:47:21 +0200 Subject: Allow nested LPE over groups also with shapes --- src/sp-item-group.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/sp-item-group.cpp') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 88b2bb1f9..c81375f05 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -32,6 +32,7 @@ #include "attributes.h" #include "sp-item-transform.h" #include "sp-root.h" +#include "sp-rect.h" #include "sp-offset.h" #include "sp-clippath.h" #include "sp-mask.h" @@ -953,11 +954,28 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) SPShape *subShape = dynamic_cast(subitem); if (subShape) { SPCurve * c = NULL; - - SPPath *subPath = dynamic_cast(subShape); - if (subPath) { - c = subPath->get_original_curve(); - } else { + // If item is a SPRect, convert it to path first: + if ( dynamic_cast(subShape) ) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (desktop) { + Inkscape::Selection *sel = desktop->getSelection(); + if ( sel && !sel->isEmpty() ) { + sel->clear(); + sel->add(SP_ITEM(subShape)); + sel->toCurves(); + subitem = sel->singleItem(); + subShape = dynamic_cast(subitem); + if (!subShape) { + continue; + } + sel->clear(); + sel->add(SP_ITEM(topgroup)); + } + } + } + //SPPath *subPath = dynamic_cast(subShape); + c = subShape->getCurveBeforeLPE(); + if (!c || (subShape->getCurve() != c)) { c = subShape->getCurve(); } bool success = false; @@ -968,7 +986,9 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) c->transform(i2anc_affine(subitem, topgroup).inverse()); Inkscape::XML::Node *repr = subitem->getRepr(); if (c && success) { + subShape->setCurveInsync( subShape->getCurveBeforeLPE(), TRUE); subShape->setCurve(c, TRUE); + subShape->setCurveInsync( c, TRUE); if (write) { gchar *str = sp_svg_write_path(c->get_pathvector()); repr->setAttribute("d", str); -- cgit v1.2.3 From 0085d04d2132cfeb1316535ead6f1943a7158cc2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 6 Sep 2017 22:45:42 +0200 Subject: A bit refactor on SPGroup --- src/sp-item-group.cpp | 92 +++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'src/sp-item-group.cpp') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index c81375f05..875d81ded 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -56,11 +56,11 @@ using Inkscape::DocumentUndo; -static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write); +static void sp_group_perform_patheffect(SPGroup *group, SPGroup *top_group, bool write); SPGroup::SPGroup() : SPLPEItem(), _expanded(false), - _insertBottom(false), + _insert_bottom(false), _layer_mode(SPGroup::GROUP) { } @@ -713,8 +713,8 @@ void SPGroup::setExpanded(bool isexpanded) { } void SPGroup::setInsertBottom(bool insertbottom) { - if ( _insertBottom != insertbottom) { - _insertBottom = insertbottom; + if ( _insert_bottom != insertbottom) { + _insert_bottom = insertbottom; } } @@ -788,19 +788,19 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo item->doWriteTransform(item->getRepr(), tAff, NULL, true); } else { // used for other import - SPItem *subItem = NULL; + SPItem *sub_item = NULL; if (item->clip_ref->getObject()) { - subItem = dynamic_cast(item->clip_ref->getObject()->firstChild()); + sub_item = dynamic_cast(item->clip_ref->getObject()->firstChild()); } - if (subItem != NULL) { - subItem->doWriteTransform(subItem->getRepr(), subItem->transform*sc, NULL, true); + if (sub_item != NULL) { + sub_item->doWriteTransform(sub_item->getRepr(), sub_item->transform*sc, NULL, true); } - subItem = NULL; + sub_item = NULL; if (item->mask_ref->getObject()) { - subItem = dynamic_cast(item->mask_ref->getObject()->firstChild()); + sub_item = dynamic_cast(item->mask_ref->getObject()->firstChild()); } - if (subItem != NULL) { - subItem->doWriteTransform(subItem->getRepr(), subItem->transform*sc, NULL, true); + if (sub_item != NULL) { + sub_item->doWriteTransform(sub_item->getRepr(), sub_item->transform*sc, NULL, true); } item->doWriteTransform(item->getRepr(), sc.inverse()*item->transform*sc, NULL, true); group->scaleChildItemsRec(sc, p, false); @@ -813,10 +813,10 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo Geom::Affine final = s.inverse() * sc * s; gchar const *conn_type = NULL; - SPText *textItem = dynamic_cast(item); - bool isTextTextpath = textItem && textItem->firstChild() && dynamic_cast(textItem->firstChild()); - if (isTextTextpath) { - textItem->optimizeTextpathText(); + SPText *text_item = dynamic_cast(item); + bool is_text_path = text_item && text_item->firstChild() && dynamic_cast(text_item->firstChild()); + if (is_text_path) { + text_item->optimizeTextpathText(); } else { SPFlowtext *flowText = dynamic_cast(item); if (flowText) { @@ -839,7 +839,7 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo Persp3D *persp = dynamic_cast(item); if (persp) { persp3d_apply_affine_transformation(persp, final); - } else if (isTextTextpath && !item->transform.isIdentity()) { + } else if (is_text_path && !item->transform.isIdentity()) { // Save and reset current transform Geom::Affine tmp(item->transform); item->transform = Geom::Affine(); @@ -908,11 +908,11 @@ void SPGroup::update_patheffect(bool write) { std::vector const item_list = sp_item_group_item_list(this); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();++iter) { - SPObject *subitem = *iter; + SPObject *sub_item = *iter; - SPLPEItem *lpeItem = dynamic_cast(subitem); - if (lpeItem) { - lpeItem->update_patheffect(write); + SPLPEItem *lpe_item = dynamic_cast(sub_item); + if (lpe_item) { + lpe_item->update_patheffect(write); } } @@ -940,55 +940,55 @@ void SPGroup::update_patheffect(bool write) { } static void -sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) +sp_group_perform_patheffect(SPGroup *group, SPGroup *top_group, bool write) { std::vector const item_list = sp_item_group_item_list(group); for ( std::vector::const_iterator iter=item_list.begin();iter!=item_list.end();++iter) { - SPObject *subitem = *iter; + SPObject *sub_item = *iter; - SPGroup *subGroup = dynamic_cast(subitem); - if (subGroup) { - sp_group_perform_patheffect(subGroup, topgroup, write); + SPGroup *sub_group = dynamic_cast(sub_item); + if (sub_group) { + sp_group_perform_patheffect(sub_group, top_group, write); } else { - SPShape *subShape = dynamic_cast(subitem); - if (subShape) { + SPShape *sub_shape = dynamic_cast(sub_item); + if (sub_shape) { SPCurve * c = NULL; // If item is a SPRect, convert it to path first: - if ( dynamic_cast(subShape) ) { + if ( dynamic_cast(sub_shape) ) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { Inkscape::Selection *sel = desktop->getSelection(); if ( sel && !sel->isEmpty() ) { sel->clear(); - sel->add(SP_ITEM(subShape)); + sel->add(SP_ITEM(sub_shape)); sel->toCurves(); - subitem = sel->singleItem(); - subShape = dynamic_cast(subitem); - if (!subShape) { + sub_item = sel->singleItem(); + sub_shape = dynamic_cast(sub_item); + if (!sub_shape) { continue; } sel->clear(); - sel->add(SP_ITEM(topgroup)); + sel->add(SP_ITEM(top_group)); } } } - //SPPath *subPath = dynamic_cast(subShape); - c = subShape->getCurveBeforeLPE(); - if (!c || (subShape->getCurve() != c)) { - c = subShape->getCurve(); + //SPPath *sub_path = dynamic_cast(sub_shape); + c = sub_shape->getCurveBeforeLPE(); + if (!c || (sub_shape->getCurve() != c)) { + c = sub_shape->getCurve(); } bool success = false; // only run LPEs when the shape has a curve defined if (c) { - c->transform(i2anc_affine(subitem, topgroup)); - success = topgroup->performPathEffect(c, subShape); - c->transform(i2anc_affine(subitem, topgroup).inverse()); - Inkscape::XML::Node *repr = subitem->getRepr(); + c->transform(i2anc_affine(sub_item, top_group)); + success = top_group->performPathEffect(c, sub_shape); + c->transform(i2anc_affine(sub_item, top_group).inverse()); + Inkscape::XML::Node *repr = sub_item->getRepr(); if (c && success) { - subShape->setCurveInsync( subShape->getCurveBeforeLPE(), TRUE); - subShape->setCurve(c, TRUE); - subShape->setCurveInsync( c, TRUE); + sub_shape->setCurveInsync( sub_shape->getCurveBeforeLPE(), TRUE); + sub_shape->setCurve(c, TRUE); + sub_shape->setCurveInsync( c, TRUE); if (write) { gchar *str = sp_svg_write_path(c->get_pathvector()); repr->setAttribute("d", str); @@ -1004,7 +1004,7 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) Geom::PathVector pv = sp_svg_read_pathv(value); SPCurve *oldcurve = new (std::nothrow) SPCurve(pv); if (oldcurve) { - subShape->setCurve(oldcurve, TRUE); + sub_shape->setCurve(oldcurve, TRUE); oldcurve->unref(); } } -- cgit v1.2.3 From 4754229fb90d296b1fad0b1a537734f9a4da5f34 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 6 Sep 2017 22:46:36 +0200 Subject: A little improvements on groups with paths having LPE --- src/sp-item-group.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/sp-item-group.cpp') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 875d81ded..68c17abc8 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -986,9 +986,12 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *top_group, bool write) c->transform(i2anc_affine(sub_item, top_group).inverse()); Inkscape::XML::Node *repr = sub_item->getRepr(); if (c && success) { - sub_shape->setCurveInsync( sub_shape->getCurveBeforeLPE(), TRUE); - sub_shape->setCurve(c, TRUE); - sub_shape->setCurveInsync( c, TRUE); + SPPath *sub_path = dynamic_cast(sub_item); + if (!sub_path) { + sub_shape->setCurveInsync( sub_shape->getCurveBeforeLPE(), TRUE); + sub_shape->setCurve(c, TRUE); + sub_shape->setCurveInsync( c, TRUE); + } if (write) { gchar *str = sp_svg_write_path(c->get_pathvector()); repr->setAttribute("d", str); -- cgit v1.2.3 From 6a03015b016c177e0657fc6274a571db16e48b64 Mon Sep 17 00:00:00 2001 From: Stefano Facchini Date: Sat, 23 Sep 2017 10:02:16 +0200 Subject: Remove unused parameter in SPItem::doWriteTransform --- src/sp-item-group.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/sp-item-group.cpp') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 68c17abc8..4dbfa8ac3 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -643,7 +643,7 @@ sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_d SPItem *item = static_cast(doc->getObjectByRepr(repr)); if (item) { - item->doWriteTransform(repr, item->transform, NULL, false); + item->doWriteTransform(item->transform, NULL, false); children.insert(children.begin(),item); } else { g_assert_not_reached(); @@ -785,7 +785,7 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo tAff[4] = 0.0; tAff[5] = 0.0; } - item->doWriteTransform(item->getRepr(), tAff, NULL, true); + item->doWriteTransform(tAff, NULL, true); } else { // used for other import SPItem *sub_item = NULL; @@ -793,16 +793,16 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo sub_item = dynamic_cast(item->clip_ref->getObject()->firstChild()); } if (sub_item != NULL) { - sub_item->doWriteTransform(sub_item->getRepr(), sub_item->transform*sc, NULL, true); + sub_item->doWriteTransform(sub_item->transform*sc, NULL, true); } sub_item = NULL; if (item->mask_ref->getObject()) { sub_item = dynamic_cast(item->mask_ref->getObject()->firstChild()); } if (sub_item != NULL) { - sub_item->doWriteTransform(sub_item->getRepr(), sub_item->transform*sc, NULL, true); + sub_item->doWriteTransform(sub_item->transform*sc, NULL, true); } - item->doWriteTransform(item->getRepr(), sc.inverse()*item->transform*sc, NULL, true); + item->doWriteTransform(sc.inverse()*item->transform*sc, NULL, true); group->scaleChildItemsRec(sc, p, false); } } else { @@ -845,18 +845,18 @@ void SPGroup::scaleChildItemsRec(Geom::Scale const &sc, Geom::Point const &p, bo item->transform = Geom::Affine(); // Apply scale item->set_i2d_affine(item->i2dt_affine() * sc); - item->doWriteTransform(item->getRepr(), item->transform, NULL, true); + item->doWriteTransform(item->transform, NULL, true); // Scale translation and restore original transform tmp[4] *= sc[0]; tmp[5] *= sc[1]; - item->doWriteTransform(item->getRepr(), tmp, NULL, true); + item->doWriteTransform(tmp, NULL, true); } else if (dynamic_cast(item)) { // calculate the matrix we need to apply to the clone // to cancel its induced transform from its original Geom::Affine move = final.inverse() * item->transform * final; - item->doWriteTransform(item->getRepr(), move, &move, true); + item->doWriteTransform(move, &move, true); } else { - item->doWriteTransform(item->getRepr(), item->transform*sc, NULL, true); + item->doWriteTransform(item->transform*sc, NULL, true); } if (conn_type != NULL) { -- cgit v1.2.3 From 3e075e587aaa712efb1704478cd1a75131882889 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 2 Oct 2017 23:30:11 +0200 Subject: third batch --- src/sp-item-group.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'src/sp-item-group.cpp') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 4dbfa8ac3..27bee1541 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -226,7 +226,7 @@ void SPGroup::modified(guint flags) { Inkscape::XML::Node* SPGroup::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if (flags & SP_OBJECT_WRITE_BUILD) { - GSList *l = NULL; + std::vector l; if (!repr) { if (dynamic_cast(this)) { @@ -236,22 +236,18 @@ Inkscape::XML::Node* SPGroup::write(Inkscape::XML::Document *xml_doc, Inkscape:: } } - l = NULL; - for (auto& child: children) { if ( !dynamic_cast(&child) && !dynamic_cast(&child) ) { Inkscape::XML::Node *crepr = child.updateRepr(xml_doc, NULL, flags); if (crepr) { - l = g_slist_prepend (l, crepr); + l.push_back(crepr); } } } - - while (l) { - repr->addChild((Inkscape::XML::Node *) l->data, NULL); - Inkscape::GC::release((Inkscape::XML::Node *) l->data); - l = g_slist_remove (l, l->data); + for (auto i=l.rbegin();i!=l.rend();++i) { + repr->addChild(*i, NULL); + Inkscape::GC::release(*i); } } else { for (auto& child: children) { @@ -510,8 +506,8 @@ sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_d group->removeAllPathEffects(false); /* Step 1 - generate lists of children objects */ - GSList *items = NULL; - GSList *objects = NULL; + std::vector items; + std::vector objects; Geom::Affine const g(group->transform); for (auto& child: group->children) { @@ -602,11 +598,11 @@ sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_d } g_free(affinestr); - items = g_slist_prepend (items, nrepr); + items.push_back(nrepr); } else { Inkscape::XML::Node *nrepr = child.getRepr()->duplicate(prepr->document()); - objects = g_slist_prepend (objects, nrepr); + objects.push_back(nrepr); } } @@ -618,21 +614,20 @@ sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_d group->deleteObject(true, false); /* Step 3 - add nonitems */ - if (objects) { + if (!objects.empty()) { Inkscape::XML::Node *last_def = defs->getRepr()->lastChild(); - while (objects) { - Inkscape::XML::Node *repr = (Inkscape::XML::Node *) objects->data; + for (auto i=objects.rbegin();i!=objects.rend();++i) { + Inkscape::XML::Node *repr = *i; if (!sp_repr_is_meta_element(repr)) { defs->getRepr()->addChild(repr, last_def); } Inkscape::GC::release(repr); - objects = g_slist_remove (objects, objects->data); } } /* Step 4 - add items */ - while (items) { - Inkscape::XML::Node *repr = (Inkscape::XML::Node *) items->data; + for (auto i=items.rbegin();i!=items.rend();++i) { + Inkscape::XML::Node *repr = *i; // add item prepr->appendChild(repr); // restore position; since the items list was prepended (i.e. reverse), we now add @@ -650,7 +645,6 @@ sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_d } Inkscape::GC::release(repr); - items = g_slist_remove (items, items->data); } if (do_done) { -- cgit v1.2.3 From ee527cbb228c6fba9c83bba5058d1a68ac647060 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 14 Oct 2017 21:29:10 +0200 Subject: Fixing problems with nested LPE and convert to paths --- src/sp-item-group.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/sp-item-group.cpp') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 27bee1541..3d4d7b253 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -967,11 +967,7 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *top_group, bool write) } } } - //SPPath *sub_path = dynamic_cast(sub_shape); - c = sub_shape->getCurveBeforeLPE(); - if (!c || (sub_shape->getCurve() != c)) { - c = sub_shape->getCurve(); - } + c = sub_shape->getCurve(); bool success = false; // only run LPEs when the shape has a curve defined if (c) { -- cgit v1.2.3