Commit fa354d9
Settings for simplification of autotraced paths
Changed files (4)
addedicons/auto_trace_simplify.pngmodifiedlibbirdfont/BackgroundImage.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/PenTool.vala
Diff
new file mode 100644Binary files /dev/null and b/icons/auto_trace_simplify.png differ@@ -39,6 +39,7 @@ public class BackgroundImage { public bool high_contrast = false; private double trace_resolution = 1.0; private double threshold = 1.0;+ private double simplification = 0.5; private Gee.ArrayList<TracedPoint> points = new Gee.ArrayList<TracedPoint> (); private Gee.ArrayList<TracedPoint> start_points = new Gee.ArrayList<TracedPoint> (); @@ -101,6 +102,7 @@ public class BackgroundImage { bg.img_scale_y = img_scale_y; bg.img_rotation = img_rotation; + bg.simplification = simplification; bg.threshold = threshold; bg.high_contrast = high_contrast; bg.trace_resolution = trace_resolution;@@ -108,6 +110,10 @@ public class BackgroundImage { return bg; } + public void set_trace_simplification (double s) {+ simplification = s;+ }+ public void set_high_contrast (bool t) { high_contrast = t; }@@ -1282,12 +1288,14 @@ public class BackgroundImage { } } - for (i = 0; i < path.points.size; i++) {- ep = path.points.get (i);- ps = new PointSelection (ep, path);- if (corners.index_of (ep) == -1) {- PenTool.remove_point_simplify (ps);- } + if (simplification > 0.01) {+ for (i = 0; i < path.points.size; i++) {+ ep = path.points.get (i);+ ps = new PointSelection (ep, path);+ if (corners.index_of (ep) == -1) {+ PenTool.remove_point_simplify (ps, simplification);+ } + } } for (i = 0; i < path.points.size; i++) {@@ -1298,7 +1306,7 @@ public class BackgroundImage { } } - path = PenTool.simplify (path, true, 0.2);+ path = PenTool.simplify (path, true, simplification); points.clear (); path.update_region_boundaries (); @@ -888,6 +888,23 @@ public class DrawingTools : ToolCollection { }); background_tools.add_tool (auto_trace_resolution);++ SpinButton auto_trace_simplify = new SpinButton ("auto_trace_simplify", t_("Autotrace simplification"));+ auto_trace_simplify.set_value_round (0.5);+ auto_trace_simplify.show_icon (true);++ auto_trace_simplify.new_value_action.connect ((self) => {+ Glyph g = MainWindow.get_current_glyph ();+ BackgroundImage? bg = g.get_background_image ();+ BackgroundImage b;+ + if (bg != null) {+ b = (!) bg;+ b.set_trace_simplification (auto_trace_simplify.get_value ());+ }+ });+ + background_tools.add_tool (auto_trace_simplify); Tool auto_trace = new Tool ("autotrace", t_("Autotrace background image")); auto_trace.select_action.connect ((self) => {@@ -371,7 +371,7 @@ public class PenTool : Tool { } /** @return path distortion. */- public static double remove_point_simplify (PointSelection p) {+ public static double remove_point_simplify (PointSelection p, double tolerance = 0.6) { double start_length, stop_length; double start_distortion, start_min_distortion, start_previous_length; double stop_distortion, stop_min_distortion, stop_previous_length;@@ -430,7 +430,7 @@ public class PenTool : Tool { min_distortion = double.MAX; distance = Path.distance (ep1.x, ep2.x, ep1.y, ep2.y); - for (double m = 50.0; m >= 0.6; m /= 10.0) {+ for (double m = 50.0; m >= tolerance / 2.0; m /= 10.0) { step = m / 10.0; min_distortion = double.MAX;