Clone in a terminal:
Commit f03ba9a
Johan Mattsson - 2015-05-07T06:57:19+00:00
f03ba9a440358156b6927baf8d061856736fc56fjohan.mattsson.m@gmail.com

Line mode Beziér tool

Changed files (7)

Diff

diff --git a/libbirdfont/BezierTool.vala b/libbirdfont/BezierTool.valaindex 5a6c2d3..2d9fbfd 100644--- a/libbirdfont/BezierTool.vala+++ b/libbirdfont/BezierTool.vala@@ -27,6 +27,7 @@ public class BezierTool : Tool { 	public const uint MOVE_FIRST_HANDLE = 4; 	 	uint state = NONE;+ 	bool move_right_handle = true; 	int previous_point = 0; 	@@ -37,6 +38,7 @@ public class BezierTool : Tool { 	int last_y = 0;  	double last_release_time = 0;+	double last_press_time = 0; 	 	public BezierTool (string name) { 		base (name, t_ ("Create Beziér curves"));@@ -87,6 +89,7 @@ public class BezierTool : Tool {  		if (b == 2) { 			if (g.is_open ()) {+				stop_drawing (); 				g.close_path (); 			} else { 				g.open_path ();@@ -97,6 +100,15 @@ public class BezierTool : Tool {  			return; 		}++		// ignore double clicks+		if ((GLib.get_real_time () - last_press_time) / 1000000.0 < 0.2) {+			last_press_time = GLib.get_real_time ();+			return;+		}+		last_press_time = GLib.get_real_time ();+				+		g.store_undo_state (); 		 		PenTool.update_orientation (); 		@@ -115,6 +127,11 @@ public class BezierTool : Tool { 			current_point.get_left_handle ().convert_to_line (); 			current_point.recalculate_linear_handles (); 			g.add_path (current_path);+			+			if (StrokeTool.add_stroke) {+				current_path.stroke = StrokeTool.stroke_width;+			}+			 			GlyphCanvas.redraw (); 			state = MOVE_POINT; 		} else if (state == MOVE_POINT) {@@ -192,12 +209,14 @@ public class BezierTool : Tool { 			current_point.y = py; 			current_path.hide_end_handle = true; 			current_point.recalculate_linear_handles ();+			current_path.reset_stroke (); 			GlyphCanvas.redraw (); 		} else if (state == MOVE_HANDLES || state == MOVE_LAST_HANDLE) { 			current_path.hide_end_handle = false; 			current_point.set_reflective_handles (true); 			current_point.convert_to_curve (); 			current_point.get_right_handle ().move_to_coordinate (px, py);+			current_path.reset_stroke (); 			GlyphCanvas.redraw (); 		} 		@@ -209,20 +228,39 @@ public class BezierTool : Tool { 	 	public void switch_to_line_mode () { 		int s = current_path.points.size;+		EditPoint p;+		 		if (s > 2) {-			current_path.points.get (s - 2).get_right_handle ().convert_to_line ();+			p = current_path.points.get (s - 2);+			p.get_right_handle ().convert_to_line (); 			current_point.get_left_handle ().convert_to_line ();+			p.recalculate_linear_handles ();+			current_point.recalculate_linear_handles ();+			current_path.reset_stroke ();+			GlyphCanvas.redraw ();+			+			state = MOVE_POINT; 		} 	} 	 	public void stop_drawing () { 		if (state == MOVE_POINT && current_path.points.size > 0) { 			current_path.delete_last_point ();+			current_path.reset_stroke (); 		} 		 		state = NONE; 	}-	++	public override void before_undo () {+	}++	public override void after_undo () {+		if (state != NONE) {+			MainWindow.set_cursor (NativeWindow.VISIBLE);+			state = NONE;+		}+	} }  }diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 0746422..a986cf7 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -126,15 +126,7 @@ public class DrawingTools : ToolCollection  { 			update_drawing_and_background_tools (self); 		}); 		draw_tools.add_tool (bezier_tool);--		Tool bezier_line = new Tool ("bezier_line", t_("Convert the last segment to a straight line"));-		bezier_line.select_action.connect ((self) => {-			bezier_tool.switch_to_line_mode ();-		});-		bezier_line.is_tool_modifier = true;-		draw_tools.add_tool (bezier_line);-		bezier_line.set_tool_visibility (false);	-			+		 		pen_tool = new PenTool ("pen_tool"); 		pen_tool.select_action.connect ((self) => { 			update_drawing_and_background_tools (self);diff --git a/libbirdfont/HiddenTools.vala b/libbirdfont/HiddenTools.valaindex bbdbaba..7d9eded 100644--- a/libbirdfont/HiddenTools.vala+++ b/libbirdfont/HiddenTools.vala@@ -38,7 +38,15 @@ public class HiddenTools : ToolCollection  { 			GlyphCanvas.current_display.zoom_out (); 		}); 		hidden_expander.add_tool (zoom_out);-		++		Tool bezier_line = new Tool ("bezier_line", t_("Convert the last segment to a straight line"));+		bezier_line.select_action.connect ((self) => {+			DrawingTools.bezier_tool.switch_to_line_mode ();+		});+		bezier_line.is_tool_modifier = true;+		hidden_expander.add_tool (bezier_line);+		bezier_line.set_tool_visibility (false);+				 		expanders.add (hidden_expander); 	} diff --git a/libbirdfont/MainWindow.vala b/libbirdfont/MainWindow.valaindex 69ca86a..66d8197 100644--- a/libbirdfont/MainWindow.vala+++ b/libbirdfont/MainWindow.vala@@ -80,10 +80,12 @@ public class MainWindow : GLib.Object { 	}
 
 	public static void set_cursor (int flags) {
-		if (dialog.visible) {
-			native_window.set_cursor (NativeWindow.VISIBLE);
-		} else {
-			native_window.set_cursor (flags);
+		if (BirdFont.has_argument ("--test")) {
+			if (dialog.visible) {
+				native_window.set_cursor (NativeWindow.VISIBLE);
+			} else {
+				native_window.set_cursor (flags);
+			}
 		}
 	}
 
diff --git a/libbirdfont/StrokeTool.vala b/libbirdfont/StrokeTool.valaindex 4261fb3..1eb5200 100644--- a/libbirdfont/StrokeTool.vala+++ b/libbirdfont/StrokeTool.vala@@ -93,15 +93,18 @@ public class StrokeTool : Tool { 		 		stroke = path.copy (); 		stroke.remove_points_on_points (0.3);-		o = create_stroke (stroke, thickness);+		o = create_stroke (stroke, thickness, true); 				 		return o; 	} 	 	public static PathList get_stroke (Path path, double thickness) { 		PathList o, m;+		Path stroke; 		-		o = get_stroke_fast (path, thickness);+		stroke = path.copy ();+		stroke.remove_points_on_points (0.3);+		o = create_stroke (stroke, thickness, false); 		o = get_all_parts (o); 		o = merge (o); 		@@ -121,6 +124,9 @@ public class StrokeTool : Tool { 		int j; 		EditPointHandle rh; 		+		segment_last = new EditPoint ();+		last = new EditPoint ();+		 		foreach (EditPoint e in p.points) { 			PenTool.convert_point_type (e, PointType.CUBIC); 		}@@ -167,10 +173,13 @@ public class StrokeTool : Tool { 				}  				added_segment = segment.copy ();	+				+				if (simplified.points.size > 0) {+					last = simplified.get_last_point ();+					segment_last = added_segment.get_last_point ();+				} -				last = simplified.get_last_point (); 				first = added_segment.get_first_point ();-				segment_last = added_segment.get_last_point (); 				 				segment_last.get_right_handle ().convert_to_line (); 				@@ -207,26 +216,20 @@ public class StrokeTool : Tool { 		simplified.recalculate_linear_handles (); 		simplified.close (); 		+		/* 		if (p.get_first_point ().tie_handles) { 			first = simplified.get_first_point (); 			first.convert_to_curve (); 			first.tie_handles = true; 			first.process_tied_handle (); 		}+		*/ -		print (p.get_last_point ().to_string ());--		if (p.get_last_point ().tie_handles) {-			last = simplified.get_last_point ();-			last.convert_to_curve ();-			last.tie_handles = true;-			last.process_tied_handle ();-		} else {-			rh = simplified.get_last_point ().get_right_handle ();-			rh.convert_to_line ();-			rh.parent.recalculate_linear_handles ();-		}+		//simplified.remove_points_on_points (); +		simplified.get_last_point ().color = Color.pink ();+		simplified.get_first_point ().color = Color.green ();+		 		return simplified; 	} 	@@ -752,15 +755,14 @@ public class StrokeTool : Tool { 		EditPoint ep1 = new EditPoint (); 		EditPoint ep2 = new EditPoint (); 		EditPoint ep3 = new EditPoint ();+		double d; 		 		if (next == path.get_first_point ()) { 			ep1.prev = null; 		} else { 			ep1.prev = prev; 		}-		-		prev.get_right_handle ().convert_to_line ();-		+				 		ep1.prev = prev; 		ep1.next = ep2; 		ep1.flags |= EditPoint.NEW_CORNER;@@ -803,7 +805,13 @@ public class StrokeTool : Tool { 		ep2.recalculate_linear_handles (); 		ep3.recalculate_linear_handles (); 		-		prev.recalculate_linear_handles ();+		d =  Path.distance_to_point (prev, next);+		prev.get_right_handle ().length *= Path.distance_to_point (prev, ep1) / d;+		next.get_left_handle ().length *= Path.distance_to_point (ep3, next) / d;+		+		prev.color = Color.green ();+		next.color = Color.blue ();+		 		next.recalculate_linear_handles (); 		 		return ep2;@@ -1833,7 +1841,9 @@ public class StrokeTool : Tool { 		return sum > 0; 	}	 -	public static PathList create_stroke (Path original_path, double thickness) {+	public static PathList create_stroke (Path original_path,+		double thickness, bool fast) {+			 		PathList pl; 		EditPoint p1, p2, p3; 		EditPoint previous, previous_inside, start, start_inside;@@ -1850,6 +1860,7 @@ public class StrokeTool : Tool { 		double step_size; 		EditPoint corner1, corner1_inside; 		double step;+		double min_increment; 		 		EditPointHandle l, r; @@ -1890,6 +1901,8 @@ public class StrokeTool : Tool { 			side2.add_point (previous_inside); 		} +		min_increment = 0.013;+		 		for (i = 0; i < size; i++) { 			p1 = path.points.get (i % path.points.size); 			p2 = path.points.get ((i + 1) % path.points.size);@@ -1908,7 +1921,7 @@ public class StrokeTool : Tool { 			 			step = 0; 			keep = 0;-			step_size = 0.013;+			step_size = 0.1;  			while (step < 1 - 2 * step_size) { 				Path.get_point_for_step (p1, p2, step, out x, out y);@@ -1929,12 +1942,12 @@ public class StrokeTool : Tool { 				 				f_bigger = is_flat (x, y, x2, y2, x3, y3, tolerance); 				-				if (!flat && !f_next && step_size > 0.013) {+				if (!flat && !f_next && step_size > min_increment) { 					step_size /= step_increment; 					continue; 				} 								-				if (flat && f_bigger && step_size < 0.1) {+				if (flat && f_bigger && step_size < 0.25) { 					step_size *= step_increment; 					continue; 				}@@ -2008,17 +2021,29 @@ public class StrokeTool : Tool { 					add_corner (side2, previous_inside, start, p2.copy (), thickness); 				} 			}+				+			if (fast) {+				convert_to_curve (side1);+				convert_to_curve (side2);+			+				side2.reverse ();+				pl.append (merge_stroke_parts (path, side1, side2));+				+				side1 = new Path ();+				side2 = new Path ();+			} 		} 		-		side1.remove_points_on_points ();-		side2.remove_points_on_points ();-		-		convert_to_curve (side1);-		convert_to_curve (side2);-		-		side2.reverse ();+		if (!fast) {+			side1.remove_points_on_points ();+			side2.remove_points_on_points ();+				+			convert_to_curve (side1);+			convert_to_curve (side2); 		-		pl = merge_stroke_parts (path, side1, side2);+			side2.reverse ();+			pl = merge_stroke_parts (path, side1, side2);+		} 		 		return pl; 	}diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 427b58d..18a4e93 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -332,6 +332,7 @@ public class Toolbox : GLib.Object  {  	public void set_current_tool (Tool tool) { 		if (tool.editor_events) {+			print (@"NEW PROP $(tool.get_name ())\n"); 			current_tool = tool; 		} 	}diff --git a/libbirdgems/fit_cubic.c b/libbirdgems/fit_cubic.cindex 05bfc58..b24921b 100644--- a/libbirdgems/fit_cubic.c+++ b/libbirdgems/fit_cubic.c@@ -89,9 +89,6 @@ void fit_bezier_curve_to_line ( 	} 	 	npoints = lines_size / 2;-	-	printf ("npoints: %d alloc: %d\n", npoints, npoints * sizeof (Point2));-	 	points = malloc (npoints * sizeof (Point2));  	j = 0;@@ -101,7 +98,6 @@ void fit_bezier_curve_to_line ( 		j += 2; 	} 	-	printf ("simplified_path\n"); 	simplified_path = malloc (8 * npoints * sizeof (double)); 	simplified_path_buffer_size = 8 * npoints; 	simplified_path_size = 0;

Contact

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