[dia] [transform] affine transformations for SVG import/export



commit e9bd23e5bae74e919e65a4e0c84aed292b6be375
Author: Hans Breuer <hans breuer org>
Date:   Sun Sep 12 14:38:38 2010 +0200

    [transform] affine transformations for SVG import/export

 lib/group.h               |    1 +
 lib/libdia.def            |    1 +
 plug-ins/svg/render_svg.c |    8 ++++++++
 plug-ins/svg/svg-import.c |   19 +++++++++++++++++--
 4 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/lib/group.h b/lib/group.h
index 37ce540..24b863b 100644
--- a/lib/group.h
+++ b/lib/group.h
@@ -27,6 +27,7 @@ DIAVAR DiaObjectType group_type;
  * outside of the created group before calling group_create().
  */
 DiaObject *group_create(GList *objects);
+DiaObject *group_create_with_matrix(GList *objects, DiaMatrix *matrix);
 GList *group_objects(DiaObject *group);
 
 void group_destroy_shallow(DiaObject *group);
diff --git a/lib/libdia.def b/lib/libdia.def
index 43ac06d..dba0248 100644
--- a/lib/libdia.def
+++ b/lib/libdia.def
@@ -436,6 +436,7 @@ EXPORTS
  get_units_name_list
 
  group_create
+ group_create_with_matrix
  group_destroy_shallow
  group_objects
  group_type
diff --git a/plug-ins/svg/render_svg.c b/plug-ins/svg/render_svg.c
index be7e6ec..4229778 100644
--- a/plug-ins/svg/render_svg.c
+++ b/plug-ins/svg/render_svg.c
@@ -45,6 +45,7 @@
 #include "dia_xml_libxml.h"
 #include "object.h"
 #include "textline.h"
+#include "dia_svg.h"
 
 G_BEGIN_DECLS
 
@@ -257,6 +258,13 @@ draw_object(DiaRenderer *self,
   xmlNodePtr child, group;
 
   g_queue_push_tail (svg_renderer->parents, renderer->root);
+
+  if (matrix) {
+    gchar *s = dia_svg_from_matrix (matrix, renderer->scale);
+    xmlSetProp(renderer->root, (const xmlChar *)"transform", (xmlChar *) s);
+    g_free (s);
+  }
+
   /* modifying the root pointer so everything below us gets into the new node */
   renderer->root = group = xmlNewNode (renderer->svg_name_space, (const xmlChar *)"g");
 
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index eb1c032..c74295d 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -739,22 +739,37 @@ read_items (xmlNodePtr startnode, DiaSvgStyle *parent_gs, const gchar *filename_
     if (!xmlStrcmp(node->name, (const xmlChar *)"g")) {
       GList *moreitems;
       DiaSvgStyle *group_gs;
+      DiaMatrix *matrix = NULL;
+      xmlChar *trans;
 
       /* We need to have/apply the groups style before the objects style */
       group_gs = g_new0 (DiaSvgStyle, 1);
       dia_svg_style_init (group_gs, parent_gs);
       dia_svg_parse_style (node, group_gs, user_scale);
 
+      trans = xmlGetProp (node, (xmlChar *)"transform");
+      if (trans) {
+        matrix = dia_svg_parse_transform ((gchar *)trans, user_scale);
+	xmlFree (trans);
+      }
+
       moreitems = read_items (node->xmlChildrenNode, group_gs, filename_svg);
 
       if (moreitems) {
-        DiaObject *group = group_create (moreitems);
+        DiaObject *group;
+
+	if (matrix) {
+	  group = group_create_with_matrix (moreitems, matrix);
+	  matrix = NULL;
+	} else
+	  group = group_create (moreitems);
 	/* group eats list */
         items = g_list_append (items, group);
       }
       if (group_gs->font)
         dia_font_unref (group_gs->font);
       g_free (group_gs);
+      g_free (matrix);
     } else if (!xmlStrcmp(node->name, (const xmlChar *)"rect")) {
       items = read_rect_svg(node, parent_gs, items);
     } else if (!xmlStrcmp(node->name, (const xmlChar *)"line")) {
@@ -782,7 +797,7 @@ read_items (xmlNodePtr startnode, DiaSvgStyle *parent_gs, const gchar *filename_
       if (moreitems) {
         items = g_list_concat (items, moreitems);
       }
-   }
+    }
   }
   return items;
 }



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