Commit 0e05f7f
Fix view matrix
Changed files (5)
modifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/SvgDrawing.valamodifiedlibsvgbird/SvgFile.valamodifiedlibsvgbird/SvgTransforms.vala
Diff
@@ -43,22 +43,17 @@ public class Layer : Object { right = CANVAS_MIN; cr.save ();- + parent_matrix = copy_matrix (cr.get_matrix ());+ apply_transform (cr);+ view_matrix = copy_matrix (cr.get_matrix ());+ foreach (Object object in objects) { bool has_size = false; - cr.save ();- if (object is Layer) { Layer sublayer = (Layer) object;- object.parent_matrix = cr.get_matrix ();- sublayer.apply_transform (cr);- object.view_matrix = cr.get_matrix (); has_size = sublayer.update_boundaries (cr); } else {- object.parent_matrix = cr.get_matrix ();- object.apply_transform (cr);- object.view_matrix = cr.get_matrix (); has_size = object.update_boundaries (cr); } @@ -67,9 +62,7 @@ public class Layer : Object { right = fmax (right, object.right); top = fmin (top, object.top); bottom = fmax (bottom, object.bottom);- }-- cr.restore ();+ } } cr.restore ();@@ -87,6 +80,8 @@ public class Layer : Object { private void draw_layer (Context cr, bool paint) { cr.save ();++ apply_transform (cr); if (clip_path != null) { ClipPath clipping = (!) clip_path;@@ -103,8 +98,7 @@ public class Layer : Object { if (object is Layer) { Layer sublayer = (Layer) object;- sublayer.apply_transform (cr);- + if (paint) { sublayer.draw (cr); } else {@@ -144,7 +138,7 @@ public class Layer : Object { foreach (Object object in objects) { if (object is Layer) { Layer sublayer = (Layer) object;- sublayer.remove (o);;+ sublayer.remove (o); } } @@ -84,8 +84,8 @@ public abstract class Object : GLib.Object { } } - public const double CANVAS_MAX = 100000;- public const double CANVAS_MIN = -100000;+ public const double CANVAS_MAX = 1000000;+ public const double CANVAS_MIN = -1000000; public Matrix view_matrix = Matrix.identity (); public Matrix parent_matrix = Matrix.identity ();@@ -289,9 +289,12 @@ public abstract class Object : GLib.Object { public virtual bool update_boundaries (Context context) { double x0, y0, x1, y1; bool has_stroke = style.has_stroke ();+ + context.save (); + parent_matrix = copy_matrix (context.get_matrix ()); apply_transform (context);- view_matrix = context.get_matrix ();+ view_matrix = copy_matrix (context.get_matrix ()); if (style.fill_gradient != null) { apply_gradient (context, (!) style.fill_gradient);@@ -308,8 +311,6 @@ public abstract class Object : GLib.Object { } draw_outline (context);-- context.save (); context.set_matrix (Matrix.identity ()); if (has_stroke) {@@ -318,8 +319,6 @@ public abstract class Object : GLib.Object { context.fill_extents (out x0, out y0, out x1, out y1); } - context.set_matrix (view_matrix);- context.fill (); context.restore (); @@ -341,6 +340,10 @@ public abstract class Object : GLib.Object { context.set_matrix (parent_matrix); return update_boundaries (context); }+ + public Matrix copy_matrix (Matrix m) {+ return new Matrix (m.xx, m.yx, m.xy, m.yy, m.x0, m.y0);+ } } }@@ -28,7 +28,10 @@ public class SvgDrawing : Object { public double height = 0; public override bool update_boundaries (Context cr) {+ parent_matrix = cr.get_matrix (); apply_transform (cr);+ view_matrix = cr.get_matrix ();+ root_layer.update_boundaries (cr); left = root_layer.left;@@ -56,7 +59,6 @@ public class SvgDrawing : Object { public override void apply_transform (Context cr) { apply_view_box (cr); base.apply_transform (cr);- root_layer.apply_transform (cr); } public void draw (Context cr) {@@ -89,6 +89,7 @@ public class SvgFile : GLib.Object { } set_object_properties (drawing, new SvgStyle (), svg_tag);+ drawing.update_boundaries_for_object (); return drawing; }@@ -32,6 +32,12 @@ public class SvgTransforms : GLib.Object { size_matrix = Matrix.identity (); } + public void clear_rotation () {+ rotation = 0;+ total_rotation = 0;+ rotation_matrix = Matrix.identity (); + }+ public double get_rotation () { Matrix m = get_matrix (); double w = 1;