Code

Added/Fixed Pango font weights. Included Jon's workaround for Pango
[inkscape.git] / src / path-chemistry.cpp
index 6ef4b27423d4f07fd2d8cf4d6df651f30fef1bd2..c44ab5bc616e3c64e26e2558f27a467b59478bfd 100644 (file)
@@ -86,12 +86,20 @@ sp_selected_path_combine(SPDesktop *desktop)
     SPItem *first = NULL;
     Inkscape::XML::Node *parent = NULL; 
 
+    if (did) {
+        selection->clear();
+    }
+
     for (GSList *i = items; i != NULL; i = i->next) {  // going from top to bottom
 
         SPItem *item = (SPItem *) i->data;
         if (!SP_IS_PATH(item))
             continue;
-        did = true;
+
+        if (!did) {
+            selection->clear();
+            did = true;
+        }
 
         SPCurve *c = sp_path_get_curve_for_edit(SP_PATH(item));
         if (first == NULL) {  // this is the topmost path
@@ -124,11 +132,8 @@ sp_selected_path_combine(SPDesktop *desktop)
     g_slist_free(items);
 
     if (did) {
-        selection->clear();
-
-        // delete the topmost one so that its clones don't get alerted; this object will be
-        // restored shortly, with the same id
         SP_OBJECT(first)->deleteObject(false);
+        // delete the topmost.
 
         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
         Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
@@ -139,17 +144,18 @@ sp_selected_path_combine(SPDesktop *desktop)
         repr->setAttribute("style", style);
         g_free(style);
 
+        repr->setAttribute("inkscape:path-effect", path_effect);
+        g_free(path_effect);
+
         // set path data corresponding to new curve
         gchar *dstring = sp_svg_write_path(curve->get_pathvector());
         curve->unref();
-        repr->setAttribute("d", dstring);
         if (path_effect)
             repr->setAttribute("inkscape:original-d", dstring);
+        else
+            repr->setAttribute("d", dstring);
         g_free(dstring);
 
-        repr->setAttribute("inkscape:path-effect", path_effect);
-        g_free(path_effect);
-
         // add the new group to the parent of the topmost
         parent->appendChild(repr);
 
@@ -231,14 +237,15 @@ sp_selected_path_break_apart(SPDesktop *desktop)
             Inkscape::XML::Node *repr = parent->document()->createElement("svg:path");
             repr->setAttribute("style", style);
 
+            repr->setAttribute("inkscape:path-effect", path_effect);
+
             gchar *str = sp_svg_write_path(curve->get_pathvector());
-            repr->setAttribute("d", str);
             if (path_effect)
                 repr->setAttribute("inkscape:original-d", str);
+            else
+                repr->setAttribute("d", str);
             g_free(str);
 
-            repr->setAttribute("inkscape:path-effect", path_effect);
-
             // add the new repr to the parent
             parent->appendChild(repr);
 
@@ -259,7 +266,7 @@ sp_selected_path_break_apart(SPDesktop *desktop)
         g_slist_free(reprs);
         g_slist_free(list);
         g_free(style);
-
+        g_free(path_effect);
     }
 
     desktop->clearWaitingCursor();
@@ -316,8 +323,33 @@ sp_selected_path_to_curves(SPDesktop *desktop, bool interactive)
     }
 }
 
+/** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */
+void sp_selected_to_lpeitems(SPDesktop *desktop)
+{
+    Inkscape::Selection *selection = sp_desktop_selection(desktop);
+
+    if (selection->isEmpty()) {
+        return;
+    }
+
+    bool did = false;
+
+    GSList *selected = g_slist_copy((GSList *) selection->itemList());
+    GSList *to_select = NULL;
+    selection->clear();
+    GSList *items = g_slist_copy(selected);
+
+    did = sp_item_list_to_curves(items, &selected, &to_select, true);
+
+    g_slist_free (items);
+    selection->setReprList(to_select);
+    selection->addList(selected);
+    g_slist_free (to_select);
+    g_slist_free (selected);
+}
+
 bool
-sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select)
+sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems)
 {
     bool did = false;
     
@@ -328,6 +360,13 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec
         SPItem *item = SP_ITEM(items->data);
        SPDocument *document = item->document;
 
+        if ( skip_all_lpeitems &&
+             SP_IS_LPE_ITEM(item) && 
+             !SP_IS_GROUP(item) ) // also convert objects in an SPGroup when skip_all_lpeitems is set.
+        { 
+            continue;
+        }
+
         if (SP_IS_PATH(item) && !SP_PATH(item)->original_curve) {
             continue; // already a path, and no path effect
         }
@@ -539,7 +578,6 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
 }
 
 
-// FIXME: THIS DOES NOT REVERSE THE NODETYPES ORDER!
 void
 sp_selected_path_reverse(SPDesktop *desktop)
 {
@@ -577,6 +615,13 @@ sp_selected_path_reverse(SPDesktop *desktop)
         g_free(str);
 
         rcurve->unref();
+
+        // reverse nodetypes order (Bug #179866)
+        gchar *nodetypes = g_strdup(SP_OBJECT_REPR(path)->attribute("sodipodi:nodetypes"));
+        if ( nodetypes ) {
+            SP_OBJECT_REPR(path)->setAttribute("sodipodi:nodetypes", g_strreverse(nodetypes));
+            g_free(nodetypes);
+        }
     }
 
     desktop->clearWaitingCursor();