The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Fix automatic orientation in SVG import

These changes was commited to the Birdfont repository Wed, 15 Apr 2015 17:02:00 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Wed, 15 Apr 2015 17:02:00 +0000]

Updated Files

libbirdfont/Path.vala
libbirdfont/StrokeTool.vala
libbirdfont/SvgParser.vala
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -280,7 +280,11 @@ c = (!) color; cr.set_source_rgba (c.r, c.g, c.b, c.a); } else { - Theme.color_opacity (cr, "Selected Objects", 0.5); + if (is_clockwise ()) { + Theme.color_opacity (cr, "Selected Objects", 0.4); + } else { + Theme.color_opacity (cr, "Selected Objects", 0.8); + } } } @@ -2138,10 +2142,10 @@ if (p.points.size > 1 && p != path && path.boundaries_intersecting (p)) { - inside = true; + inside = false; foreach (EditPoint ep in path.points) { - if (!SvgParser.is_inside (ep, p)) { - inside = false; + if (SvgParser.is_inside (ep, p)) { + inside = true; } }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -97,6 +97,10 @@ public static PathList get_stroke (Path path, double thickness) { PathList n; Path stroke = path.copy (); + + if (!stroke.is_clockwise ()) { + stroke.force_direction (Direction.CLOCKWISE); + } stroke.remove_points_on_points (0.3); @@ -167,12 +171,14 @@ if ((ep.flags & EditPoint.REMOVE_PART) > 0) { if (p.points.size > 5) { + ep.color = Color.pink (); return false; } } if ((ep.flags & EditPoint.NEW_CORNER) > 0) { if (p.points.size > 5) { + ep.color = Color.pink (); return false; } } @@ -205,6 +211,7 @@ if (Path.distance_to_point (ep.get_prev (), ep.get_next ()) < 1) { ep.deleted = true; + ep.color = Color.red (); p.remove_deleted_points (); return is_corner_self_intersection (p) || is_counter_to_outline (p); } @@ -620,10 +627,6 @@ p2 = p.points.get (index % p.points.size); a1 = p.points.get ((index + 3) % p.points.size); // two points ahead a2 = p.points.get ((index + 4) % p.points.size); - - if ((p2.flags & EditPoint.STROKE_OFFSET) > 0) { - a1.color = Color.yellow (); - } if ((p2.flags & EditPoint.STROKE_OFFSET) > 0 && (a1.flags & EditPoint.STROKE_OFFSET) > 0) { @@ -824,7 +827,6 @@ foreach (EditPoint p in path.points) { if (insides (p, path) == 1) { path.set_new_start (p); - p.color = Color.green (); path.close (); break; } @@ -1732,6 +1734,7 @@ ps = new PointSelection (ep1, merged); if (is_inside_of_path (ps, result, out outline)) { ep1.deleted = true; + ep1.color = Color.red (); } } } @@ -1953,12 +1956,14 @@ if (start.type == PointType.HIDDEN) { start.tie_handles = false; start.deleted = true; + start.color = Color.red (); } if (end.type == PointType.HIDDEN) { start.tie_handles = false; end.tie_handles = false; end.deleted = true; + end.color = Color.red (); } if (unlikely (added_points > 4)) {
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -450,14 +450,34 @@ pl.paths.append (path_list); } } - + // assume the even odd rule is applied and convert the path // to a path using the non-zero rule + int inside_count; + bool inside; foreach (Path p1 in pl.paths.paths) { - if (Path.is_counter (pl.paths, p1)) { - p1.force_direction (Direction.COUNTER_CLOCKWISE); - } else { + 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) { p1.force_direction (Direction.CLOCKWISE); + } else { + p1.force_direction (Direction.COUNTER_CLOCKWISE); } } @@ -545,19 +565,16 @@ if (path.points.size <= 1) { return false; } - - prev = path.get_last_point (); - - foreach (EditPoint start in path.points) { - if (start.x == point.x && point.y == start.y) { - inside = true; - break; - } else if ((start.y > point.y) != (prev.y > point.y) - && point.x < (prev.x - start.x) * (point.y - start.y) / (prev.y - start.y) + start.x) { - inside = !inside; - } - - prev = start; + + prev = path.points.get (path.points.size - 1); + + foreach (EditPoint p in path.points) { + if ((p.y > point.y) != (prev.y > point.y) + && point.x < (prev.x - p.x) * (point.y - p.y) / (prev.y - p.y) + p.x) { + inside = !inside; + } + + prev = p; } return inside;