Clone in a terminal:
Commit 406c728
Johan Mattsson - 2015-04-01T22:51:05+00:00
406c728806e3ac844eb38d8468a5a427ba8fcad1johan.mattsson.m@gmail.com

Remove points on points in TTF export

Changed files (6)

Diff

diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex 61ec225..2716db9 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -485,18 +485,7 @@ public class Font : GLib.Object { 	 	/** Obtain all versions and alterntes for this glyph. */ 	public GlyphCollection? get_glyph_collection (string glyph) {-		GlyphCollection? gc = get_cached_glyph_collection (glyph);-		Glyph? g;-		-		if (gc == null && otf_font) {-			// load it from otf file if we need to-			g = otf.read_glyph (glyph);-			-			if (g != null) {-				return get_cached_glyph_collection (glyph);-			}-		}-			+		GlyphCollection? gc = get_cached_glyph_collection (glyph);	 		return gc; 	} diff --git a/libbirdfont/OpenFontFormat/GlyfData.vala b/libbirdfont/OpenFontFormat/GlyfData.valaindex 9ba455a..a01e2e2 100644--- a/libbirdfont/OpenFontFormat/GlyfData.vala+++ b/libbirdfont/OpenFontFormat/GlyfData.vala@@ -36,6 +36,7 @@ public class CoordinateFlags { /** Data for one entry in the glyf table. */ public class GlyfData : GLib.Object {		 	public Gee.ArrayList<Path> paths = new Gee.ArrayList<Path> ();+	public Gee.ArrayList<EditPoint> points = new Gee.ArrayList<EditPoint> (); 	public Gee.ArrayList<uint16> end_points = new Gee.ArrayList<uint16> (); 	public Gee.ArrayList<uint8> flags = new Gee.ArrayList<uint8> (); 	public Gee.ArrayList<int16> coordinate_x = new Gee.ArrayList<int16> ();@@ -55,26 +56,48 @@ public class GlyfData : GLib.Object { 		get { return HeadTable.UNITS; } 	} 		-	public GlyfData (Glyph g) {	+	public GlyfData (Glyph g) {+		bool process;+		PathList qp = g.get_quadratic_paths (); +		 		glyph = g; 						-		foreach (Path p in g.get_quadratic_paths ().paths) {+		foreach (Path p in qp.paths) { 			if (p.points.size > 0) { 				if (!is_empty (p)) { 					// Add points at extrema 					p.add_extrema ();-					paths.add (p); 				} 			} 		} 		-		if (paths.size > 0) {+		process = true;+		+		while (process) {+			points.clear ();+			paths.clear ();+			foreach (Path p in qp.paths) {+				if (!is_empty (p)) {+					paths.add (p);+					foreach (EditPoint ep in p.points) {+						points.add (ep);+					}+				}+			}+			+			if (paths.size == 0) {+				break;+			}+			 			process_end_points (); 			process_flags (); 			process_x ();-			process_y ();+			+			// error checking is done here+			process = !process_y (); +			 			process_bounding_box ();-		}+		 } 	}  	bool is_empty (Path p) {@@ -112,6 +135,7 @@ public class GlyfData : GLib.Object { 		uint16 last_end_point = 0; 		PointType type; 		+		end_points.clear (); 		end_point = 0; 		 		foreach (Path quadratic in paths) {@@ -187,6 +211,7 @@ public class GlyfData : GLib.Object { 		double x; 		PointType type; 		+		coordinate_x.clear (); 		foreach (Path p in paths) { 			foreach (EditPoint e in p.points) { 				x = rint (e.x * UNITS - prev - glyph.left_limit * UNITS);@@ -205,17 +230,31 @@ public class GlyfData : GLib.Object { 		} 	} 	-	void process_y () {+	bool process_y () { 		double prev = 0; 		double y; 		Font font = OpenFontFormatWriter.get_current_font (); 		PointType type;+		int epi = 0;+		+		coordinate_y.clear (); 		 		foreach (Path p in paths) { 			foreach (EditPoint e in p.points) { 				y = rint (e.y * UNITS - prev - font.base_line  * UNITS); 				coordinate_y.add ((int16) y); 				+				if ((int16) y == 0 && (int16) coordinate_x.get (coordinate_y.size - 1) == 0) {+					warning (@"Point on point in TTF. Index $(coordinate_y.size - 1)");+					+					if (BirdFont.has_argument ("--test")) {+						print (glyph.get_name () + "\n");+						print (points.get (epi).to_string ());+						PenTool.remove_point_simplify (new PointSelection (points.get (epi), p));+						return false;+					}+				}+				 				prev = rint (e.y * UNITS - font.base_line * UNITS); 				 				type = e.get_right_handle ().type;@@ -223,10 +262,24 @@ public class GlyfData : GLib.Object { 				// off curve 				y = rint (e.get_right_handle ().y * UNITS - prev - font.base_line * UNITS); 				coordinate_y.add ((int16) y);-			++				if ((int16) y == 0 && (int16) coordinate_x.get (coordinate_y.size - 1) == 0) {+					warning (@"Point on point in TTF (off curve) Index: $(coordinate_y.size - 1) ");+					if (BirdFont.has_argument ("--test")) {+						print (glyph.get_name () + "\n");+						print (points.get (epi).to_string ());+						+						PenTool.remove_point_simplify (new PointSelection (points.get (epi), p));+						return false;+					}+				}+							 				prev = rint (e.get_right_handle ().y * UNITS - font.base_line  * UNITS);+				epi++; 			} 		}+		+		return true; 	} 	 	void process_bounding_box () {@@ -283,3 +336,4 @@ public class GlyfData : GLib.Object { }  }+diff --git a/libbirdfont/OpenFontFormat/GlyfTable.vala b/libbirdfont/OpenFontFormat/GlyfTable.valaindex 5ce2ddc..f1fb066 100644--- a/libbirdfont/OpenFontFormat/GlyfTable.vala+++ b/libbirdfont/OpenFontFormat/GlyfTable.vala@@ -319,20 +319,6 @@ public class GlyfTable : OtfTable { 		} 		printd (@"length after padding: $(fd.length ())\n"); 	}--	public Glyph? read_glyph (string name) throws GLib.Error {-		Glyph? glyph;-		int i;-		-		i = post_table.get_gid (name);-		-		if (i == -1) {-			return null;-		}-		-		glyph = parse_index (i, dis, loca_table, hmtx_table, head_table, post_table);-		return glyph;-	} 	 	public new void parse (FontData dis, CmapTable cmap_table, LocaTable loca, HmtxTable hmtx_table, HeadTable head_table, PostTable post_table, KernTable kern_table) throws GLib.Error { 		this.cmap_table = cmap_table;@@ -344,56 +330,6 @@ public class GlyfTable : OtfTable { 		this.dis = dis; 	} 	-	Glyph parse_index (int index, FontData dis, LocaTable loca, HmtxTable hmtx_table, HeadTable head_table, PostTable post_table) throws GLib.Error {--// FIXME: DELETE parse with freetype-		Glyph glyph = new Glyph ("");-/*-		double xmin, xmax;-		double units_per_em = head_table.get_units_per_em ();-		unichar character = 0;-		string name;-		-		character = cmap_table.get_char (index);-		name = post_table.get_name (index);-		-		if (name == "") {-			StringBuilder name_c = new StringBuilder ();-			name_c.append_unichar (character);-			name = name_c.str;-		}--		printd (@"name: $(name)\n");--		if (!loca.is_empty (index)) {	-			glyph = parse_next_glyf (dis, character, index, out xmin, out xmax, units_per_em);-			-			glyph.left_limit = xmin - hmtx_table.get_lsb (index);-			glyph.left_limit = 0;-			glyph.right_limit = glyph.left_limit + hmtx_table.get_advance (index);-		} else {-			// add empty glyph-			glyph = new Glyph (name, character);-			glyph.left_limit = -hmtx_table.get_lsb (index);-			glyph.right_limit = hmtx_table.get_advance (index) - hmtx_table.get_lsb (index);				-		}-		-		glyph.name = name;--		if (character == 0) {-			glyph.set_unassigned (true);-		}-		-		if (character == 0 && name != "") {-			stderr.printf (@"Got null character\n");-			stderr.printf (@"gid: $index\n");-			stderr.printf (@"char: $((uint) character)\n");-			stderr.printf (@"name: $(name)\n");-		}-*/-		return glyph;-	}-	 	Glyph parse_next_composite_glyf (FontData dis, unichar character, int pgid) throws Error { 		uint16 component_flags = 0; 		uint16 glyph_index;diff --git a/libbirdfont/OpenFontFormat/HmtxTable.vala b/libbirdfont/OpenFontFormat/HmtxTable.valaindex 2402b07..2a9abe8 100644--- a/libbirdfont/OpenFontFormat/HmtxTable.vala+++ b/libbirdfont/OpenFontFormat/HmtxTable.vala@@ -173,7 +173,9 @@ public class HmtxTable : OtfTable { 		 		font_data = fd; 		-		warn_if_fail (max_advance != 0);+		if (max_advance != 0) {+			warning ("max_advance is zero");+		} 	} 	 	public int16 get_average_width () {diff --git a/libbirdfont/OpenFontFormat/OpenFontFormatReader.vala b/libbirdfont/OpenFontFormat/OpenFontFormatReader.valaindex 3cc0f8f..e4d81bd 100644--- a/libbirdfont/OpenFontFormat/OpenFontFormatReader.vala+++ b/libbirdfont/OpenFontFormat/OpenFontFormatReader.vala@@ -60,16 +60,6 @@ public class OpenFontFormatReader : Object { 		dis.close (); 	} 	-	public Glyph? read_glyph (string name) {-		try {-			return directory_table.glyf_table.read_glyph (name);-		} catch (GLib.Error e) {-			warning (e.message);-		}-		-		return null;-	}-	 	public void parse_index (string file_name) throws Error { 		file = File.new_for_path (file_name); 		if (!file.query_exists ()) {diff --git a/libbirdfont/PointConverter.vala b/libbirdfont/PointConverter.valaindex 9b56c89..858160e 100644--- a/libbirdfont/PointConverter.vala+++ b/libbirdfont/PointConverter.vala@@ -38,8 +38,6 @@ public class PointConverter { 			warning ("Too many points in segment."); 		} 	-		quadratic_path.remove_points_on_points ();- 		if (quadratic_path.points.size < 2) { 			return new Path (); 		}

Contact

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