Clone in a terminal:
Commit fa354d9
Johan Mattsson - 2014-08-30T23:00:54+00:00
fa354d9ba1c1ab84811635531fefe1055c0ad262johan.mattsson.m@gmail.com

Settings for simplification of autotraced paths

Changed files (4)

Diff

diff --git a/icons/auto_trace_simplify.png b/icons/auto_trace_simplify.pngnew file mode 100644index 0000000..f0eb412Binary files /dev/null and b/icons/auto_trace_simplify.png differdiff --git a/libbirdfont/BackgroundImage.vala b/libbirdfont/BackgroundImage.valaindex ef54ab2..da71160 100644--- a/libbirdfont/BackgroundImage.vala+++ b/libbirdfont/BackgroundImage.vala@@ -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 (); 		diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 58d14d7..443f7f6 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -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) => {diff --git a/libbirdfont/PenTool.vala b/libbirdfont/PenTool.valaindex b1d7bb6..aacb1f7 100644--- a/libbirdfont/PenTool.vala+++ b/libbirdfont/PenTool.vala@@ -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; 			

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112