The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix last handle in stroke simplification

These changes was commited to the Birdfont repository Sat, 03 Oct 2015 18:48:45 +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>
Sat, 03 Oct 2015 18:48:45 +0000 (20:48 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 03 Oct 2015 18:48:45 +0000 (20:48 +0200)
commit abe1885c7fe2881e56761f5703859e97139514cf
tree 72c9aa04eceecf554012d8baade26d6b9b6fbfe4
parent be6895b90436553edc751fae36699b0065c2d56f
Fix last handle in stroke simplification

libbirdfont/OverviewTools.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/OverviewTools.vala +++ b/libbirdfont/OverviewTools.vala @@ -128,9 +128,11 @@ transform.set_persistent (false); transform_expander.add_tool (transform); - Tool alternate = new Tool ("alternate", t_("Create alternate")); - alternate.select_action.connect (add_new_alternate); - glyph_expander.add_tool (alternate); + if (BirdFont.has_argument ("--test")) { + Tool alternate = new Tool ("alternate", t_("Create alternate")); + alternate.select_action.connect (add_new_alternate); + glyph_expander.add_tool (alternate); + } expanders.add (font_name); expanders.add (zoom_expander);
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -133,22 +133,7 @@ foreach (Path p in o.paths) { p.close (); - p.remove_points_on_points (); - - // fix paths with intersections around a single points - PointSelection ps; - for (int i = 0; i < p.points.size; i++) { - EditPoint ep = p.points.get (i); - if (fabs (ep.get_right_handle ().angle - ep.get_left_handle ().angle) < 0.001) { - ps = new PointSelection (ep, p); - PenTool.remove_point_simplify (ps); - i--; - } else if (ep.next != null && Path.distance_to_point (ep, ep.get_next ()) < 0.1) { - ps = new PointSelection (ep, p); - PenTool.remove_point_simplify (ps); - i--; - } - } + remove_single_point_intersections (p); } o = remove_overlap (o, out error); @@ -230,6 +215,25 @@ GlyphCanvas.redraw (); } + static void remove_single_point_intersections (Path p) { + PointSelection ps; + + p.remove_points_on_points (0.1); + + for (int i = 0; i < p.points.size; i++) { + EditPoint ep = p.points.get (i); + if (fabs (ep.get_right_handle ().angle - ep.get_left_handle ().angle) < 0.001) { + ps = new PointSelection (ep, p); + PenTool.remove_point_simplify (ps); + i--; + } else if (ep.next != null && Path.distance_to_point (ep, ep.get_next ()) < 0.01) { + ps = new PointSelection (ep, p); + PenTool.remove_point_simplify (ps); + i--; + } + } + } + static PathList remove_overlap (PathList pl, out bool error) { PathList r = new PathList (); @@ -929,9 +933,14 @@ EditPoint ep, ep_start, last, first, segment_last; int start, stop; int j; + EditPointHandle last_handle; + + last_handle = new EditPointHandle.empty (); segment_last = new EditPoint (); last = new EditPoint (); + + p.remove_points_on_points (); foreach (EditPoint e in p.points) { PenTool.convert_point_type (e, PointType.CUBIC); @@ -987,7 +996,7 @@ segment_last.right_handle = ep_start.get_right_handle ().copy (); if (simplified.points.size > 1) { - simplified.delete_last_point (); + last = simplified.delete_last_point (); } first.set_tie_handle (false); @@ -1014,6 +1023,8 @@ first.recalculate_linear_handles (); } } + + last_handle = last.get_left_handle (); } else { warning ("No points in segment."); } @@ -1026,8 +1037,12 @@ simplified.recalculate_linear_handles (); simplified.close (); + remove_single_point_intersections (simplified); - simplified.remove_points_on_points (0.01); + first = simplified.get_first_point (); + first.left_handle.angle = last_handle.angle; + first.left_handle.length = last_handle.length; + first.recalculate_linear_handles (); return simplified; }