[dia] svg: improve group-to-layer support



commit 875ad6a1a7650a604bc2024d0f0e4d80ec352898
Author: Hans Breuer <hans breuer org>
Date:   Sat Jul 20 20:08:24 2013 +0200

    svg: improve group-to-layer support
    
    We have to convert _all_ the groups to layers or not at all to
    preserve the drawing order. Also we should keep the groups intact
    to preserve potential transformations.

 plug-ins/svg/svg-import.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 274905a..68bad3f 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -1194,8 +1194,10 @@ read_items (xmlNodePtr   startnode,
       /* Patterns could be considered as groups, too But Dia does not
        * have the facility to apply them (yet?). */
     } else {
-      /* everything else is treated like a group _without grouping_, i.e. we dive into unknown stuff */
-      /* this allows to import stuff generated by 'dot' with links for the nodes */
+      /* everything else is treated like a group _without grouping_, i.e. we dive
+       * into unknown stuff. This allows to import stuff generated by 'dot' with
+       * e.g. links for the nodes.
+       */
       GList *moreitems;
       /* on of the non-grouping elements is <a>, extract possible links */
       xmlChar *href = xmlGetProp (node, (const xmlChar *)"href");
@@ -1347,6 +1349,7 @@ import_svg (xmlDocPtr doc, DiagramData *dia,
   xmlNodePtr shape_root = NULL;
   GList *items, *item;
   guint num_items = 0;
+  gboolean groups_to_layers = TRUE;
 
   /* skip (emacs) comments */
   root = doc->xmlRootNode;
@@ -1443,23 +1446,34 @@ import_svg (xmlDocPtr doc, DiagramData *dia,
    * But if there is just one item - even if a group - it is put into the active layer.
    */
   num_items = g_list_length (items);
+  /* We have to convert _all_ the groups to layers or not at all to
+   * preserve the drawing order. Also we should keep the groups intact
+   * to preserve potential transformations.
+   */
+  if (num_items == 1)
+    groups_to_layers = FALSE;
+  for (item = items; groups_to_layers && item != NULL; item = g_list_next (item)) {
+    DiaObject *obj = (DiaObject *)item->data;
+    gchar *name;
+
+    if (IS_GROUP(obj) && ((name = dia_object_get_meta (obj, "id")) != NULL))
+      g_free (name);
+    else
+      groups_to_layers = FALSE;
+  }
   for (item = items; item != NULL; item = g_list_next (item)) {
     DiaObject *obj = (DiaObject *)item->data;
-    gchar *name = NULL;
 
-    if (num_items > 1 && IS_GROUP(obj) && ((name = dia_object_get_meta (obj, "id")) != NULL)) {
-      DiaObject *group = (DiaObject *)item->data;
+    if (groups_to_layers) {
+      gchar *name = dia_object_get_meta (obj, "id");
       /* new_layer() is taking ownership of the name */
-      Layer *layer = new_layer (g_strdup (name), dia);
+      Layer *layer = new_layer (name, dia);
 
-      /* layer_add_objects() is taking ownersip of the list */
-      layer_add_objects (layer, g_list_copy (group_objects (group)));
+      /* keep the group for potential transformation */
+      layer_add_object (layer, obj);
       data_add_layer (dia, layer);
-      group_destroy_shallow (group);
-      g_free (name);
     } else {
       /* Just as before: throw it in the active layer */
-      DiaObject *obj = (DiaObject *)item->data;
       layer_add_object(dia->active_layer, obj);
       layer_update_extents(dia->active_layer);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]