The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Merge ../birdfont-2.x

These changes was commited to the Birdfont repository Thu, 02 Jun 2016 19:15:48 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Thu, 02 Jun 2016 19:15:48 +0000]

Updated Files

configure
libbirdfont/EditPointHandle.vala
libbirdfont/StrokeTool.vala
libbirdfont/TrackTool.vala
--- a/configure +++ b/configure @@ -87,10 +87,10 @@ print (OKGREEN + 'Using posix profile.' + ENDC) return 'True' - def configure(gtk, libbgee): + def configure(gtk, libbgee, valac): global gee - if not test_program_version ('valac', 0, 16, 0): + if not test_program_version(valac, 0, 16, 0): print (FAIL + 'valac is too old.' + ENDC) exit (1) @@ -203,7 +203,7 @@ else: options.nonnull = True - configure(options.gtk, options.gee) + configure(options.gtk, options.gee, options.valac) configfile.write_config(options.prefix) configfile.write_compile_parameters(options.prefix,
--- a/libbirdfont/EditPointHandle.vala +++ b/libbirdfont/EditPointHandle.vala @@ -49,7 +49,9 @@ if (parent.reflective_point) { parent.process_symmetrical_handles (); - } + } + + process_connected_handle (); } } @@ -75,6 +77,8 @@ if (parent.reflective_point) { parent.process_symmetrical_handles (); } + + process_connected_handle (); } } @@ -289,16 +293,18 @@ if (!is_left_handle ()) { if (parent.next != null) { h = parent.get_next ().get_left_handle (); + h.parent.set_reflective_handles (false); h.parent.set_tie_handle (false); h.type = PointType.QUADRATIC; - h.move_to_coordinate_internal (px (), py ()); + h.move_to_coordinate_internal (x, y); } } else { if (parent.prev != null) { h = parent.get_prev ().get_right_handle (); + h.parent.set_reflective_handles (false); h.parent.set_tie_handle (false); h.type = PointType.QUADRATIC; - h.move_to_coordinate_internal (px (), py ()); + h.move_to_coordinate_internal (x, y); } } }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -1076,7 +1076,7 @@ return simplified; } - Path fit_bezier_path (Path p, int start, int stop, double error) { + public static Path fit_bezier_path (Path p, int start, int stop, double error) { int index, size; Path simplified; double[] lines;
--- a/libbirdfont/TrackTool.vala +++ b/libbirdfont/TrackTool.vala @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 2015 Johan Mattsson + Copyright (C) 2014 2015 2016 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -97,16 +97,20 @@ if (join_paths) { ps = get_path_with_end_point (x, y); + if (unlikely (ps == null)) { warning ("No end point."); return; } + end_point = (!) ps; + if (end_point.is_first ()) { end_point.path.reverse (); } + + Path path = end_point.path; glyph.set_active_path (end_point.path); - add_corner (x, y); } else { p = new Path (); glyph.add_path (p); @@ -154,11 +158,11 @@ if (p.points.size > 1) { previous = p.points.get (p.points.size - 1); - previous.type = DrawingTools.point_type; + previous.type = PointType.CUBIC; previous.set_tie_handle (false); previous = p.points.get (0); - previous.type = DrawingTools.point_type; + previous.type = PointType.CUBIC; previous.set_tie_handle (false); } } @@ -167,10 +171,11 @@ return_if_fail (drawing); add_endpoint_and_merge (x, y); } - + foreach (Object path in g.active_paths) { if (path is PathObject) { convert_hidden_points (((PathObject) path).get_path ()); + path.update_region_boundaries (); } } @@ -227,8 +232,8 @@ foreach (EditPoint e in p.points) { if (e.type == PointType.HIDDEN) { e.type = DrawingTools.point_type; - e.get_right_handle ().type = DrawingTools.point_type; - e.get_left_handle ().type = DrawingTools.point_type; + e.get_right_handle ().type = PointType.CUBIC; + e.get_left_handle ().type = PointType.CUBIC; } } } @@ -302,17 +307,16 @@ warning ("No point."); return; } + + EditPoint last_point = p.get_last_point (); + EditPointHandle handle = last_point.get_right_handle (); + handle.convert_to_line (); + p.recalculate_linear_handles (); + + PenTool.convert_point_type (p.get_last_point (), PointType.CUBIC); + PenTool.convert_point_type (p.get_first_point (), PointType.CUBIC); p.create_list (); - - if (DrawingTools.get_selected_point_type () == PointType.QUADRATIC) { - foreach (EditPoint e in p.points) { - if (e.tie_handles) { - e.convert_to_curve (); - e.process_tied_handle (); - } - } - } if (PenTool.is_counter_path (p)) { p.force_direction (Direction.COUNTER_CLOCKWISE); @@ -345,10 +349,8 @@ merged.append_path (b.path); - g = MainWindow.get_current_glyph (); - + g = MainWindow.get_current_glyph (); g.add_path (merged); - a.delete_last_point (); update_corner_handle (a.get_last_point (), b.path.get_first_point ()); @@ -360,7 +362,7 @@ merged.update_region_boundaries (); merged.recalculate_linear_handles (); merged.reopen (); - + return merged; } @@ -423,14 +425,26 @@ p = ((PathObject) o).get_path (); p.reopen (); + + EditPoint last_point = new EditPoint (); + + if (p.points.size > 0) { + last_point = p.get_last_point (); + } + px = Glyph.path_coordinate_x (x); py = Glyph.path_coordinate_y (y); - new_point = p.add (px, py); + + new_point = new EditPoint (px, py, PointType.CUBIC); + p.add_point (new_point); added_points++; PenTool.convert_point_to_line (new_point, false); - new_point.set_point_type (PointType.HIDDEN); + + new_point.set_point_type (PointType.HIDDEN); p.recalculate_linear_handles_for_point (new_point); + + last_point.get_right_handle ().length = 0.000001; if (p.points.size > 1) { glyph.redraw_segment (new_point, new_point.get_prev ()); @@ -472,29 +486,28 @@ update_cycles = 0; } - if (update_cycles > 4) { // cycles of 100 ms + if (update_cycles > 0.7 * 10) { // delay in time convert_points_to_line (); - last_update = get_current_time (); + last_update = get_current_time (); add_corner (last_x, last_y); added_points = 0; update_cycles = 0; } - if (added_points > 25 / samples_per_point) { - last_update = get_current_time (); + if (added_points > 80 / samples_per_point) { + last_update = get_current_time (); convert_points_to_line (); } } /** Add a sharp corner instead of a smooth curve. */ - void add_corner (int px, int py) { - PointSelection p; - delete_last_points_at (px, py); - p = PenTool.add_new_edit_point (px, py); - p.point.set_tie_handle (false); - p.point.get_left_handle ().convert_to_line (); - p.point.get_right_handle ().convert_to_line (); - p.path.recalculate_linear_handles_for_point (p.point); + void add_corner (double px, double py) { + EditPoint p; + p = new EditPoint (px, py, PointType.CUBIC); + p.set_tie_handle (false); + p.get_left_handle ().convert_to_line (); + p.get_right_handle ().convert_to_line (); + get_active_path ().recalculate_linear_handles_for_point (p); last_update = get_current_time (); MainWindow.get_current_glyph ().update_view (); } @@ -519,8 +532,7 @@ } /** Delete all points close to the pixel at x,y. */ - void delete_last_points_at (int x, int y) { - double px, py; + void delete_last_points_at (double px, double py) { Path p; p = get_active_path (); @@ -529,9 +541,6 @@ warning ("Missing point."); return; } - - px = Glyph.path_coordinate_x (x); - py = Glyph.path_coordinate_y (y); while (p.points.size > 0 && is_close (p.points.get (p.points.size - 1), px, py)) { p.delete_last_point (); @@ -579,42 +588,22 @@ sum_x = 0; sum_y = 0; - last_point = p.points.get (p.points.size - 1); + int start = p.points.size - 1 - added_points; + int stop = p.points.size - 1; + + EditPoint end = p.points.get (stop); + + Path segment = StrokeTool.fit_bezier_path (p, start, stop, 5.0 / samples_per_point); for (int i = 0; i < added_points; i++) { - ep = p.delete_last_point (); - sum_x += ep.x; - sum_y += ep.y; - points.add (ep); - } + p.delete_last_point (); + } - nx = sum_x / added_points; - ny = sum_y / added_points; - - px = Glyph.reverse_path_coordinate_x (nx); - py = Glyph.reverse_path_coordinate_y (ny); - average = PenTool.add_new_edit_point (px, py).point; - average.type = PointType.HIDDEN; + p.append_path (segment); + p.remove_points_on_points (); - // tie handles for all points except for the end points - average.set_tie_handle (p.points.size > 1); + add_corner (end.x, end.y); - if (unlikely (p.points.size == 0)) { - warning ("No points."); - return; - } - - if (average.prev != null && average.get_prev ().tie_handles) { - if (p.points.size > 2) { - previous = average.get_prev (); - previous.type = DrawingTools.point_type; - PenTool.convert_point_to_line (previous, true); - p.recalculate_linear_handles_for_point (previous); - previous.process_tied_handle (); - previous.set_tie_handle (false); - } - } - added_points = 0; last_update = get_current_time (); glyph.update_view ();