The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Set point type in Beziér tool

These changes was commited to the Birdfont repository Thu, 07 May 2015 11:45:23 +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 11:45:23 +0000]

Updated Files

libbirdfont/BezierTool.vala
libbirdfont/StrokeTool.vala
--- a/libbirdfont/BezierTool.vala +++ b/libbirdfont/BezierTool.vala @@ -23,8 +23,9 @@ public const uint NONE = 0; public const uint MOVE_POINT = 1; public const uint MOVE_HANDLES = 2; - public const uint MOVE_LAST_HANDLE = 3; - public const uint MOVE_FIRST_HANDLE = 4; + public const uint MOVE_LAST_HANDLE_RIGHT = 3; + public const uint MOVE_LAST_HANDLE_LEFT = 4; + public const uint MOVE_FIRST_HANDLE = 5; uint state = NONE; @@ -86,7 +87,11 @@ double px, py; Path? p; Path path; - + + return_if_fail (state != MOVE_HANDLES); + return_if_fail (state != MOVE_LAST_HANDLE_RIGHT); + return_if_fail (state != MOVE_LAST_HANDLE_LEFT); + if (b == 2) { if (g.is_open ()) { stop_drawing (); @@ -127,6 +132,8 @@ current_point.get_left_handle ().convert_to_line (); current_point.recalculate_linear_handles (); g.add_path (current_path); + + set_point_type (); if (StrokeTool.add_stroke) { current_path.stroke = StrokeTool.stroke_width; @@ -136,6 +143,10 @@ state = MOVE_POINT; } else if (state == MOVE_POINT) { if (PenTool.can_join (current_point)) { + bool clockwise; + bool swap; + + clockwise = current_path.is_clockwise (); p = PenTool.join_paths (current_point); return_if_fail (p != null); @@ -149,8 +160,9 @@ } else { g.open_path (); current_path = path; - current_point = path.get_first_point (); - state = MOVE_LAST_HANDLE; + swap = path.is_clockwise () != clockwise; + current_point = !swap ? path.get_first_point () : path.get_last_point (); + state = !swap ? MOVE_LAST_HANDLE_RIGHT : MOVE_LAST_HANDLE_LEFT; } } else { state = MOVE_HANDLES; @@ -158,9 +170,24 @@ } } + void set_point_type () { + PointType pt; + + pt = DrawingTools.get_selected_point_type (); + + current_point.type = pt; + current_point.get_left_handle ().type = pt; + current_point.get_right_handle ().type = pt; + + current_point.get_left_handle ().convert_to_line (); + current_point.get_right_handle ().convert_to_line (); + } + public void release (int b, int x, int y) { double px, py; Glyph g; + + return_if_fail (state != MOVE_POINT); // ignore double clicks if ((GLib.get_real_time () - last_release_time) / 1000000.0 < 0.2) { @@ -178,11 +205,12 @@ current_path.hide_end_handle = true; current_point.get_left_handle ().convert_to_line (); current_point.recalculate_linear_handles (); + set_point_type (); g.clear_active_paths (); g.add_active_path (current_path); GlyphCanvas.redraw (); state = MOVE_POINT; - } else if (state == MOVE_LAST_HANDLE) { + } else if (state == MOVE_LAST_HANDLE_LEFT || state == MOVE_LAST_HANDLE_RIGHT) { current_path.update_region_boundaries (); g.close_path (); MainWindow.set_cursor (NativeWindow.VISIBLE); @@ -192,6 +220,8 @@ } else { current_path.force_direction (Direction.CLOCKWISE); } + + current_path.reset_stroke (); state = NONE; } @@ -213,11 +243,20 @@ current_point.recalculate_linear_handles (); current_path.reset_stroke (); GlyphCanvas.redraw (); - } else if (state == MOVE_HANDLES || state == MOVE_LAST_HANDLE) { + } else if (state == MOVE_HANDLES + || state == MOVE_LAST_HANDLE_LEFT + || state == MOVE_LAST_HANDLE_RIGHT) { + current_path.hide_end_handle = false; current_point.set_reflective_handles (true); current_point.convert_to_curve (); - current_point.get_right_handle ().move_to_coordinate (px, py); + + if (state == MOVE_LAST_HANDLE_LEFT) { + current_point.get_left_handle ().move_to_coordinate (px, py); + } else { + current_point.get_right_handle ().move_to_coordinate (px, py); + } + current_path.reset_stroke (); GlyphCanvas.redraw (); }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -88,7 +88,7 @@ } public static PathList get_stroke_fast (Path path, double thickness) { - PathList o; + /* PathList o; Path stroke; stroke = path.copy (); @@ -96,6 +96,8 @@ o = create_stroke (stroke, thickness, true); return o; + */ + return get_stroke (path, thickness); } public static PathList get_stroke (Path path, double thickness) { @@ -107,6 +109,7 @@ o = create_stroke (stroke, thickness, false); o = get_all_parts (o); o = merge (o); + m = new PathList (); foreach (Path p in o.paths) { @@ -2046,7 +2049,13 @@ side2.reverse (); s1 = side1.get_last_point ().copy (); s2 = side2.get_first_point ().copy (); + + s1.flags &= EditPoint.CURVE ^ EditPoint.ALL; + s2.flags &= EditPoint.CURVE ^ EditPoint.ALL; + s1.convert_to_line (); + s2.convert_to_line (); + open = path.is_open (); if (!open) { @@ -2062,8 +2071,20 @@ side1 = new Path (); side2 = new Path (); + get_segment (thickness, 0, 0.00001, p2, p3, out start); + get_segment (-thickness, 0, 0.00001, p2, p3, out start_inside); + + previous = start.copy (); + previous_inside = start_inside.copy (); + + previous.flags |= EditPoint.CURVE; + previous_inside.flags |= EditPoint.CURVE; + side1.add_point (s1); side2.add_point (s2); + + side1.add_point (previous); + side2.add_point (previous_inside); } } @@ -2076,6 +2097,14 @@ side2.reverse (); pl = merge_stroke_parts (path, side1, side2); + } + + if (fast) { + foreach (Path p in pl.paths) { + p.close (); + convert_to_curve (p); + p.recalculate_linear_handles (); + } } return pl;