Code

fix rendering of testcase errorhandling-nosuchlpe.svg: make sure shapes do not calcul...
authorbuliabyak <buliabyak@users.sourceforge.net>
Sat, 22 Aug 2009 21:49:32 +0000 (21:49 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Sat, 22 Aug 2009 21:49:32 +0000 (21:49 +0000)
src/sp-ellipse.cpp
src/sp-lpe-item.cpp
src/sp-lpe-item.h
src/sp-spiral.cpp
src/sp-star.cpp

index ff2e3904437961c62e8f6481a4cb7e12ad9c323e..769fa54fd62ed41b84ac16d06b6b9251eebe0041 100644 (file)
@@ -28,6 +28,7 @@
 #include "display/curve.h"
 #include <glibmm/i18n.h>
 #include <2geom/transforms.h>
+#include <2geom/pathvector.h>
 
 #include "document.h"
 #include "sp-ellipse.h"
@@ -184,6 +185,18 @@ sp_genericellipse_update_patheffect(SPLPEItem *lpeitem, bool write)
 /* Can't we use arcto in this method? */
 static void sp_genericellipse_set_shape(SPShape *shape)
 {
+    if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) {
+        g_warning ("The ellipse shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as ellipse will remove the bad LPE");
+        if (SP_OBJECT_REPR(shape)->attribute("d")) {
+            // unconditionally read the curve from d, if any, to preserve appearance
+            Geom::PathVector pv = sp_svg_read_pathv(SP_OBJECT_REPR(shape)->attribute("d"));
+            SPCurve *cold = new SPCurve(pv);
+            sp_shape_set_curve_insync (shape, cold, TRUE);
+            cold->unref();
+        }
+        return;
+    }
+
     double rx, ry, s, e;
     double x0, y0, x1, y1, x2, y2, x3, y3;
     double len;
index 90e9b2d6d62e18057b40c46c71177d811b5362ef..a27344ebca69fd14c2672741ba90d8830c2d3b14 100644 (file)
@@ -598,6 +598,24 @@ void sp_lpe_item_up_current_path_effect(SPLPEItem *lpeitem)
     sp_lpe_item_cleanup_original_path_recursive(lpeitem);
 }
 
+/** used for shapes so they can see if they should also disable shape calculation and read from d= */
+bool sp_lpe_item_has_broken_path_effect(SPLPEItem *lpeitem)
+{
+    if (lpeitem->path_effect_list->empty())
+        return false;
+
+    // go through the list; if some are unknown or invalid, return true
+    PathEffectList effect_list =  sp_lpe_item_get_effect_list(lpeitem);
+    for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); it++)
+    {
+        LivePathEffectObject *lpeobj = (*it)->lpeobject;
+        if (!lpeobj || !lpeobj->get_lpe())
+            return true;
+    }
+
+    return false;
+}
+
 
 bool sp_lpe_item_has_path_effect(SPLPEItem *lpeitem)
 {
index e9561c2c2c26f6f89a9ba5436c0b213d8a15d924..5b6cc241eeb2112f37cf3e1460d762ccb29ef1e4 100644 (file)
@@ -64,6 +64,7 @@ void sp_lpe_item_remove_current_path_effect(SPLPEItem *lpeitem, bool keep_paths)
 void sp_lpe_item_down_current_path_effect(SPLPEItem *lpeitem);
 void sp_lpe_item_up_current_path_effect(SPLPEItem *lpeitem);
 bool sp_lpe_item_has_path_effect(SPLPEItem *lpeitem);
+bool sp_lpe_item_has_broken_path_effect(SPLPEItem *lpeitem);
 bool sp_lpe_item_has_path_effect_recursive(SPLPEItem *lpeitem);
 Inkscape::LivePathEffect::Effect* sp_lpe_item_has_path_effect_of_type(SPLPEItem *lpeitem, int type);
 bool sp_lpe_item_can_accept_freehand_shape(SPLPEItem *lpeitem);
index 71906fcc0c3b65d394e6333dd163c7640a7ddaed..6297153327939f3b71f5100d4675add5a31ac9ed 100644 (file)
@@ -20,6 +20,7 @@
 #include "svg/svg.h"
 #include "attributes.h"
 #include <2geom/bezier-utils.h>
+#include <2geom/pathvector.h>
 #include "display/curve.h"
 #include <glibmm/i18n.h>
 #include "xml/repr.h"
@@ -418,11 +419,23 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral,
 static void
 sp_spiral_set_shape (SPShape *shape)
 {
+       SPSpiral *spiral = SP_SPIRAL(shape);
+
+    if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) {
+        g_warning ("The spiral shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as spiral will remove the bad LPE");
+        if (SP_OBJECT_REPR(shape)->attribute("d")) {
+            // unconditionally read the curve from d, if any, to preserve appearance
+            Geom::PathVector pv = sp_svg_read_pathv(SP_OBJECT_REPR(shape)->attribute("d"));
+            SPCurve *cold = new SPCurve(pv);
+            sp_shape_set_curve_insync (shape, cold, TRUE);
+            cold->unref();
+        }
+        return;
+    }
+
        Geom::Point darray[SAMPLE_SIZE + 1];
        double t;
 
-       SPSpiral *spiral = SP_SPIRAL(shape);
-
        SP_OBJECT (spiral)->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
        SPCurve *c = new SPCurve ();
index 71c9ad1c72d47bc17513335be25baf65d8c064c7..9cffd952ca2c72bb2ea91ec0b26ebdc4a9eb1933 100644 (file)
@@ -28,6 +28,8 @@
 #include "xml/repr.h"
 #include "document.h"
 
+#include <2geom/pathvector.h>
+
 #include "sp-star.h"
 
 static void sp_star_class_init (SPStarClass *klass);
@@ -428,6 +430,21 @@ sp_star_set_shape (SPShape *shape)
 {
        SPStar *star = SP_STAR (shape);
 
+    // perhaps we should convert all our shapes into LPEs without source path
+    // and with knotholders for parameters, then this situation will be handled automatically
+    // by disabling the entire stack (including the shape LPE)
+    if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) {
+        g_warning ("The star shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as star will remove the bad LPE");
+        if (SP_OBJECT_REPR(shape)->attribute("d")) {
+            // unconditionally read the curve from d, if any, to preserve appearance
+            Geom::PathVector pv = sp_svg_read_pathv(SP_OBJECT_REPR(shape)->attribute("d"));
+            SPCurve *cold = new SPCurve(pv);
+            sp_shape_set_curve_insync (shape, cold, TRUE);
+            cold->unref();
+        }
+        return;
+    }
+
        SPCurve *c = new SPCurve ();
 
        gint sides = star->sides;
@@ -500,7 +517,7 @@ sp_star_set_shape (SPShape *shape)
         bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe);
         if (success) {
             sp_shape_set_curve_insync (shape, c_lpe, TRUE);
-        }
+        } 
         c_lpe->unref();
     }
     c->unref();
@@ -587,3 +604,13 @@ sp_star_get_xy (SPStar *star, SPStarPoint point, gint index, bool randomized)
        }
 }
 
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :