The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Merge lines

These changes was commited to the Birdfont repository Mon, 29 Jun 2015 10:50:22 +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>
Mon, 29 Jun 2015 10:50:22 +0000 (12:50 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Mon, 29 Jun 2015 10:50:22 +0000 (12:50 +0200)
commit 8adce83df88a3f865e1460638e4b6a7ca2e2e80d
tree abb45805f032761202f62fd87f0dae57667358f2
parent daacc69e76f4b67e4184a705f44026d5f6669919
Merge lines

libbirdfont/Menu.vala
libbirdfont/Path.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/Menu.vala +++ b/libbirdfont/Menu.vala @@ -229,6 +229,14 @@ }); edit_menu.items.add (select_point_below); + // FIXME: overview + MenuItem merge_paths = add_menu_item (t_("Merge Paths"), "merge_paths", "Glyph"); + merge_paths.action.connect (() => { + StrokeTool.merge_selected_paths (); + show_menu = false; + }); + edit_menu.items.add (merge_paths); + // layers MenuItem layers = add_menu_item (t_("Layers")); layers.action.connect (() => {
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -846,13 +846,17 @@ return Math.fabs (Math.sqrt (x * x + y * y)); } - public Path flatten () { + public Path flatten (int steps = 10) { Path flat = new Path (); all_of_path ((x, y, t) => { flat.add (x, y); return true; - }, 10); // FIXME: g.view_zoom + }, steps); // FIXME: g.view_zoom + + if (!is_open ()) { + flat.close (); + } return flat; }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -101,17 +101,33 @@ return m; } - public PathList merge_selected_paths () { + public static PathList merge_selected_paths () { PathList n = new PathList (); Glyph g = MainWindow.get_current_glyph (); + + g.store_undo_state (); foreach (Path p in g.active_paths) { if (p.stroke == 0) { - n.add (p); + n.add (p.copy ().flatten ()); } } n = merge (n); + + foreach (Path p in g.active_paths) { + g.delete_path (p); + } + + g.clear_active_paths (); + + foreach (Path p in n.paths) { + g.add_path (p); + g.add_active_path (null, p); + } + + GlyphCanvas.redraw (); + return n; } @@ -963,6 +979,8 @@ path.create_list (); } + // FIXME: set handle position + /* PenTool.convert_point_to_line (ep1, true); PenTool.convert_point_to_line (ep2, true); PenTool.convert_point_to_line (ep3, true); @@ -970,6 +988,7 @@ ep1.recalculate_linear_handles (); ep2.recalculate_linear_handles (); ep3.recalculate_linear_handles (); + */ d = Path.distance_to_point (prev, next); prev.get_right_handle ().length *= Path.distance_to_point (prev, ep1) / d; @@ -1011,7 +1030,7 @@ iy = next.y; return true; } - + Path.find_intersection_point (ep, next, p1, p2, out cross_x, out cross_y); if (fmin (ep.x, next.x) <= cross_x <= fmax (ep.x, next.x) @@ -1026,7 +1045,6 @@ return true; } } - return false; } @@ -1313,7 +1331,7 @@ return r; } - static PathList merge (PathList pl) { + public static PathList merge (PathList pl) { bool error = false; PathList m; PathList r = pl; @@ -1700,7 +1718,7 @@ dm = double.MAX; foreach (Path o in other_paths.paths) { bool inter = segment_intersects (o, ep1, next, out iix, out iiy, - out pp1, out pp2); + out pp1, out pp2, false, false); d = Path.distance (ep1.x, iix, ep1.y, iiy); if (d < dm && inter) { other = o;