The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Autocorrect curve orientation

These changes was commited to the Birdfont repository Tue, 20 Oct 2015 19:40:43 +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>
Tue, 20 Oct 2015 19:40:43 +0000 (21:40 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 20 Oct 2015 19:42:18 +0000 (21:42 +0200)
commit 6a3007e984fddc68fe88da9436be3c35b10759d0
tree 1f2ad6d9698929d6261680d94d86a7c5c152f80a
parent 6dce8976571229a90f73ebfedcc62c6817a541ee
Autocorrect curve orientation

libbirdfont/Glyph.vala
libbirdfont/OverviewTools.vala
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -173,10 +173,6 @@ } warning ("Layer is not added to glyph."); - } - - public PathList get_visible_path_list () { - return layers.get_visible_paths (); } public Gee.ArrayList<Path> get_visible_paths () { @@ -2384,8 +2380,41 @@ set_current_layer (layer); } + } + + public void fix_curve_orientation () { + int inside_count; + bool inside; + Path outline; + + foreach (Path p1 in get_visible_paths ()) { + inside_count = 0; + + foreach (Path p2 in get_visible_paths ()) { + if (p1 != p2) { + inside = true; + outline = p2.flatten (); + + foreach (EditPoint ep in p1.points) { + if (!SvgParser.is_inside (ep, outline)) { + inside = false; + } + } + + if (inside) { + inside_count++; + } + } + } + + if (inside_count % 2 == 0) { + p1.force_direction (Direction.CLOCKWISE); + } else { + p1.force_direction (Direction.COUNTER_CLOCKWISE); + } + } } } }
--- a/libbirdfont/OverviewTools.vala +++ b/libbirdfont/OverviewTools.vala @@ -131,12 +131,52 @@ Tool alternate = new Tool ("alternate", t_("Create alternate")); alternate.select_action.connect (add_new_alternate); glyph_expander.add_tool (alternate); + + Tool curve_orientation = new Tool ("curve_orientation", t_("Set curve orientation")); + curve_orientation.select_action.connect ((self) => { + Task t = new Task (fix_curve_orientation); + + MainWindow.native_window.run_background_thread (t); + + IdleSource idle = new IdleSource (); + idle.set_callback (() => { + self.set_selected (false); + BirdFont.get_current_font ().touch (); + return false; + }); + idle.attach (null); + }); + glyph_expander.add_tool (curve_orientation); expanders.add (font_name); expanders.add (zoom_expander); expanders.add (character_sets); expanders.add (transform_expander); expanders.add (glyph_expander); + } + + void fix_curve_orientation () { + OverView o; + Glyph g; + OverView.OverViewUndoItem ui; + + o = get_overview (); + ui = new OverView.OverViewUndoItem (); + + Font f = BirdFont.get_current_font (); + ui.alternate_sets = f.alternates.copy (); + + foreach (GlyphCollection gc in o.selected_items) { + if (gc.length () > 0) { + g = gc.get_current (); + ui.glyphs.add (gc.copy_deep ()); + g.add_help_lines (); + g.fix_curve_orientation (); + } + } + + o.undo_items.add (ui); + GlyphCanvas.redraw (); } public void add_new_alternate (Tool tool) {