Clone in a terminal:
Commit 0e05f7f
Johan Mattsson - 2016-07-24T20:22:55+00:00
0e05f7facf16ba8b0b1f17eb2c5f80f2a367b8b5johan.mattsson.m@gmail.com

Fix view matrix

Changed files (5)

Diff

diff --git a/libsvgbird/Layer.vala b/libsvgbird/Layer.valaindex 046ead1..1834d85 100644--- a/libsvgbird/Layer.vala+++ b/libsvgbird/Layer.vala@@ -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); 			} 		} 		diff --git a/libsvgbird/Object.vala b/libsvgbird/Object.valaindex 034c618..80c45f6 100644--- a/libsvgbird/Object.vala+++ b/libsvgbird/Object.vala@@ -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);+	} }  }diff --git a/libsvgbird/SvgDrawing.vala b/libsvgbird/SvgDrawing.valaindex 9e0a73f..106d24f 100644--- a/libsvgbird/SvgDrawing.vala+++ b/libsvgbird/SvgDrawing.vala@@ -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) {diff --git a/libsvgbird/SvgFile.vala b/libsvgbird/SvgFile.valaindex a28e07e..8b378e2 100644--- a/libsvgbird/SvgFile.vala+++ b/libsvgbird/SvgFile.vala@@ -89,6 +89,7 @@ public class SvgFile : GLib.Object { 		}  		set_object_properties (drawing, new SvgStyle (), svg_tag);+		drawing.update_boundaries_for_object (); 		 		return drawing; 	}diff --git a/libsvgbird/SvgTransforms.vala b/libsvgbird/SvgTransforms.valaindex 6524250..cf6214c 100644--- a/libsvgbird/SvgTransforms.vala+++ b/libsvgbird/SvgTransforms.vala@@ -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;

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112