From 95b1c7b549605d7c6ce6623cc4cd121ed7c51a64 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 3 Mar 2018 01:12:41 +0100 Subject: Base LPE refactor --- src/object/sp-shape.cpp | 111 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 26 deletions(-) (limited to 'src/object/sp-shape.cpp') diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp index 9edf03cbf..07416650e 100644 --- a/src/object/sp-shape.cpp +++ b/src/object/sp-shape.cpp @@ -37,7 +37,8 @@ #include "sp-path.h" #include "preferences.h" #include "attributes.h" - +#include "svg/svg.h" +#include "svg/path-string.h" #include "live_effects/lpeobject.h" #include "helper/mathfns.h" // for triangle_area() @@ -416,7 +417,7 @@ void SPShape::modified(unsigned int flags) { Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype) const { Geom::OptRect bbox; - if (!this->_curve) { + if (!this->_curve || this->_curve->get_pathvector().empty()) { return bbox; } @@ -738,6 +739,38 @@ void SPShape::print(SPPrintContext* ctx) { } } +void SPShape::update_patheffect(bool write) +{ + if (SPCurve *c_lpe = this->getCurveForEdit()) { + /* if a path has an lpeitem applied, then reset the curve to the _curve_before_lpe. + * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ + this->setCurveInsync(c_lpe); + this->resetClipPathAndMaskLPE(); + bool success = false; + if (hasPathEffect() && pathEffectsEnabled()) { + success = this->performPathEffect(c_lpe, SP_SHAPE(this)); + if (success) { + this->setCurveInsync(c_lpe); + this->applyToClipPath(this); + this->applyToMask(this); + } + } + + if (write && success) { + Inkscape::XML::Node *repr = this->getRepr(); + if (c_lpe != NULL) { + gchar *str = sp_svg_write_path(c_lpe->get_pathvector()); + repr->setAttribute("d", str); + g_free(str); + } else { + repr->setAttribute("d", NULL); + } + } + c_lpe->unref(); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + } +} + Inkscape::DrawingItem* SPShape::show(Inkscape::Drawing &drawing, unsigned int /*key*/, unsigned int /*flags*/) { // std::cout << "SPShape::show(): " << (getId()?getId():"null") << std::endl; Inkscape::DrawingShape *s = new Inkscape::DrawingShape(drawing); @@ -995,67 +1028,93 @@ void SPShape::setCurve(SPCurve *new_curve, unsigned int owner) this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } + /** * Sets _curve_before_lpe to refer to the curve. */ void -SPShape::setCurveBeforeLPE (SPCurve *new_curve) +SPShape::setCurveBeforeLPE(SPCurve *new_curve, unsigned int owner) { if (_curve_before_lpe) { _curve_before_lpe = _curve_before_lpe->unref(); } if (new_curve) { - _curve_before_lpe = new_curve->ref(); + if (owner) { + _curve_before_lpe = new_curve->ref(); + } else { + _curve_before_lpe = new_curve->copy(); + } } } /** - * Return duplicate of curve (if any exists) or NULL if there is no curve + * Same as sp_shape_set_curve but without updating the display */ -SPCurve * SPShape::getCurve() const +void SPShape::setCurveInsync(SPCurve *new_curve, unsigned int owner) { if (_curve) { - return _curve->copy(); + _curve = _curve->unref(); } - return NULL; + if (new_curve) { + if (owner) { + _curve = new_curve->ref(); + } else { + _curve = new_curve->copy(); + } + } } + /** - * Return duplicate of curve *before* LPE (if any exists) or NULL if there is no curve + * Return curve (if any exists) or NULL if there is no curve +* if owner == 0 return a copy */ -SPCurve * SPShape::getCurveBeforeLPE() const +SPCurve * SPShape::getCurve(unsigned int owner) const { - if (hasPathEffectRecursive()) { - if (_curve_before_lpe) { - return this->_curve_before_lpe->copy(); - } - } else { - if (_curve) { - return _curve->copy(); + if (_curve) { + if(owner) { + return _curve; } + return _curve->copy(); } return NULL; } /** - * Same as sp_shape_set_curve but without updating the display + * Return curve *before* LPE (if any exists) or NULL if there is no curve + * If force is set allow return curve_before_lpe even if not + * has path effect like in clips and mask + * if owner == 0 return a copy */ -void SPShape::setCurveInsync(SPCurve *new_curve, unsigned int owner) +SPCurve * SPShape::getCurveBeforeLPE(unsigned int owner) const { - if (_curve) { - _curve = _curve->unref(); - } + if (_curve_before_lpe) { + if (owner) { + return _curve_before_lpe; + } + return _curve_before_lpe->copy(); + } + return NULL; +} - if (new_curve) { +/** + * Return curve for edit + * If force is set allow return curve_before_lpe even if not + * has path effect like in clips and mask + * if owner == 0 return a copy + */ +SPCurve * SPShape::getCurveForEdit(unsigned int owner) const +{ + if (_curve_before_lpe) { if (owner) { - _curve = new_curve->ref(); - } else { - _curve = new_curve->copy(); + return _curve_before_lpe; } + return _curve_before_lpe->copy(); } + return getCurve(owner); } void SPShape::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) const { -- cgit v1.2.3