The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Save stroke buffer

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

Updated Files

libbirdfont/DrawingTools.vala
libbirdfont/Glyph.vala
libbirdfont/Path.vala
libbirdfont/PenTool.vala
libbirdfont/StrokeTool.vala
libbirdfont/Svg.vala
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -255,6 +255,7 @@ PenTool.convert_point_types (); GlyphCanvas.redraw (); update_type_selection (); + PenTool.reset_stroke (); }); convert_points.set_persistent (false); draw_tool_modifiers.add_tool (convert_points); @@ -375,6 +376,7 @@ resize_tool.objects_rotated.connect ((angle) => { rotation.set_value_round (angle, true, false); + PenTool.reset_stroke (); }); move_tool.objects_deselected.connect (() => { @@ -395,6 +397,7 @@ skew.set_persistent (false); skew.new_value_action.connect ((self) => { resize_tool.skew (-skew.get_value ()); + PenTool.reset_stroke (); GlyphCanvas.redraw (); }); @@ -517,6 +520,7 @@ } MainWindow.get_current_glyph ().update_view (); + PenTool.reset_stroke (); }); draw_tool_modifiers.add_tool (tie_handles); @@ -540,6 +544,8 @@ } MainWindow.get_current_glyph ().update_view (); } + + PenTool.reset_stroke (); }); draw_tool_modifiers.add_tool (reflect_handle); @@ -547,6 +553,7 @@ create_line.select_action.connect ((self) => { PenTool.convert_segment_to_line (); MainWindow.get_current_glyph ().update_view (); + PenTool.reset_stroke (); }); draw_tool_modifiers.add_tool (create_line); @@ -568,6 +575,7 @@ flip_vertical.select_action.connect ((self) => { MoveTool.flip_vertical (); MainWindow.get_current_glyph ().update_view (); + PenTool.reset_stroke (); }); draw_tool_modifiers.add_tool (flip_vertical); @@ -575,6 +583,7 @@ flip_horizontal.select_action.connect ((self) => { MoveTool.flip_horizontal (); MainWindow.get_current_glyph ().update_view (); + PenTool.reset_stroke (); }); draw_tool_modifiers.add_tool (flip_horizontal);
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -145,7 +145,7 @@ pl = new PathList (); foreach (Path p in path_list) { if (p.stroke > 0) { - stroke = StrokeTool.get_stroke (p, p.stroke); + stroke = p.get_stroke_fast (); foreach (Path stroke_part in stroke.paths) { pc = new PointConverter (stroke_part); pl.add (pc.get_quadratic_path ()); @@ -1511,7 +1511,7 @@ cr.new_path (); foreach (Path p in path_list) { if (p.stroke > 0) { - stroke = StrokeTool.get_stroke (p, p.stroke); + stroke = p.get_stroke_fast (); draw_path_list (stroke, cr, Color.black ()); } else { p.draw_path (cr, this, Color.black ()); @@ -1528,7 +1528,7 @@ cr.new_path (); foreach (Path p in path_list) { if (p.stroke > 0) { - stroke = StrokeTool.get_stroke (p, p.stroke); + stroke = p.get_stroke_fast (); draw_path_list (stroke, cr, get_path_fill_color ()); } @@ -1543,7 +1543,7 @@ cr.new_path (); foreach (Path p in path_list) { if (p.stroke > 0) { - stroke = StrokeTool.get_stroke (p, p.stroke); + stroke = p.get_stroke_fast (); draw_outline_for_paths (stroke, cr); } @@ -1563,7 +1563,7 @@ if (p.stroke == 0) { p.draw_path (cr, this, Color.black ()); } else { - stroke = StrokeTool.get_stroke (p, p.stroke); + stroke = p.get_stroke_fast (); draw_path_list (stroke, cr, Color.black ()); } } @@ -1577,7 +1577,7 @@ if (p.stroke == 0) { p.draw_path (cr, this); } else { - draw_path_list (StrokeTool.get_stroke (p, p.stroke), cr); + draw_path_list (p.get_stroke_fast (), cr); } cr.close_path (); cr.fill (); @@ -1588,7 +1588,7 @@ if (show_orientation_arrow) { foreach (Path p in path_list) { if (p.stroke > 0) { - stroke = StrokeTool.get_stroke (p, p.stroke); + stroke = p.get_stroke_fast (); foreach (Path ps in stroke.paths) { ps.draw_orientation_arrow (cr, orientation_arrow_opacity); }
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -48,6 +48,8 @@ /** Stroke width */ public double stroke = 0; + PathList? full_stroke = null; + PathList? fast_stroke = null; /** Fill property for closed paths with stroke. */ public bool fill = false; @@ -830,7 +832,7 @@ } if (stroke > 0) { - pathlist = StrokeTool.get_stroke (this, stroke); + pathlist = get_stroke_fast (); // FIXME: add to clickmap instead if (pathlist.paths.size > 1) { if (pathlist.paths.get (1).is_over_coordinate_var (x, y)) { @@ -2285,8 +2287,40 @@ nx = npx; ny = npy; + } + + public void reset_stroke () { + full_stroke = null; + fast_stroke = null; + } + + public void create_full_stroke () { + full_stroke = StrokeTool.get_stroke (this, stroke); + } + + public PathList get_stroke () { + if (full_stroke == null) { + full_stroke = StrokeTool.get_stroke (this, stroke); + } + + return (!) full_stroke; + } + + public PathList get_stroke_fast () { + PathList s; + + if (full_stroke != null) { + return (!) full_stroke; + } + + if (fast_stroke != null) { + return (!) fast_stroke; + } + + fast_stroke = StrokeTool.get_stroke_fast (this, stroke); + return (!) fast_stroke; } } }
--- a/libbirdfont/PenTool.vala +++ b/libbirdfont/PenTool.vala @@ -131,6 +131,8 @@ if (b == 1 && (GridTool.has_ttf_grid () || GridTool.is_visible ())) { move (x, y); } + + reset_stroke (); }); double_click_action.connect ((self, b, x, y) => { @@ -142,7 +144,9 @@ release_action.connect ((self, b, ix, iy) => { double x, y; + Glyph g; + g = MainWindow.get_current_glyph (); x = Glyph.path_coordinate_x (ix); y = Glyph.path_coordinate_y (iy); @@ -177,7 +181,7 @@ } MainWindow.set_cursor (NativeWindow.VISIBLE); - + point_selection_image = false; BirdFont.get_current_font ().touch (); }); @@ -220,6 +224,8 @@ GlyphCanvas.redraw (); BirdFont.get_current_font ().touch (); + + reset_stroke (); }); key_release_action.connect ((self, keyval) => { @@ -229,6 +235,7 @@ x = Glyph.reverse_path_coordinate_x (selected_point.x); y = Glyph.reverse_path_coordinate_y (selected_point.y); join_paths (x, y); + reset_stroke (); } } }); @@ -540,6 +547,13 @@ public void set_precision (double p) { precision = p; SettingsDisplay.precision.set_value_round (p, false, false); + } + + public static void reset_stroke () { + Glyph g = MainWindow.get_current_glyph (); + foreach (Path p in g.active_paths) { + p.reset_stroke (); + } } public void move (int x, int y) { @@ -547,6 +561,9 @@ double delta_coordinate_x, delta_coordinate_y; double angle = 0; bool tied; + Glyph g; + + g = MainWindow.get_current_glyph (); control_point_event (x, y); curve_active_corner_event (x, y); @@ -560,6 +577,7 @@ if (move_selected_handle || move_selected) { MainWindow.set_cursor (NativeWindow.HIDDEN); + reset_stroke (); } else { MainWindow.set_cursor (NativeWindow.VISIBLE); } @@ -780,7 +798,7 @@ } if (button == 2) { - if (glyph.is_open ()) { + if (glyph.is_open ()) { force_direction (); glyph.close_path (); } else { @@ -1660,7 +1678,9 @@ private void curve_active_corner_event (double event_x, double event_y) { PointSelection eh; + Glyph glyph; + glyph = MainWindow.get_current_glyph (); active_handle.active = false; if (!is_over_handle (event_x, event_y)) { @@ -1671,6 +1691,9 @@ eh.handle.active = true; active_handle = eh.handle; active_path = eh.path; + + glyph.clear_active_paths (); + glyph.add_active_path (eh.path); } private void curve_corner_event (double event_x, double event_y) {
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -39,7 +39,7 @@ foreach (Path p in g.active_paths) { if (p.stroke > 0) { - paths.append (get_stroke (p, p.stroke)); + paths.append (p.get_stroke ()); } } @@ -84,27 +84,22 @@ stroke_selected = false; // FIXME: delete } - public static PathList get_stroke (Path path, double thickness) { + public static PathList get_stroke_fast (Path path, double thickness) { PathList o; - Path stroke = path.copy (); - + Path stroke; + + stroke = path.copy (); stroke.remove_points_on_points (0.3); - o = create_stroke (stroke, thickness); - foreach (Path p in o.paths) { - if (stroke_selected) {// FIXME: DELETE - ((!) BirdFont.get_current_font ().get_glyph ("c")).add_path (p); - } - } - o = get_all_parts (o); // FIXME: only on stroke to outline - foreach (Path p in o.paths) { - if (stroke_selected) {// FIXME: DELETE - ((!) BirdFont.get_current_font ().get_glyph ("d")).add_path (p); - } - } + return o; + } + + public static PathList get_stroke (Path path, double thickness) { + PathList o; - // FIXME: only on stroke to outline + o = get_stroke_fast (path, thickness); + o = get_all_parts (o); o = merge (o); return o; @@ -1133,12 +1128,10 @@ foreach (EditPoint p in path.points) { if ((p.x == point.x && p.y == point.y) || (prev.x == point.x && prev.y == point.y)) { - point.color = Color.green (); return true; } else 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; - point.color = Color.yellow (); } prev = p; @@ -1658,7 +1651,9 @@ p.recalculate_linear_handles (); - return_val_if_fail (p.points.size >= 3, true); + if (p.points.size < 3) { + return true; + } for (int i = 0; i < p.points.size; i++) { p1 = p.points.get (i); @@ -1804,6 +1799,7 @@ Path overlay; double x, y, x2, y2, x3, y3; EditPoint corner1, corner2, corner3; + PointType type; Path.get_point_for_step (p1, p2, step, out x, out y); Path.get_point_for_step (p1, p2, step + step_size, out x2, out y2); @@ -1811,9 +1807,10 @@ overlay = new Path (); - corner1 = new EditPoint (x, y, PointType.LINE_CUBIC); - corner2 = new EditPoint (x2, y2, PointType.LINE_CUBIC); - corner3 = new EditPoint (x3, y3, PointType.LINE_CUBIC); + type = p1.get_right_handle ().type; + corner1 = new EditPoint (x, y, type); + corner2 = new EditPoint (x2, y2, type); + corner3 = new EditPoint (x3, y3, type); overlay.add_point (corner1); overlay.add_point (corner2);
--- a/libbirdfont/Svg.vala +++ b/libbirdfont/Svg.vala @@ -23,11 +23,11 @@ StringBuilder svg = new StringBuilder (); PathList stroke_list; - foreach (Path pl in g.path_list) { - if (pl.stroke == 0) { - write_path_as_glyph (pl, svg, g); + foreach (Path p in g.path_list) { + if (p.stroke == 0) { + write_path_as_glyph (p, svg, g); } else { - stroke_list = StrokeTool.get_stroke (pl, pl.stroke); + stroke_list = p.get_stroke (); write_paths_as_glyph (stroke_list, svg, g); } }