Clone in a terminal:
Commit d1133cb
Johan Mattsson - 2016-07-21T22:20:14+00:00
d1133cbf040141e0532645333a93870e767a8bc5johan.mattsson.m@gmail.com

Resize SVG objects

Changed files (4)

Diff

diff --git a/README.md b/README.mdindex 580a12e..97e96e1 100644--- a/README.md+++ b/README.md@@ -60,7 +60,7 @@ Configure the project with ./configure --nonnull ## Packages  Windows and Mac binaries can be downloaded from-http://birdfont.org Many Linux distributions have packages of+https://birdfont.org Many Linux distributions have packages of Birdfont in their repositories. There is a BSD package in OpenBSD.  [birdfont]: https://birdfont.org/images/birdfont_logo2.png "Birdfont logo"diff --git a/libsvgbird/Object.vala b/libsvgbird/Object.valaindex fa1d538..2953b75 100644--- a/libsvgbird/Object.vala+++ b/libsvgbird/Object.vala@@ -105,6 +105,23 @@ public abstract class Object : GLib.Object { 		m.invert (); 		m.transform_point (ref x, ref y); 	}++	public void to_parent_distance (ref double x, ref double y) {+		Matrix m = parent_matrix;+		m.invert ();+		m.transform_distance (ref x, ref y);+	}+	+	public void to_parent_view (ref double x, ref double y) {+		Matrix m = parent_matrix;+		m.invert ();+		m.transform_point (ref x, ref y);+	}+	+	public void from_object_view (ref double x, ref double y) {+		Matrix m = view_matrix;+		m.transform_point (ref x, ref y);+	} 	 	public void to_object_distance (ref double x, ref double y) { 		Matrix m = view_matrix;@@ -274,6 +291,7 @@ public abstract class Object : GLib.Object { 		bool has_stroke = style.has_stroke ();  		apply_transform (context);+		view_matrix = context.get_matrix (); 		 		if (style.fill_gradient != null) { 			apply_gradient (context, (!) style.fill_gradient);diff --git a/libsvgbird/SvgStyle.vala b/libsvgbird/SvgStyle.valaindex 6b3d44c..cf13806 100644--- a/libsvgbird/SvgStyle.vala+++ b/libsvgbird/SvgStyle.vala@@ -26,6 +26,8 @@ public class SvgStyle : GLib.Object { 	public Gradient? fill_gradient = null; 	public LineCap line_cap = LineCap.BUTT; +	public bool visible = true;+ 	public double padding_top { 		get { 			return SvgFile.parse_number (get_css_property ("padding-top"));@@ -322,6 +324,14 @@ public class SvgStyle : GLib.Object { 			Color color = (!) s.stroke; 			color.a = stroke_opacity; 		}+		+		string? v = s.get_css_property ("visibility");+		if (v != null) {+			string visible = (!) v;+			if (visible == "hidden" || visible == "collapse") {+				s.visible = false;+			}+		} 	} 	 	void parse_key_value_pairs (string svg_style) {diff --git a/libsvgbird/SvgTransforms.vala b/libsvgbird/SvgTransforms.valaindex bd4a4ca..ae85c69 100644--- a/libsvgbird/SvgTransforms.vala+++ b/libsvgbird/SvgTransforms.vala@@ -23,8 +23,6 @@ public class SvgTransforms : GLib.Object { 	 	public double rotation = 0; 	public double total_rotation = 0;-	public double scale_x = 1;-	public double scale_y = 1; 	public double translate_x = 0; 	public double translate_y = 0; 	@@ -35,27 +33,19 @@ public class SvgTransforms : GLib.Object { 	}  	public void collapse_transforms () {-		Matrix translate_matrix = Matrix.identity ();-		translate_matrix.translate (translate_x, translate_y);-		SvgTransform translate_transform = new SvgTransform.for_matrix (translate_matrix);-		add (translate_transform);-		-		SvgTransform rotation_transform = new SvgTransform.for_matrix (rotation_matrix);-		add (rotation_transform);+		Matrix collapsed = get_matrix (); 		+		translate_x	= 0;+		translate_y	= 0;+ 		rotation_matrix = Matrix.identity (); 		rotation = 0; -		SvgTransform size_transform = new SvgTransform.for_matrix (size_matrix);-		add (size_transform);- 		size_matrix = Matrix.identity ();-		scale_x = 1;-		scale_y = 1; 		-		Matrix collapsed = get_matrix ();-		SvgTransform collapsed_transform = new SvgTransform.for_matrix (collapsed); 		clear ();+		+		SvgTransform collapsed_transform = new SvgTransform.for_matrix (collapsed); 		add (collapsed_transform); 	} @@ -66,8 +56,6 @@ public class SvgTransforms : GLib.Object { 		rotation = 0; 		 		size_matrix = Matrix.identity ();-		scale_x = 1;-		scale_y = 1; 		 		translate_x = 0; 		translate_y = 0;@@ -104,18 +92,22 @@ public class SvgTransforms : GLib.Object { 		rotation_matrix.translate (-x, -y); 	} -	public void resize (double ratio_x, double ratio_y, double x, double y) {-		scale_x *= ratio_x;-		scale_y *= ratio_y;-+	public void resize (double scale_x, double scale_y, double x, double y) { 		if (scale_x <= 0 || scale_y <= 0) { 			return; 		}-+		+		double x2 = x;+		double y2 = y;+		 		size_matrix = Matrix.identity ();-		size_matrix.translate (x, y); 		size_matrix.scale (scale_x, scale_y);-		size_matrix.translate (-x, -y);+		size_matrix.transform_point (ref x2, ref y2);++		double dx = x - x2;+		double dy = y - y2;+		+		size_matrix.translate (dx / scale_x, dy / scale_y); 	}  	public SvgTransforms copy () {@@ -141,8 +133,9 @@ public class SvgTransforms : GLib.Object { 		}  		transformation_matrix.translate (translate_x, translate_y);-		transformation_matrix.multiply (transformation_matrix, size_matrix);+ 		transformation_matrix.multiply (transformation_matrix, rotation_matrix);+		transformation_matrix.multiply (transformation_matrix, size_matrix);  		return transformation_matrix; 	}

Contact

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