The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix crash bugs and move quadratic control points independet of handles in the new Beziér tool

These changes was commited to the Birdfont repository Wed, 15 Oct 2014 11:10:25 +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>
Wed, 15 Oct 2014 11:10:25 +0000 (13:10 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 15 Oct 2014 12:11:26 +0000 (14:11 +0200)
commit 9df4a319cb91f9c108f64db07f1b51e85576fa9f
tree efd81c14a84d0827e6d692f0b1ae1788d5745566
parent 25e62f44a34a4e23b9aa29e6ce53c891264bf1a3
Fix crash bugs and move quadratic control points independet of handles in the new Beziér tool

libbirdfont/BirdFont.vala
libbirdfont/EditPoint.vala
libbirdfont/ExportTool.vala
libbirdfont/ForesightTool.vala
libbirdfont/PenTool.vala
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -685,5 +685,4 @@ } } - }
--- a/libbirdfont/EditPoint.vala +++ b/libbirdfont/EditPoint.vala @@ -226,6 +226,8 @@ unowned EditPointHandle h; unowned EditPoint n; double nx, ny; + + return_if_fail (!is_null (right_handle) && !is_null (left_handle)); if (prev == null && next != null) { // FIXME: prev = get_next ().last (); @@ -235,6 +237,8 @@ if (prev != null) { n = get_prev (); h = get_left_handle (); + + return_if_fail (!is_null (n) && !is_null (h)); if (h.type == PointType.LINE_CUBIC) { nx = x + ((n.x - x) / 3); @@ -256,13 +260,14 @@ // the other side h = n.get_right_handle (); - + return_if_fail (!is_null (h) && !is_null (h)); + if (h.type == PointType.LINE_DOUBLE_CURVE) { nx = n.x + ((x - n.x) / 4); ny = n.y + ((y - n.y) / 4); h.move_to_coordinate (nx, ny); } - + if (h.type == PointType.LINE_CUBIC) { nx = n.x + ((x - n.x) / 3); ny = n.y + ((y - n.y) / 3); @@ -280,6 +285,8 @@ if (next != null) { n = get_next (); h = get_right_handle (); + + return_if_fail (!is_null (n) && !is_null (h)); if (h.type == PointType.LINE_CUBIC) { nx = x + ((n.x - x) / 3); @@ -303,6 +310,7 @@ } h = n.get_left_handle (); + return_if_fail (!is_null (h)); if (h.type == PointType.LINE_CUBIC) { nx = n.x + ((x - n.x) / 3); @@ -431,10 +439,18 @@ } public unowned EditPointHandle get_left_handle () { + if (unlikely (is_null (left_handle))) { + warning ("EditPoint.left_handle is null"); + } + return left_handle; } public unowned EditPointHandle get_right_handle () { + if (unlikely (is_null (right_handle))) { + warning ("EditPoint.right_handle is null"); + } + return right_handle; } @@ -456,6 +472,21 @@ public unowned EditPoint get_link_item () { return this; + } + + public void set_independet_position (double tx, double ty) { + double rx, ry, lx, ly; + + rx = right_handle.x; + ry = right_handle.y; + + lx = left_handle.x; + ly = left_handle.y; + + set_position (tx, ty); + + left_handle.move_to_coordinate_internal (lx, ly); + right_handle.move_to_coordinate_internal (rx, ry); } public void set_position (double tx, double ty) {
--- a/libbirdfont/ExportTool.vala +++ b/libbirdfont/ExportTool.vala @@ -384,8 +384,8 @@ bool done = true; try { - ttf_file = folder.get_child (current_font.get_full_name () + ".ttf"); - eot_file = folder.get_child (current_font.get_full_name () + ".eot"); + ttf_file = get_child (folder, current_font.get_full_name () + ".ttf"); + eot_file = get_child (folder, current_font.get_full_name () + ".eot"); printd (@"Writing TTF fonts to $((!) ttf_file.get_path ())\n");
--- a/libbirdfont/ForesightTool.vala +++ b/libbirdfont/ForesightTool.vala @@ -17,7 +17,7 @@ namespace BirdFont { - /** Move control points. */ + /** Create Beziér curves and preview the path. */ public class ForesightTool : Tool { public const uint NONE = 0; @@ -32,9 +32,11 @@ base (name, t_ ("Create Beziér curves"), '.', CTRL); select_action.connect ((self) => { + state = NONE; }); deselect_action.connect ((self) => { + state = NONE; }); press_action.connect ((self, b, x, y) => { @@ -44,7 +46,7 @@ if (state == NONE) { add_new_point (x, y); - move_action (this, x + 10, y + 10); + move_action (this, x, y); state = MOVE_HANDLES; PenTool.active_path.hide_end_handle = false; } @@ -124,6 +126,7 @@ PenTool.move_selected_handle = true; PenTool.selected_handle = (state == MOVE_LAST_HANDLE) ? last.point.get_left_handle () : last.point.get_right_handle (); + last.point.set_reflective_handles (true); last.point.convert_to_curve (); p.move_action (p, x, y); @@ -133,7 +136,14 @@ last.point.set_tie_handle (true); } else { - p.move_action (p, x, y); + + if (DrawingTools.get_selected_point_type () != PointType.QUADRATIC) { + p.move_action (p, x, y); + } else { + PenTool.move_point_independent_of_handle = true; + p.move_action (p, x, y); + PenTool.move_point_independent_of_handle = false; + } } }); @@ -157,18 +167,22 @@ void add_new_point (int x, int y) { PointSelection last; - Tool p = PointTool.pen (); + PenTool p = (PenTool) PointTool.pen (); PenTool.selected_points.clear (); PenTool.selected_handle = new EditPointHandle.empty (); p.release_action (p, 3, x, y); - p.press_action (p, 1, x, y); + //p.press_action (p, 1, x, y); + + //return_if_fail (PenTool.selected_points.size != 0); + //last = PenTool.selected_points.get (PenTool.selected_points.size - 1); + + //p.release_action (p, 1, x, y); - return_if_fail (PenTool.selected_points.size != 0); - last = PenTool.selected_points.get (PenTool.selected_points.size - 1); + last = p.new_point_action (x, y); + p.move_selected = false; - p.release_action (p, 1, x, y); p.press_action (p, 3, x, y); PenTool.selected_points.clear ();
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -32,6 +32,8 @@ public static bool move_point_on_path = false; public static bool edit_active_corner = false; + + public static bool move_point_independent_of_handle = false; public static Gee.ArrayList<PointSelection> selected_points; @@ -607,8 +609,14 @@ delta_coordinate_y = coordinate_y - last_point_y; foreach (PointSelection selected in selected_points) { - selected.point.set_position (selected.point.x + delta_coordinate_x, - selected.point.y + delta_coordinate_y); + if (move_point_independent_of_handle) { + selected.point.set_independet_position (selected.point.x + delta_coordinate_x, + selected.point.y + delta_coordinate_y); + } else { + selected.point.set_position (selected.point.x + delta_coordinate_x, + selected.point.y + delta_coordinate_y); + } + selected.point.recalculate_linear_handles (); selected.path.update_region_boundaries (); } @@ -620,8 +628,14 @@ delta_coordinate_y = coordinate_y - last_point_y; foreach (PointSelection selected in selected_points) { - selected.point.set_position (selected.point.x + delta_coordinate_x, - selected.point.y + delta_coordinate_y); + if (move_point_independent_of_handle) { + selected.point.set_independet_position (selected.point.x + delta_coordinate_x, + selected.point.y + delta_coordinate_y); + } else { + selected.point.set_position (selected.point.x + delta_coordinate_x, + selected.point.y + delta_coordinate_y); + } + selected.point.recalculate_linear_handles (); selected.path.update_region_boundaries (); } @@ -632,8 +646,14 @@ delta_coordinate_y = coordinate_y - last_point_y; foreach (PointSelection selected in selected_points) { - selected.point.set_position (selected.point.x + delta_coordinate_x, - selected.point.y + delta_coordinate_y); + + if (move_point_independent_of_handle) { + selected.point.set_independet_position (selected.point.x + delta_coordinate_x, + selected.point.y + delta_coordinate_y); + } else { + selected.point.set_position (selected.point.x + delta_coordinate_x, + selected.point.y + delta_coordinate_y); + } selected.point.recalculate_linear_handles (); selected.path.update_region_boundaries (); @@ -1328,7 +1348,7 @@ } } - public void new_point_action (int x, int y) { + public PointSelection new_point_action (int x, int y) { Glyph glyph; PointSelection new_point; glyph = MainWindow.get_current_glyph (); @@ -1346,6 +1366,8 @@ add_selected_point (selected_point, glyph.active_paths.get (glyph.active_paths.size - 1)); move_selected = true; + + return new_point; } public static PointSelection add_new_edit_point (int x, int y) {