The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Fix self intersecting stroke

These changes was commited to the Birdfont repository Thu, 07 May 2015 09:00:58 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Thu, 07 May 2015 09:00:58 +0000]

Updated Files

libbirdfont/BezierTool.vala
libbirdfont/StrokeTool.vala
libbirdfont/Toolbox.vala
--- a/libbirdfont/BezierTool.vala +++ b/libbirdfont/BezierTool.vala @@ -171,17 +171,19 @@ px = Glyph.path_coordinate_x (x); py = Glyph.path_coordinate_y (y); + g = MainWindow.get_current_glyph (); if (state == MOVE_HANDLES) { current_point = current_path.add (px, py); current_path.hide_end_handle = true; current_point.get_left_handle ().convert_to_line (); current_point.recalculate_linear_handles (); + g.clear_active_paths (); + g.add_active_path (current_path); GlyphCanvas.redraw (); state = MOVE_POINT; } else if (state == MOVE_LAST_HANDLE) { current_path.update_region_boundaries (); - g = MainWindow.get_current_glyph (); g.close_path (); MainWindow.set_cursor (NativeWindow.VISIBLE);
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -398,6 +398,7 @@ if (ratio > 1) { stroked.add_point (corner); } else { + cutoff1 = new EditPoint (); cutoff1.set_point_type (previous.type); cutoff1.convert_to_line (); @@ -405,13 +406,13 @@ cutoff2 = new EditPoint (); cutoff2.set_point_type (previous.type); cutoff2.convert_to_line (); - + cutoff1.x = previous.x + (corner.x - previous.x) * ratio; cutoff1.y = previous.y + (corner.y - previous.y) * ratio; cutoff2.x = next.x + (corner.x - next.x) * ratio; cutoff2.y = next.y + (corner.y - next.y) * ratio; - + if (!cutoff1.is_valid () || cutoff2.is_valid ()) { cutoff1 = stroked.add_point (cutoff1); cutoff2 = stroked.add_point (cutoff2); @@ -419,6 +420,19 @@ cutoff1.recalculate_linear_handles (); cutoff2.recalculate_linear_handles (); + + return_if_fail (previous.prev != null); + + bool d1 = corner.x - previous.x > 0 == previous.x - previous.get_prev ().x > 0; + bool d2 = corner.y - previous.y > 0 == previous.y - previous.get_prev ().y > 0; + + if (!d1 && !d2) { + cutoff1.deleted = true; + cutoff2.deleted = true; + + stroked.remove_deleted_points (); + return; + } if (distance > 4 * stroke_width) { previous.flags = EditPoint.NONE; @@ -1874,7 +1888,7 @@ side1 = new Path (); side2 = new Path (); - + if (path.points.size < 2) { return pl; } @@ -2023,14 +2037,33 @@ } if (fast) { + EditPoint s1, s2; + bool open; + convert_to_curve (side1); convert_to_curve (side2); side2.reverse (); - pl.append (merge_stroke_parts (path, side1, side2)); + s1 = side1.get_last_point ().copy (); + s2 = side2.get_first_point ().copy (); + open = path.is_open (); + + if (!open) { + path.reopen (); + } + + pl.append (merge_stroke_parts (path, side1, side2)); + + if (!open) { + path.close (); + } + side1 = new Path (); side2 = new Path (); + + side1.add_point (s1); + side2.add_point (s2); } }
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -332,7 +332,6 @@ public void set_current_tool (Tool tool) { if (tool.editor_events) { - print (@"NEW PROP $(tool.get_name ())\n"); current_tool = tool; } }