The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Line mode Beziér tool

These changes was commited to the Birdfont repository Thu, 07 May 2015 06:57:19 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 07 May 2015 06:57:19 +0000 (08:57 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 07 May 2015 06:57:19 +0000 (08:57 +0200)
commit f03ba9a440358156b6927baf8d061856736fc56f
tree 17b0e8f65952dc3916bdeea751afe504ee2ec15a
parent 6950425706d2078ea41519dfb8c11d8f0ef59691
Line mode Beziér tool

libbirdfont/BezierTool.vala
libbirdfont/DrawingTools.vala
libbirdfont/HiddenTools.vala
libbirdfont/MainWindow.vala
libbirdfont/StrokeTool.vala
libbirdfont/Toolbox.vala
libbirdgems/fit_cubic.c
--- a/libbirdfont/BezierTool.vala +++ b/libbirdfont/BezierTool.vala @@ -27,6 +27,7 @@ public const uint MOVE_FIRST_HANDLE = 4; uint state = NONE; + bool move_right_handle = true; int previous_point = 0; @@ -37,6 +38,7 @@ 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 @@ if (b == 2) { if (g.is_open ()) { + stop_drawing (); g.close_path (); } else { g.open_path (); @@ -97,6 +100,15 @@ 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 @@ 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 @@ 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,21 +228,40 @@ 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; + } + } } }
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -126,15 +126,7 @@ 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);
--- a/libbirdfont/HiddenTools.vala +++ b/libbirdfont/HiddenTools.vala @@ -38,7 +38,15 @@ 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); }
--- a/libbirdfont/MainWindow.vala +++ b/libbirdfont/MainWindow.vala @@ -80,10 +80,12 @@ } 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); + } } }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -93,15 +93,18 @@ 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); @@ -120,6 +123,9 @@ int start, stop; 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ double step_size; EditPoint corner1, corner1_inside; double step; + double min_increment; EditPointHandle l, r; @@ -1890,6 +1901,8 @@ 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 @@ 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 @@ 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; } @@ -2007,18 +2020,30 @@ get_segment (-thickness, 0, 0.00001, p2, p3, out start); 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 (); + if (!fast) { + side1.remove_points_on_points (); + side2.remove_points_on_points (); + + convert_to_curve (side1); + convert_to_curve (side2); - convert_to_curve (side1); - convert_to_curve (side2); - - side2.reverse (); - - pl = merge_stroke_parts (path, side1, side2); + side2.reverse (); + pl = merge_stroke_parts (path, side1, side2); + } return pl; }
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -332,6 +332,7 @@ public void set_current_tool (Tool tool) { if (tool.editor_events) { + print (@"NEW PROP $(tool.get_name ())\n"); current_tool = tool; } }
--- a/libbirdgems/fit_cubic.c +++ b/libbirdgems/fit_cubic.c @@ -89,9 +89,6 @@ } 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 @@ j += 2; } - printf ("simplified_path\n"); simplified_path = malloc (8 * npoints * sizeof (double)); simplified_path_buffer_size = 8 * npoints; simplified_path_size = 0;