Clone in a terminal:
Commit abd6de7
Johan Mattsson - 2016-06-04T16:04:22+00:00
abd6de75a41b7d62e13dde998510d4e91be2fdffjohan.mattsson.m@gmail.com

Merge ../birdfont-2.x

Changed files (8)

Diff

diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex 30140ea..071ae7d 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -343,7 +343,8 @@ class BirdFontFile : GLib.Object { 			os.put_string ("\n"); 		} 		-		os.put_string (@"<background scale=\"$(font.background_scale)\" />\n");	+		os.put_string (@"<background scale=\"$(font.background_scale)\" />\n");+		os.put_string (@"<conversion tolerance=\"$(font.tolerance)\" />\n");	 	}  	public void write_description (DataOutputStream os) throws GLib.Error {@@ -818,6 +819,10 @@ class BirdFontFile : GLib.Object { 				parse_background (t); 			} +			if (t.get_name () == "conversion") {+				parse_cubic_conversion (t);+			}+			 			if (t.get_name () == "postscript_name") { 				font.postscript_name = XmlParser.decode (t.get_content ()); 			}@@ -1188,6 +1193,18 @@ class BirdFontFile : GLib.Object { 		} 	} 	+	private void parse_cubic_conversion (Tag tag) {+		string tolerance = "1";+		+		foreach (Attribute attr in tag.get_attributes ()) {+			if (attr.get_name () == "tolerance") {+				tolerance = attr.get_content ();+			}+		}+		+		font.tolerance = parse_double (tolerance);+	}+	 	private void parse_background_image (Tag tag) { 		string file = ""; 		string data = "";diff --git a/libbirdfont/ExportSettings.vala b/libbirdfont/ExportSettings.valaindex dee61c6..7e66641 100644--- a/libbirdfont/ExportSettings.vala+++ b/libbirdfont/ExportSettings.vala@@ -24,6 +24,7 @@ public class ExportSettings : TableLayout { 	CheckBox ttf; 	CheckBox eot; 	CheckBox svg;+	TextArea tolerance; 	Button export_action; 	Button name_tab; 	@@ -130,6 +131,31 @@ public class ExportSettings : TableLayout {  		svg.margin_bottom = 20 * MainWindow.units; +		widgets.add (new Text (t_("Conversion Tolerance"), label_size, label_margin));+		+		tolerance = new LineTextArea (label_size);+		tolerance.margin_bottom = 20 * MainWindow.units;+		+		tolerance.set_text (@"$(font.tolerance * 100.0)%");+		tolerance.text_changed.connect ((t) => {+			Font f = BirdFont.get_current_font ();+			string tolerance_percent = t.replace ("%", "");+			tolerance_percent = t.replace (",", ".");+			tolerance_percent = t.replace (" ", "");+			double error_tolerance = double.parse (tolerance_percent);+			+			if (error_tolerance >= 100.0) {+				f.tolerance = 1;+			} else if (error_tolerance <= 0) {+				f.tolerance = 0;+			} else {+				f.tolerance = error_tolerance / 100.0;+			}+		});+		+		widgets.add (tolerance);+		focus_ring.add (tolerance);+ 		name_tab = new Button (t_("Name and Description"), margin); 		name_tab.action.connect ((c) => { 			MenuTab.show_description ();diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex 78e7526..010fc7a 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -125,6 +125,7 @@ public class Font : GLib.Object { 	public int format_minor = 0; 	 	public int units_per_em = 1024;+	public double tolerance = 1.0;  	public Font () { 		KerningClasses kerning_classes;diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 4da4d0e..ee9178d 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -231,7 +231,7 @@ public class Glyph : FontDisplay { 		return (!) ttf_data; 	} -	public PathList get_quadratic_paths () {+	public PathList get_quadratic_paths (double tolerance) { 		PointConverter pc; 		PathList pl; 		PathList stroke;@@ -242,11 +242,11 @@ public class Glyph : FontDisplay { 			if (p.stroke > 0) { 				stroke = p.get_completed_stroke (); 				foreach (Path stroke_part in stroke.paths) {-					pc = new PointConverter (stroke_part);+					pc = new PointConverter (stroke_part, tolerance); 					pl.add (pc.get_quadratic_path ()); 				} 			} else {-				pc = new PointConverter (p);+				pc = new PointConverter (p, tolerance); 				pl.add (pc.get_quadratic_path ()); 			} 		}diff --git a/libbirdfont/OpenFontFormat/GlyfData.vala b/libbirdfont/OpenFontFormat/GlyfData.valaindex 2b87c24..39b43dd 100644--- a/libbirdfont/OpenFontFormat/GlyfData.vala+++ b/libbirdfont/OpenFontFormat/GlyfData.vala@@ -58,11 +58,12 @@ public class GlyfData : GLib.Object { 		 	public GlyfData (Glyph g) { 		bool process;-		PathList qp = g.get_quadratic_paths (); +		Font font = OpenFontFormatWriter.get_current_font ();+		PathList quadratic_path = g.get_quadratic_paths (font.tolerance);  		 		glyph = g; 						-		foreach (Path p in qp.paths) {+		foreach (Path p in quadratic_path.paths) { 			if (p.points.size > 0) { 				if (!is_empty (p)) { 					// Add points at extrema@@ -76,7 +77,7 @@ public class GlyfData : GLib.Object { 		while (process) { 			points.clear (); 			paths.clear ();-			foreach (Path p in qp.paths) {+			foreach (Path p in quadratic_path.paths) { 				if (!is_empty (p)) { 					paths.add (p); 					foreach (EditPoint ep in p.points) {diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 0eb4f5d..337d048 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -1204,9 +1204,9 @@ public class Path : GLib.Object { 	/** Convert quadratic bezier points to cubic representation of the glyph 	 * for ttf-export. 	 */ -	public Path get_quadratic_points () {+	public Path get_quadratic_points (double tolerance) { 		PointConverter converter;-		converter = new PointConverter (this);		+		converter = new PointConverter (this, tolerance); 		return converter.get_quadratic_path (); 	} diff --git a/libbirdfont/PointConverter.vala b/libbirdfont/PointConverter.valaindex 530af68..9c6edf2 100644--- a/libbirdfont/PointConverter.vala+++ b/libbirdfont/PointConverter.vala@@ -22,9 +22,11 @@ public class PointConverter {  	Path original_path; 	Path quadratic_path;+	double error_tolerance = 1; -	public PointConverter (Path path) {	+	public PointConverter (Path path, double tolerance) {	 		original_path = path;+		error_tolerance = tolerance; 	}  	public Path get_quadratic_path () {@@ -106,7 +108,7 @@ public class PointConverter { 						out distance, out e, out step); 			} 			-			if (distance > 0.2) { //  range 0.1 - 0.4,+			if (distance > 0.1 + 0.1 * error_tolerance) { //  range 0.1 - 0.4, 				quadratic_path.insert_new_point_on_path (e); 				points_in_segment++; 				size += 2; // the new point + segment startdiff --git a/libbirdfont/TestCases.vala b/libbirdfont/TestCases.valaindex 913219c..8b3a33c 100644--- a/libbirdfont/TestCases.vala+++ b/libbirdfont/TestCases.vala@@ -592,7 +592,7 @@ class TestCases { 		g = MainWindow.get_current_glyph (); 		 		foreach (Path path in g.get_all_paths ()) {-			paths.append (path.get_quadratic_points ());+			paths.append (path.get_quadratic_points (1.0)); 			paths.append (path.copy ()); 		} 				@@ -610,7 +610,7 @@ class TestCases { 		p.add (-10, -10); 		p.close (); 		g.add_path (p);-		g.add_path (p1.get_quadratic_points ());+		g.add_path (p1.get_quadratic_points (1.0));  		e0 = new EditPoint (20, 40); 		e1 = new EditPoint (40, 40);@@ -634,7 +634,7 @@ class TestCases { 		e3.process_tied_handle ();  		g.add_path (p1);-		g.add_path (p1.get_quadratic_points ());+		g.add_path (p1.get_quadratic_points (1.0)); 		 		foreach (Path path in paths) { 			g.add_path (path);

Contact

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