Clone in a terminal:
Commit d3ee36a
Johan Mattsson - 2013-08-04T18:53:47+00:00
d3ee36a93b2456ef61d24cf99d4ebc23bf8999e7johan.mattsson.m@gmail.com

flip paths

Changed files (5)

Diff

diff --git a/icons/flip_horizontal.png b/icons/flip_horizontal.pngnew file mode 100644index 0000000..f725b2dBinary files /dev/null and b/icons/flip_horizontal.png differdiff --git a/icons/flip_vertical.png b/icons/flip_vertical.pngnew file mode 100644index 0000000..757f95bBinary files /dev/null and b/icons/flip_vertical.png differdiff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex 21e4d99..ea6027d 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -29,10 +29,10 @@ class MoveTool : Tool {  	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;+	static double selection_box_width = 0;+	static double selection_box_height = 0;+	static double selection_box_center_x = 0;+	static double selection_box_center_y = 0; 	double rotation = 0; 	double last_rotate = 0; 	@@ -132,9 +132,9 @@ class MoveTool : Tool { 			}  			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);	+				get_selection_box_boundries (out selection_box_center_x,+					out selection_box_center_y, out selection_box_width,+					out selection_box_height);	 			}  			last_x = x;@@ -178,17 +178,17 @@ class MoveTool : Tool { 		}); 	} -	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);	+	static void update_selection_boundries () {+		get_selection_box_boundries (out selection_box_center_x,+			out selection_box_center_y, out selection_box_width,+			out selection_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);+		cx = Glyph.reverse_path_coordinate_x (selection_box_center_x);+		cy = Glyph.reverse_path_coordinate_y (selection_box_center_y); 		 		cr.save (); 		@@ -211,7 +211,7 @@ class MoveTool : Tool { 		cr.restore ();				 	} 	-	void get_rotation_box_boundries (out double x, out double y, out double w, out double h) {+	static void get_selection_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 (); 		@@ -396,11 +396,12 @@ class MoveTool : Tool { 	void rotate (double x, double y) { 		double cx, cy, xc, yc, xc2, yc2, a, b, w, h;		 		Glyph glyph = MainWindow.get_current_glyph ();  +		double dx, dy; -		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;+		cx = Glyph.reverse_path_coordinate_x (selection_box_center_x);+		cy = Glyph.reverse_path_coordinate_y (selection_box_center_y);+		xc = selection_box_center_x;+		yc = selection_box_center_y; 		 		a = x - cx; 		b = y - cy;@@ -412,15 +413,14 @@ class MoveTool : Tool { 		} 		 		foreach (Path p in glyph.active_paths) {-			p.rotate (rotation - last_rotate, rotation_box_center_x, rotation_box_center_y);+			p.rotate (rotation - last_rotate, selection_box_center_x, selection_box_center_y); 		} -		get_rotation_box_boundries (out xc2, out yc2, out w, out h); -	-		double dx, dy;-		+		get_selection_box_boundries (out xc2, out yc2, out w, out h); + 		dx = -(xc2 - xc); 		dy = -(yc2 - yc);+		 		foreach (Path p in glyph.active_paths) { 			p.move (dx, dy); 		}@@ -435,8 +435,8 @@ class MoveTool : Tool { 		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);+		cx = Glyph.reverse_path_coordinate_x (selection_box_center_x);+		cy = Glyph.reverse_path_coordinate_y (selection_box_center_y);  		hx = cos (rotation) * 75; 		hy = sin (rotation) * 75;@@ -446,6 +446,43 @@ class MoveTool : Tool { 		 		return inx && iny; 	}+++	public static void flip_vertical () {+		flip (true);+	}+	+	public static void flip_horizontal () {+		flip (false);+	}++	public static void flip (bool vertical) {+		double xc, yc, xc2, yc2, w, h;		+		double dx, dy;+		Glyph glyph = MainWindow.get_current_glyph ();  ++		xc = selection_box_center_x;+		yc = selection_box_center_y;++		foreach (Path p in glyph.active_paths) {+			if (vertical) {+				p.flip_vertical ();+			} else {+				p.flip_horizontal ();+			}+		}++		get_selection_box_boundries (out xc2, out yc2, out w, out h); ++		dx = -(xc2 - xc);+		dy = -(yc2 - yc);+		+		foreach (Path p in glyph.active_paths) {+			p.move (dx, dy);+		}+		+		update_selection_boundries ();	+	} }  }diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 367ebc6..09133fe 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -2022,6 +2022,47 @@ public class Path { 		update_region_boundries (); 	} 	+	public void flip_vertical () {+		EditPointHandle hl, hr;+		double lx, ly, rx, ry;+		foreach (EditPoint e in points) {+			hl = e.get_left_handle ();+			hr = e.get_right_handle ();+			+			lx = hl.x ();+			ly = hl.y ();+			rx = hr.x ();+			ry = hr.y ();+						+			e.y *= -1;+			+			hr.move_to_coordinate_internal (rx, -1 * ry);+			hl.move_to_coordinate_internal (lx, -1 * ly);+		}+		+		update_region_boundries ();+	}++	public void flip_horizontal () {+		EditPointHandle hl, hr;+		double lx, ly, rx, ry;+		foreach (EditPoint e in points) {+			hl = e.get_left_handle ();+			hr = e.get_right_handle ();+			+			lx = hl.x ();+			ly = hl.y ();+			rx = hr.x ();+			ry = hr.y ();+						+			e.x *= -1;+			+			hr.move_to_coordinate_internal (-1 * rx, ry);+			hl.move_to_coordinate_internal (-1 * lx, ly);+		}+		+		update_region_boundries ();+	} }  }diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 0e753b4..89dc4a5 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -183,6 +183,20 @@ public class Toolbox : GLib.Object  { 		}); 		path_tool_modifiers.add_tool (move_layer); +		Tool flip_vertical = new Tool ("flip_vertical", _("Flip path vertically"));+		flip_vertical.select_action.connect ((self) => {+			MoveTool.flip_vertical ();+			MainWindow.get_current_glyph ().update_view ();+		});+		path_tool_modifiers.add_tool (flip_vertical);++		Tool flip_horizontal = new Tool ("flip_horizontal", _("Flip path horizontally"));+		flip_horizontal.select_action.connect ((self) => {+			MoveTool.flip_horizontal ();+			MainWindow.get_current_glyph ().update_view ();+		});+		path_tool_modifiers.add_tool (flip_horizontal);+		 		// adjust precision 		string precision_value = Preferences.get ("precision"); 		

Contact

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