[dia] svg: group transforms now pass the W3C SVG test suite



commit 4c7a08303af693b3c39072aaabcf777fe8e91147
Author: Hans Breuer <hans breuer org>
Date:   Fri Aug 23 17:39:26 2013 +0200

    svg: group transforms now pass the W3C SVG test suite
    
    The initial attempt to translate matrix.x0 and matrix.y0 to
    simple group offset was flawed. Now the given matrix is kept
    as given and the groups position etc. are calculated with it.
    The group' objects real coordinates are only moved without
    a matrix, otherwise it's just a simple matrix change.
    
    Also fix some comments/typos.

 lib/dia_svg.c |    5 ++---
 lib/group.c   |   41 ++++++++++++++++++-----------------------
 2 files changed, 20 insertions(+), 26 deletions(-)
---
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index 13fcad7..d924806 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -1413,9 +1413,8 @@ _parse_transform (const gchar *trans, DiaMatrix *m, real scale)
       g_warning ("transform=rotate no angle?");
     }
     m->xx =  cos(G_PI*angle/180);
-    /* FIXME: swapped xy and yx - correct? */
-    m->xy = -sin(G_PI*angle/180);
     m->yx =  sin(G_PI*angle/180);
+    m->xy = -sin(G_PI*angle/180);
     m->yy =  cos(G_PI*angle/180);
     /* FIXME: check with real world data, I'm uncertain */
     if (list[i]) {
@@ -1461,7 +1460,7 @@ dia_svg_parse_transform(const gchar *trans, real scale)
   gchar **transforms = g_regex_split_simple ("\\)", trans, 0, 0);
   int i = 0;
 
-  /* go through the list of ztansformations - not that one would be enough ;) */
+  /* go through the list of transformations - not that one would be enough ;) */
   while (transforms[i]) {
     DiaMatrix mat = { 0, };
 
diff --git a/lib/group.c b/lib/group.c
index 547fa92..c341f80 100644
--- a/lib/group.c
+++ b/lib/group.c
@@ -196,6 +196,20 @@ group_update_connectionpoints(Group *group)
 #endif
 }
 
+static void
+group_objects_move_delta (Group *group, const Point *delta)
+{
+  if (group->matrix) {
+    DiaMatrix *m = group->matrix;
+
+    m->x0 += delta->x;
+    m->y0 += delta->y;
+  } else {
+    Point dt = *delta;
+    object_list_move_delta(group->objects, &dt);
+  }
+}
+
 static ObjectChange*
 group_move_handle(Group *group, Handle *handle, Point *to, ConnectionPoint *cp,
                  HandleMoveReason reason, ModifierKeys modifiers)
@@ -258,7 +272,7 @@ group_move_handle(Group *group, Handle *handle, Point *to, ConnectionPoint *cp,
   }
 
   if (also_move)
-    object_list_move_delta(group->objects, &delta);
+    group_objects_move_delta(group, &delta);
   if (!group->matrix) {
     group->matrix = g_new0 (DiaMatrix, 1);
     group->matrix->xx = 1.0;
@@ -312,7 +326,7 @@ group_move(Group *group, Point *to)
   /* We don't need any transformation of delta, because 
    * group_update_data () maintains the relative position.
    */
-  object_list_move_delta(group->objects, &delta);
+  group_objects_move_delta(group, &delta);
   
   group_update_data(group);
 
@@ -465,8 +479,7 @@ group_update_data(Group *group)
       DiaMatrix *m = group->matrix;
 
       /* maintain obj->position */
-      m->x0 = obj->position.x - (m->xx * obj->position.x + m->xy  * obj->position.y);
-      m->y0 = obj->position.y - (m->yx * obj->position.x + m->yy  * obj->position.y);
+      transform_point (&group->object.position, m);
 
       /* recalculate bounding box */
       /* need to consider all corners */
@@ -499,15 +512,7 @@ DiaObject *
 group_create_with_matrix(GList *objects, DiaMatrix *matrix)
 {
   Group *group = (Group *)group_create(objects);
-  if (matrix->x0 != 0 || matrix->y0 != 0) {
-    Point delta = {matrix->x0, matrix->y0};
-    const Point *pos = &group->object.position;
-    /* the resulting offset is what we want to shift to */
-    delta.x += (matrix->xx * pos->x - pos->x);
-    delta.y += (matrix->yy * pos->y - pos->y);
-    matrix->x0 = matrix->y0 = 0; /* offset used internally */
-    object_list_move_delta(group->objects, &delta);
-  }
+
   if (dia_matrix_is_identity (matrix)) {
     /* just drop it as it has no effect */
     g_free (matrix);
@@ -894,15 +899,5 @@ group_transform (Group *group, const DiaMatrix *m)
   } else {
     group->matrix = g_memdup (m, sizeof(*m));
   }
-  /* don't keep the offset in the matrix*/
-  if (group->matrix->x0 != 0 || group->matrix->y0 != 0) {
-    Point delta = {group->matrix->x0, group->matrix->y0};
-    const Point *pos = &group->object.position;
-    /* the resulting offset is what we want to shift to */
-    delta.x += (m->xx * pos->x - pos->x);
-    delta.y += (m->yy * pos->y - pos->y);
-    group->matrix->x0 = group->matrix->y0 = 0; /* offset used internally */
-    object_list_move_delta(group->objects, &delta);
-  }
   group_update_data (group);
 }


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