Clone in a terminal:
Commit 78d50a2
Johan Mattsson - 2013-08-04T16:47:13+00:00
78d50a273cb3288d24ff9cd1c33ef6ba349da9a9johan.mattsson.m@gmail.com

rotate paths

Changed files (5)

Diff

diff --git a/NEWS b/NEWSindex 828554a..975b534 100644--- a/NEWS+++ b/NEWS@@ -1,4 +1,10 @@-birdfont (0.24) stable;+birdfont (0.26) stable;++  * Bug fixes for Mac OS X++ -- Johan Mattsson <johan.mattsson.m@gmail.com>  Sun Aug  4 18:28:40 CEST 2013++birdfont (0.25) stable;    * Bug fixes diff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex c915b60..21e4d99 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -26,6 +26,15 @@ class MoveTool : Tool { 	bool resize_path = false; 	Path? resized_path = null; 	double last_resize_y;++	bool rotate_path = false;+	double last_rotate_y;+	double rotation_box_width = 0;+	double rotation_box_height = 0;+	double rotation_box_center_x = 0;+	double rotation_box_center_y = 0;+	double rotation = 0;+	double last_rotate = 0; 	 	ImageSurface? resize_handle; 	@@ -54,12 +63,18 @@ class MoveTool : Tool { 					last_resize_y = y; 					return; 				}+				+				if (is_over_rotate_handle (p, x, y)) {+					rotate_path = true;+					return;+				} 			} 			 			if (resized_path != null) { 				if (is_over_resize_handle ((!) resized_path, x, y)) { 					resize_path = true; 					last_resize_y = y;+					rotation = 0; 					return;					 				} 			}@@ -71,7 +86,13 @@ class MoveTool : Tool { 			} 			 			move_path = true;-				++			last_rotate = 0;+			rotation = 0;+			last_rotate_y = y;++			update_selection_boundries ();+						 			last_x = x; 			last_y = y; 		});@@ -81,7 +102,8 @@ class MoveTool : Tool { 			 			move_path = false; 			resize_path = false;-				+			rotate_path = false;+			 			if (GridTool.is_visible ()) { 				foreach (Path p in glyph.active_paths) { 					tie_path_to_grid (p, x, y);@@ -105,6 +127,16 @@ class MoveTool : Tool { 				resize (x, y); 			} +			if (rotate_path) {+				rotate (x, y);+			}++			if (!rotate_path) {+				get_rotation_box_boundries (out rotation_box_center_x,+					out rotation_box_center_y, out rotation_box_width,+					out rotation_box_height);	+			}+ 			last_x = x; 			last_y = y; @@ -133,15 +165,85 @@ class MoveTool : Tool { 		 		draw_action.connect ((self, cr, glyph) => { 			Glyph g = MainWindow.get_current_glyph ();-			ImageSurface img = (!) resize_handle;-		+			ImageSurface resize_img = (!) resize_handle;+			 			foreach (Path p in g.active_paths) {-				cr.set_source_surface (img, Glyph.reverse_path_coordinate_x (p.xmax) - 10, Glyph.reverse_path_coordinate_y (p.ymax) - 10);-				cr.paint ();	+				cr.set_source_surface (resize_img, Glyph.reverse_path_coordinate_x (p.xmax) - 10, Glyph.reverse_path_coordinate_y (p.ymax) - 10);+				cr.paint ();+			}+			+			if (g.active_paths.length () > 0) {+				draw_rotate_handle (cr); 			} 		}); 	} +	void update_selection_boundries () {+		get_rotation_box_boundries (out rotation_box_center_x,+			out rotation_box_center_y, out rotation_box_width,+			out rotation_box_height);	+	}++	void draw_rotate_handle (Context cr) {+		double cx, cy, hx, hy;+		+		cx = Glyph.reverse_path_coordinate_x (rotation_box_center_x);+		cy = Glyph.reverse_path_coordinate_y (rotation_box_center_y);+		+		cr.save ();+		+		cr.set_source_rgba (0, 0, 0.3, 1);+		cr.rectangle (cx - 2.5, cy - 2.5, 5, 5);+		cr.fill ();++		hx = cos (rotation) * 75;+		hy = sin (rotation) * 75;++		cr.set_line_width (1);+		cr.move_to (cx, cy);+		cr.line_to (cx + hx, cy + hy);+		cr.stroke ();++		cr.set_source_rgba (0, 0, 0.3, 1);+		cr.rectangle (cx + hx - 2.5, cy + hy - 2.5, 5, 5);+		cr.fill ();+					+		cr.restore ();				+	}+	+	void get_rotation_box_boundries (out double x, out double y, out double w, out double h) {+		double px, py, px2, py2;+		Glyph glyph = MainWindow.get_current_glyph ();+		+		px = 10000;+		py = 10000;+		px2 = -10000;+		py2 = -10000;+		+		foreach (Path p in glyph.active_paths) {+			if (px > p.xmin) {+				px = p.xmin;+			} ++			if (py > p.ymin) {+				py = p.ymin;+			}++			if (px2 < p.xmax) {+				px2 = p.xmax;+			}+			+			if (py2 < p.ymax) {+				py2 = p.ymax;+			}+		}+		+		w = px2 - px;+		h = py2 - py;+		x = px + (w / 2);+		y = py + (h / 2);+	}+	 	void move_selected_paths (uint key) { 		Glyph glyph = MainWindow.get_current_glyph (); 		double x, y;@@ -289,7 +391,61 @@ class MoveTool : Tool { 			p.move (sx - p.xmax, 0); 		}		 	}+	+	/** Move rotate handle to pixel x,y. */+	void rotate (double x, double y) {+		double cx, cy, xc, yc, xc2, yc2, a, b, w, h;		+		Glyph glyph = MainWindow.get_current_glyph ();  ++		cx = Glyph.reverse_path_coordinate_x (rotation_box_center_x);+		cy = Glyph.reverse_path_coordinate_y (rotation_box_center_y);+		xc = rotation_box_center_x;+		yc = rotation_box_center_y;+		+		a = x - cx;+		b = y - cy;+		+		rotation = atan (b / a);+		+		if (a < 0) {+			rotation += PI;+		}+		+		foreach (Path p in glyph.active_paths) {+			p.rotate (rotation - last_rotate, rotation_box_center_x, rotation_box_center_y);+		}++		get_rotation_box_boundries (out xc2, out yc2, out w, out h); +	+		double dx, dy;+		+		dx = -(xc2 - xc);+		dy = -(yc2 - yc);+		foreach (Path p in glyph.active_paths) {+			p.move (dx, dy);+		}+		+		last_rotate = rotation;+		+		update_selection_boundries ();+	}++	bool is_over_rotate_handle (Path p, double x, double y) {+		double cx, cy, hx, hy;+		double size = 10;+		bool inx, iny;+		+		cx = Glyph.reverse_path_coordinate_x (rotation_box_center_x);+		cy = Glyph.reverse_path_coordinate_y (rotation_box_center_y);++		hx = cos (rotation) * 75;+		hy = sin (rotation) * 75; +		inx = x - size <= cx + hx - 2.5 <= x + size;+		iny = y - size <= cy + hy - 2.5 <= y + size;+		+		return inx && iny;+	} }  }diff --git a/libbirdfont/OpenFontFormat/HheaTable.vala b/libbirdfont/OpenFontFormat/HheaTable.valaindex 45d8e68..c180f5f 100644--- a/libbirdfont/OpenFontFormat/HheaTable.vala+++ b/libbirdfont/OpenFontFormat/HheaTable.vala@@ -82,7 +82,6 @@ class HheaTable : Table { 	 	public void process () throws GLib.Error { 		int16 ascender, descender;-		Font font = OpenFontFormatWriter.get_current_font (); 		FontData fd = new FontData (); 		Fixed version = 1 << 16; 		diff --git a/libbirdfont/OpenFontFormat/Os2Table.vala b/libbirdfont/OpenFontFormat/Os2Table.valaindex 88f6217..92c630a 100644--- a/libbirdfont/OpenFontFormat/Os2Table.vala+++ b/libbirdfont/OpenFontFormat/Os2Table.vala@@ -26,8 +26,7 @@ class Os2Table : Table { 	 	public void process (GlyfTable glyf_table) { 		FontData fd = new FontData ();-		Font font = OpenFontFormatWriter.get_current_font ();-		+ 		int16 ascender; 		int16 descender; 		diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex d10563f..367ebc6 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -2003,6 +2003,25 @@ public class Path { 		 		close (); 	}++	/** Roatate around coordinate xc, xc. */+	public void rotate (double theta, double xc, double yc) {+		double a, radius;+		+		foreach (EditPoint ep in points) {+			radius = Math.sqrt (Math.pow (xc - ep.x, 2) + Math.pow (yc + ep.y, 2));+			a = acos ((ep.x - xc) / radius);+			+			ep.x = xc + cos (a - theta) * radius;+			ep.y = yc + sin (a - theta) * radius;+			+			ep.get_right_handle ().angle -= theta;+			ep.get_left_handle ().angle -= theta;+		}++		update_region_boundries ();+	}+	 }  }

Contact

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