Code

Fixed copying of old settings, along with some data() vs. c_str() cleanup. Fixes...
[inkscape.git] / src / sp-lpe-item.cpp
index fdf348b78a7a022f075c5104a079b2d184f73578..49264c684c5217b30205a16e08871a8e9f102731 100644 (file)
@@ -44,7 +44,7 @@ static void sp_lpe_item_class_init(SPLPEItemClass *klass);
 static void sp_lpe_item_init(SPLPEItem *lpe_item);
 static void sp_lpe_item_finalize(GObject *object);
 
-static void sp_lpe_item_build(SPObject *object, Document *document, Inkscape::XML::Node *repr);
+static void sp_lpe_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
 static void sp_lpe_item_release(SPObject *object);
 static void sp_lpe_item_set(SPObject *object, unsigned int key, gchar const *value);
 static void sp_lpe_item_update(SPObject *object, SPCtx *ctx, guint flags);
@@ -137,7 +137,7 @@ sp_lpe_item_finalize(GObject *object)
  * sp-object-repr.cpp's repr_name_entries array.
  */
 static void
-sp_lpe_item_build(SPObject *object, Document *document, Inkscape::XML::Node *repr)
+sp_lpe_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
 {
     sp_object_read_attr(object, "inkscape:path-effect");
 
@@ -283,11 +283,13 @@ sp_lpe_item_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::
 {
     SPLPEItem *lpeitem = (SPLPEItem *) object;
 
-    if ( sp_lpe_item_has_path_effect(lpeitem) ) {
-        std::string href = patheffectlist_write_svg(*lpeitem->path_effect_list);
-        repr->setAttribute("inkscape:path-effect", href.c_str());
-    } else {
-        repr->setAttribute("inkscape:path-effect", NULL);
+    if (flags & SP_OBJECT_WRITE_EXT) {
+        if ( sp_lpe_item_has_path_effect(lpeitem) ) {
+            std::string href = patheffectlist_write_svg(*lpeitem->path_effect_list);
+            repr->setAttribute("inkscape:path-effect", href.c_str());
+        } else {
+            repr->setAttribute("inkscape:path-effect", NULL);
+        }
     }
 
     if (((SPObjectClass *)(parent_class))->write) {
@@ -541,7 +543,11 @@ void sp_lpe_item_remove_current_path_effect(SPLPEItem *lpeitem, bool keep_paths)
     new_list.remove(lperef); //current lpe ref is always our 'own' pointer from the path_effect_list
     std::string r = patheffectlist_write_svg(new_list);
 
-    SP_OBJECT_REPR(lpeitem)->setAttribute("inkscape:path-effect", r.c_str());
+    if (!r.empty()) {
+        SP_OBJECT_REPR(lpeitem)->setAttribute("inkscape:path-effect", r.c_str());
+    } else {
+        SP_OBJECT_REPR(lpeitem)->setAttribute("inkscape:path-effect", NULL);
+    }
 
     if (!keep_paths) {
         sp_lpe_item_cleanup_original_path_recursive(lpeitem);
@@ -598,6 +604,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)
 {