summaryrefslogtreecommitdiffstats
path: root/src/sp-lpe-item.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sp-lpe-item.cpp')
-rw-r--r--src/sp-lpe-item.cpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp
index 762dc3191..5818054a7 100644
--- a/src/sp-lpe-item.cpp
+++ b/src/sp-lpe-item.cpp
@@ -38,6 +38,11 @@
#include "desktop.h"
#include "shape-editor.h"
#include "sp-ellipse.h"
+#include "display/curve.h"
+#include "svg/svg.h"
+#include <2geom/pathvector.h>
+#include "sp-clippath.h"
+#include "sp-mask.h"
#include "tools-switch.h"
#include "ui/tools/node-tool.h"
#include "ui/tools/tool-base.h"
@@ -51,6 +56,8 @@ static void lpeobject_ref_modified(SPObject *href, guint flags, SPLPEItem *lpeit
static void sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem);
static void sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem);
+static void sp_lpe_item_apply_to_clip_or_mask_group(SPGroup * group, SPItem * item);
+
typedef std::list<std::string> HRefList;
static std::string patheffectlist_write_svg(PathEffectList const & list);
static std::string hreflist_write_svg(HRefList const & list);
@@ -332,6 +339,16 @@ lpeobject_ref_modified(SPObject */*href*/, guint /*flags*/, SPLPEItem *lpeitem)
static void
sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem)
{
+ SPMask * mask = lpeitem->mask_ref->getObject();
+ if(mask)
+ {
+ sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(mask->firstChild()));
+ }
+ SPClipPath * clipPath = lpeitem->clip_ref->getObject();
+ if(clipPath)
+ {
+ sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild()));
+ }
if (SP_IS_GROUP(lpeitem)) {
GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
for ( GSList const *iter = item_list; iter; iter = iter->next ) {
@@ -352,6 +369,17 @@ sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem)
static void
sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem)
{
+ SPMask * mask = lpeitem->mask_ref->getObject();
+ if(mask)
+ {
+ sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(mask->firstChild()));
+ }
+ SPClipPath * clipPath = lpeitem->clip_ref->getObject();
+ if(clipPath)
+ {
+ sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild()));
+ }
+
if (SP_IS_GROUP(lpeitem)) {
GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
for ( GSList const *iter = item_list; iter; iter = iter->next ) {
@@ -597,6 +625,124 @@ bool SPLPEItem::hasPathEffectRecursive() const
}
}
+void
+sp_lpe_item_apply_to_clippath(SPItem * item)
+{
+ SPClipPath *clipPath = item->clip_ref->getObject();
+ if(clipPath) {
+ SPObject * clip_data = clipPath->firstChild();
+ SPCurve * clip_curve = NULL;
+
+ if (SP_IS_PATH(clip_data)) {
+ clip_curve = SP_PATH(clip_data)->get_original_curve();
+ } else if(SP_IS_SHAPE(clip_data)) {
+ clip_curve = SP_SHAPE(clip_data)->getCurve();
+ } else if(SP_IS_GROUP(clip_data)) {
+ sp_lpe_item_apply_to_clip_or_mask_group(SP_GROUP(clip_data), item);
+ return;
+ }
+ if(clip_curve) {
+ bool success = SP_LPE_ITEM(item)->performPathEffect(clip_curve);
+ Inkscape::XML::Node *reprClip = clip_data->getRepr();
+ if (success) {
+ gchar *str = sp_svg_write_path(clip_curve->get_pathvector());
+ reprClip->setAttribute("d", str);
+ g_free(str);
+ } else {
+ // LPE was unsuccesfull. Read the old 'd'-attribute.
+ if (gchar const * value = reprClip->attribute("d")) {
+ Geom::PathVector pv = sp_svg_read_pathv(value);
+ SPCurve *oldcurve = new SPCurve(pv);
+ if (oldcurve) {
+ SP_SHAPE(clip_data)->setCurve(oldcurve, TRUE);
+ oldcurve->unref();
+ }
+ }
+ }
+ clip_curve->unref();
+ }
+ }
+}
+
+void
+sp_lpe_item_apply_to_mask(SPItem * item)
+{
+ SPMask *mask = item->mask_ref->getObject();
+ if(mask) {
+ SPObject * mask_data = mask->firstChild();
+ SPCurve * mask_curve = NULL;
+ mask_data = mask->firstChild();
+ if (SP_IS_PATH(mask_data)) {
+ mask_curve = SP_PATH(mask_data)->get_original_curve();
+ } else if(SP_IS_SHAPE(mask_data)) {
+ mask_curve = SP_SHAPE(mask_data)->getCurve();
+ } else if(SP_IS_GROUP(mask_data)) {
+ sp_lpe_item_apply_to_clip_or_mask_group(SP_GROUP(mask_data), item);
+ return;
+ }
+ if(mask_curve) {
+ bool success = SP_LPE_ITEM(item)->performPathEffect(mask_curve);
+ Inkscape::XML::Node *reprmask = mask_data->getRepr();
+ if (success) {
+ gchar *str = sp_svg_write_path(mask_curve->get_pathvector());
+ reprmask->setAttribute("d", str);
+ g_free(str);
+ } else {
+ // LPE was unsuccesfull. Read the old 'd'-attribute.
+ if (gchar const * value = reprmask->attribute("d")) {
+ Geom::PathVector pv = sp_svg_read_pathv(value);
+ SPCurve *oldcurve = new SPCurve(pv);
+ if (oldcurve) {
+ SP_SHAPE(mask_data)->setCurve(oldcurve, TRUE);
+ oldcurve->unref();
+ }
+ }
+ }
+ mask_curve->unref();
+ }
+ }
+}
+
+static void
+sp_lpe_item_apply_to_clip_or_mask_group(SPGroup *group, SPItem *item)
+{
+ GSList *item_list = sp_item_group_item_list(group);
+ for ( GSList *iter = item_list; iter; iter = iter->next ) {
+ SPObject *subitem = static_cast<SPObject *>(iter->data);
+ if (SP_IS_GROUP(subitem)) {
+ sp_lpe_item_apply_to_clip_or_mask_group(SP_GROUP(subitem), item);
+ } else if (SP_IS_SHAPE(subitem)) {
+ SPCurve * c = NULL;
+
+ if (SP_IS_PATH(subitem)) {
+ c = SP_PATH(subitem)->get_original_curve();
+ } else {
+ c = SP_SHAPE(subitem)->getCurve();
+ }
+ if (c) {
+ bool success = SP_LPE_ITEM(item)->performPathEffect(c);
+ Inkscape::XML::Node *repr = subitem->getRepr();
+ if (success) {
+ gchar *str = sp_svg_write_path(c->get_pathvector());
+ repr->setAttribute("d", str);
+ g_free(str);
+ } else {
+ // LPE was unsuccesfull. Read the old 'd'-attribute.
+ if (gchar const * value = repr->attribute("d")) {
+ Geom::PathVector pv = sp_svg_read_pathv(value);
+ SPCurve *oldcurve = new SPCurve(pv);
+ if (oldcurve) {
+ SP_SHAPE(subitem)->setCurve(oldcurve, TRUE);
+ oldcurve->unref();
+ }
+ }
+ }
+ c->unref();
+ }
+ }
+ }
+}
+
Inkscape::LivePathEffect::Effect*
SPLPEItem::getPathEffectOfType(int type)
{