The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Create new paths with the Beziér tool

These changes was commited to the Birdfont repository Thu, 30 Apr 2015 22:56:01 +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, 30 Apr 2015 22:56:01 +0000]

Updated Files

libbirdfont/ForesightTool.vala
libbirdfont/Path.vala
libbirdfont/PenTool.vala
libbirdfont/StrokeTool.vala
libbirdfont/TrackTool.vala
--- a/libbirdfont/ForesightTool.vala +++ b/libbirdfont/ForesightTool.vala @@ -47,6 +47,7 @@ p.release_action (p, 1, last_move_x, last_move_y); } + MainWindow.get_current_glyph ().clear_active_paths (); MainWindow.set_cursor (NativeWindow.VISIBLE); state = NONE; }); @@ -67,16 +68,24 @@ PointSelection ps; EditPoint first_point; bool clockwise; + Path? path = null; + bool one_point = false; MainWindow.set_cursor (NativeWindow.HIDDEN); if (b == 2) { p.release_action (p, 1, x, y); + + if (PenTool.active_path.is_open ()) { + PenTool.active_path.delete_last_point (); + } + p.press_action (p, 2, x, y); p.release_action (p, 2, x, y); current_path.hide_end_handle = true; state = NONE; MainWindow.set_cursor (NativeWindow.VISIBLE); + MainWindow.get_current_glyph ().clear_active_paths (); return; } @@ -90,25 +99,16 @@ previous_point = 0; state = MOVE_POINT; } else { - if (state == NONE) { - state = MOVE_POINT; - add_new_point (x, y); + if (state == MOVE_POINT) { + state = MOVE_HANDLES; - PenTool.last_point_x = Glyph.path_coordinate_x (x); - PenTool.last_point_y = Glyph.path_coordinate_y (y); + path = PenTool.find_path_to_join (); - move_action (this, x, y); - state = MOVE_FIRST_HANDLE; - release_action(this, b, x, y); - } else if (state == MOVE_POINT) { - state = MOVE_HANDLES; + if (path != null) { + one_point = (((!) path).points.size == 1); + } - if (p.has_join_icon ()) { - if (unlikely (PenTool.active_path.points.size == 0)) { - warning ("No point to join."); - return; - } - + if (p.has_join_icon ()) { ps = new PointSelection (PenTool.active_path.points.get (PenTool.active_path.points.size - 1), PenTool.active_path); ps.point.set_tie_handle (false); @@ -117,13 +117,13 @@ first_point = PenTool.active_path.points.get (0); clockwise = PenTool.active_path.is_clockwise (); - + PenTool.move_selected = false; p.release_action (p, 2, x, y); PenTool.move_selected = false; p.press_action (p, 2, x, y); - + if (ps.path.has_point (first_point)) { ps.path.reverse (); } @@ -139,8 +139,25 @@ PenTool.selected_point = ps.point; state = MOVE_LAST_HANDLE; + + if (one_point) { + p.press_action (p, 2, x, y); + state = NONE; + } } } + + if (state == NONE) { + state = MOVE_POINT; + add_new_point (x, y); + + PenTool.last_point_x = Glyph.path_coordinate_x (x); + PenTool.last_point_y = Glyph.path_coordinate_y (y); + + move_action (this, x, y); + state = MOVE_FIRST_HANDLE; + release_action(this, b, x, y); + } } });
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -608,10 +608,6 @@ reverse_points (); if (unlikely (direction == is_clockwise ())) { - stderr.printf ("Error: Direction did not change after reversing path.\n"); - stderr.printf (@"Length: $(points.size)\n"); - stderr.printf (@"No particular direction can be derived: $no_derived_direction \n"); - warning ("Path.reverse () failed.\n"); return false; }
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -972,12 +972,9 @@ move_point_on_path = true; if (active_edit_point != null) { - glyph.clear_active_paths (); glyph.add_active_path (active_path); - DrawingTools.update_stroke_settings (); - if (KeyBindings.modifier == SHIFT) { if (((!)active_edit_point).is_selected () && selected_points.size > 1) { @@ -1017,7 +1014,7 @@ } } - private static Path? find_path_to_join () { + public static Path? find_path_to_join () { Path? m = null; Glyph glyph = MainWindow.get_current_glyph (); EditPoint ep_last, ep_first; @@ -1148,7 +1145,39 @@ return; } - return_if_fail (path.points.size > 1); + return_if_fail (path.points.size > 0); + + px = Glyph.reverse_path_coordinate_x (((!) active_edit_point).x); + py = Glyph.reverse_path_coordinate_y (((!) active_edit_point).y); + + if (path.points.size == 1) { + glyph.delete_path (path); + glyph.clear_active_paths (); + + foreach (Path merge in glyph.path_list) { + if (merge.points.size > 0) { + if (is_close_to_point (merge.points.get (merge.points.size - 1), px, py)) { + glyph.add_active_path (merge); + active_path = merge; + merge.reopen (); + glyph.open_path (); + return; + } + + if (is_close_to_point (merge.points.get (0), px, py)) { + glyph.add_active_path (merge); + active_path = merge; + merge.reverse (); + clear_directions (); + merge.reopen (); + glyph.open_path (); + return; + } + } + } + + return; + } if (active_edit_point == path.points.get (0)) { path.reverse (); @@ -1165,8 +1194,6 @@ } // join path with it self - px = Glyph.reverse_path_coordinate_x (((!) active_edit_point).x); - py = Glyph.reverse_path_coordinate_y (((!) active_edit_point).y); if (is_endpoint ((!) active_edit_point) && is_close_to_point (path.points.get (0), px, py)) { @@ -1183,6 +1210,7 @@ } remove_all_selected_points (); + return; } @@ -1193,7 +1221,7 @@ } // we need both start and end points - if (merge.points.size < 1 || path.points.size < 1) { + if (merge.points.size <= 1 || path.points.size <= 1) { continue; } @@ -1205,28 +1233,34 @@ return_if_fail (merge.points.size > 0); - if (is_close_to_point (merge.points.get (0), px, py)) { - union = merge_open_paths (path, merge); + if (is_close_to_point (merge.points.get (0), px, py)) { + if (path.points.size == 1) { + warning ("path.points.size == 1\n"); + } else if (merge.points.size == 1) { + warning ("merge.points.size == 1\n"); + } else { + union = merge_open_paths (path, merge); - glyph.add_path (union); - glyph.delete_path (path); - glyph.delete_path (merge); - glyph.clear_active_paths (); - glyph.add_active_path (union); - - union.reopen (); - union.create_list (); - - force_direction (); - - if (direction_changed) { - path.reverse (); - update_selection (); + glyph.add_path (union); + glyph.delete_path (path); + glyph.delete_path (merge); + glyph.clear_active_paths (); + glyph.add_active_path (union); + + union.reopen (); + union.create_list (); + + force_direction (); + + if (direction_changed) { + path.reverse (); + update_selection (); + } + + union.update_region_boundaries (); + + return; } - - union.update_region_boundaries (); - - return; } } @@ -1245,7 +1279,7 @@ distance = sqrt (fabs (pow (px - x, 2)) + fabs (pow (py - y, 2))); - return (distance < 8 * MainWindow.units); + return (distance < 7 * MainWindow.units); } /** Show the user that curves will be merged on release. */
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -1670,14 +1670,14 @@ } public static PathList create_stroke (Path path, double thickness) { - PathList pl = new PathList (); + PathList pl; EditPoint p1, p2, p3; EditPoint previous, previous_inside, start; Path side1, side2; double x, y, x2, y2, x3, y3; - int size = path.is_open () ? path.points.size - 1 : path.points.size; + int size; bool flat, f_next, f_bigger; int i; @@ -1688,11 +1688,16 @@ double step; EditPointHandle l, r; + + pl = new PathList (); + size = path.is_open () ? path.points.size - 1 : path.points.size; side1 = new Path (); side2 = new Path (); - return_val_if_fail (path.points.size > 1, pl); + if (path.points.size < 2) { + return pl; + } previous = new EditPoint (); previous_inside = new EditPoint ();
--- a/libbirdfont/TrackTool.vala +++ b/libbirdfont/TrackTool.vala @@ -48,9 +48,6 @@ int join_x = -1; int join_y = -1; bool join_paths = false; - - /** Create a stroked path instead of filling the shape. */ - double stroke_width = 0; /** Adjust the number of samples per point by this factor. */ double samples_per_point = 1; @@ -59,15 +56,6 @@ string sw; base (name, t_("Freehand drawing")); - - sw = Preferences.get ("free_hand_stroke_width"); - if (sw != "") { - stroke_width = SpinButton.convert_to_double (sw); - } - - select_action.connect((self) => { - Toolbox.set_object_stroke (stroke_width); - }); press_action.connect ((self, button, x, y) => { Glyph glyph = MainWindow.get_current_glyph (); @@ -109,7 +97,6 @@ glyph.open_path (); PenTool.add_new_edit_point (x, y).point; - p.set_stroke (stroke_width); } glyph.update_view (); @@ -143,7 +130,7 @@ if (join != join_paths) { MainWindow.get_current_glyph ().update_view (); - + PenTool.reset_stroke (); } join_paths = join; @@ -159,6 +146,7 @@ convert_on_timeout (); last_x = x; last_y = y; + PenTool.reset_stroke (); } }); @@ -410,7 +398,7 @@ update_cycles = 0; } - if (added_points > 40 / samples_per_point) { + if (added_points > 10 / samples_per_point) { last_update = get_current_time (); convert_points_to_line (); } @@ -537,6 +525,7 @@ added_points = 0; last_update = get_current_time (); glyph.update_view (); + PenTool.reset_stroke (); } /** @return current time in milli seconds. */