Commit 85e35a0
Save stroke buffer
Changed files (6)
modifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PenTool.valamodifiedlibbirdfont/StrokeTool.valamodifiedlibbirdfont/Svg.vala
Diff
@@ -255,6 +255,7 @@ public class DrawingTools : ToolCollection { 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 @@ public class DrawingTools : ToolCollection { 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 @@ public class DrawingTools : ToolCollection { 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 @@ public class DrawingTools : ToolCollection { } MainWindow.get_current_glyph ().update_view ();+ PenTool.reset_stroke (); }); draw_tool_modifiers.add_tool (tie_handles); @@ -540,6 +544,8 @@ public class DrawingTools : ToolCollection { } MainWindow.get_current_glyph ().update_view (); }+ + PenTool.reset_stroke (); }); draw_tool_modifiers.add_tool (reflect_handle); @@ -547,6 +553,7 @@ public class DrawingTools : ToolCollection { 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 @@ public class DrawingTools : ToolCollection { 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 @@ public class DrawingTools : ToolCollection { 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); @@ -145,7 +145,7 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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); } @@ -48,6 +48,8 @@ public class Path { /** 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 @@ public class Path { } 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)) {@@ -2286,6 +2288,38 @@ public class Path { 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;+ } } }@@ -131,6 +131,8 @@ public class PenTool : Tool { 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 @@ public class PenTool : Tool { 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 @@ public class PenTool : Tool { } MainWindow.set_cursor (NativeWindow.VISIBLE);- + point_selection_image = false; BirdFont.get_current_font ().touch (); });@@ -220,6 +224,8 @@ public class PenTool : Tool { GlyphCanvas.redraw (); BirdFont.get_current_font ().touch ();+ + reset_stroke (); }); key_release_action.connect ((self, keyval) => {@@ -229,6 +235,7 @@ public class PenTool : Tool { x = Glyph.reverse_path_coordinate_x (selected_point.x); y = Glyph.reverse_path_coordinate_y (selected_point.y); join_paths (x, y);+ reset_stroke (); } } });@@ -542,11 +549,21 @@ public class PenTool : Tool { 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) { double coordinate_x, coordinate_y; 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 @@ public class PenTool : Tool { if (move_selected_handle || move_selected) { MainWindow.set_cursor (NativeWindow.HIDDEN);+ reset_stroke (); } else { MainWindow.set_cursor (NativeWindow.VISIBLE); }@@ -780,7 +798,7 @@ public class PenTool : Tool { } if (button == 2) {- if (glyph.is_open ()) {+ if (glyph.is_open ()) { force_direction (); glyph.close_path (); } else {@@ -1660,7 +1678,9 @@ public class PenTool : Tool { 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 @@ public class PenTool : Tool { 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) {@@ -39,7 +39,7 @@ public class StrokeTool : Tool { 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 @@ public class StrokeTool : Tool { 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 ();-- stroke.remove_points_on_points (0.3);+ 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 @@ public class StrokeTool : Tool { 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 @@ public class StrokeTool : Tool { 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 @@ public class StrokeTool : Tool { 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 @@ public class StrokeTool : Tool { 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);@@ -23,11 +23,11 @@ class Svg { 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); } }