The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Detect counter paths automatically

These changes was commited to the Birdfont repository Wed, 18 Mar 2015 15:16:08 +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, 18 Mar 2015 15:16:08 +0000 (16:16 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 18 Mar 2015 15:41:56 +0000 (16:41 +0100)
commit c65241bb5a3250e2849fd51d1607db6f67b840c3
tree cb1fed817f654d459314b2f212ac3ac9cc9eb99d
parent 27cd392b2ae2bb420b1b70059cd1ad4ddba3f182
Detect counter paths automatically

libbirdfont/Path.vala
libbirdfont/SvgParser.vala
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -2046,18 +2046,26 @@ return ep; } - public static bool is_counter (PathList pl, Path p) { - foreach (Path o in pl.paths) { - if (o != p) { - if (p.points.size > 0) { - if (o.is_over_coordinate (p.points.get (0).x, p.points.get (0).y)) { - return true; + public static bool is_counter (PathList pl, Path path) { + int inside_count = 0; + bool inside; + + foreach (Path p in pl.paths) { + if (p.points.size > 1 && p != path) { + inside = true; + foreach (EditPoint ep in path.points) { + if (!SvgParser.is_inside (ep, p)) { + inside = false; } + } + + if (inside) { + inside_count++; } } } - return false; + return inside_count % 2 != 0; } public void remove_points_on_points () {
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -443,8 +443,6 @@ private void parse_path (Tag tag, Layer pl) { Glyph glyph = MainWindow.get_current_glyph (); PathList path_list = new PathList (); - int inside_count; - bool inside; foreach (Attribute attr in tag.get_attributes ()) { if (attr.get_name () == "d") { @@ -456,28 +454,10 @@ // assume the even odd rule is applied and convert the path // to a path using the non-zero rule foreach (Path p1 in pl.paths.paths) { - inside_count = 0; - - foreach (Path p2 in pl.paths.paths) { - if (p1 != p2) { - inside = true; - - foreach (EditPoint ep in p1.points) { - if (!is_inside (ep, p2)) { - inside = false; - } - } - - if (inside) { - inside_count++; - } - } - } - - if (inside_count % 2 == 0) { + if (Path.is_counter (pl.paths, p1)) { + p1.force_direction (Direction.COUNTER_CLOCKWISE); + } else { p1.force_direction (Direction.CLOCKWISE); - } else { - p1.force_direction (Direction.COUNTER_CLOCKWISE); } } @@ -489,7 +469,7 @@ } /** Check if a point is inside using the even odd fill rule. */ - bool is_inside (EditPoint point, Path path) { + public static bool is_inside (EditPoint point, Path path) { EditPoint prev; bool inside = false;