Clone in a terminal:
Commit 03541fb
Johan Mattsson - 2013-08-31T15:09:32+00:00
03541fb6a8b0b1de70ce7f19174ebb493f3aaf6ejohan.mattsson.m@gmail.com

truncate kerning table and set word wrap in text areas

Changed files (5)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 0b2724a..ac5b96c 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -1201,6 +1201,7 @@ public class DescriptionForm : GLib.Object { 			Font f = BirdFont.get_current_font (); 			f.description = description.get_buffer ().text; 		});+		description.set_wrap_mode (Gtk.WrapMode.WORD);  		copyright = new TextView (); 		add_textview (copyright, _("Copyright"));@@ -1208,6 +1209,7 @@ public class DescriptionForm : GLib.Object { 			Font f = BirdFont.get_current_font (); 			f.copyright = copyright.get_buffer ().text; 		});+		copyright.set_wrap_mode (Gtk.WrapMode.WORD); 		 		update_fields (); 		@@ -1217,13 +1219,23 @@ public class DescriptionForm : GLib.Object { 	 	public void update_fields () { 		Font font = BirdFont.get_current_font ();++		return_if_fail (font.postscript_name.validate ());+		return_if_fail (font.name.validate ());+		return_if_fail (font.subfamily.validate ());+		return_if_fail (font.full_name.validate ());+		return_if_fail (font.unique_identifier.validate ());+		return_if_fail (font.version.validate ());+		return_if_fail (font.description.validate ());+		return_if_fail (font.copyright.validate ());+		 		postscript_name.set_text (font.postscript_name); 		font_name.set_text (font.name); 		style.set_text (font.subfamily); 		full_name.set_text (font.full_name); 		id.set_text (font.unique_identifier); 		version.set_text (font.version);-		+ 		description.get_buffer ().set_text (font.description.dup ()); 		copyright.get_buffer ().set_text (font.copyright.dup ()); 	}diff --git a/libbirdfont/FileTab.vala b/libbirdfont/FileTab.valaindex d5b927b..996dbb0 100644--- a/libbirdfont/FileTab.vala+++ b/libbirdfont/FileTab.vala@@ -293,6 +293,11 @@ public class FileTab : FontDisplay { 	public override void selected_canvas () { 		update_recent_files (); 		update_scrollbar ();+		+		while (backups.length () != 0) {+			backups.delete_link (backups.first ());+		}+		 		backups = get_backups (); 		redraw_area (0, 0, allocation.width, allocation.height); 	}diff --git a/libbirdfont/OpenFontFormat/GposTable.vala b/libbirdfont/OpenFontFormat/GposTable.valaindex c35bd92..d8b3a15 100644--- a/libbirdfont/OpenFontFormat/GposTable.vala+++ b/libbirdfont/OpenFontFormat/GposTable.vala@@ -92,27 +92,28 @@ class GposTable : Table { 	FontData get_pair_pos_format1 () throws GLib.Error { 		FontData fd = new FontData (); 		uint16 pair_set_count;+		uint coverage_offset = 10 + pairs_offset_length () + pairs_set_length (); 		 		create_kerning_pairs (); 		 		// FIXME: add more then current maximum of pairs 		-		if (pairs.length () > uint16.MAX) {+		if (pairs.length () > uint16.MAX || coverage_offset > uint16.MAX) { 			print_pairs ();-			warning ("Too many kerning pairs.");+			warning (@"Too many kerning pairs. $(pairs.length ())"); 		} 		 		pair_set_count = (uint16) pairs.length (); 			 		fd.add_ushort (1); // position format 		// offset to coverage table from beginning of kern pair table-		fd.add_ushort (10 + pairs_offset_length () + pairs_set_length ());  +		fd.add_ushort ((uint16) coverage_offset);   		fd.add_ushort (0x0004); // ValueFormat1 (0x0004 is x advance) 		fd.add_ushort (0); // ValueFormat2 (0 is null) 		fd.add_ushort (pair_set_count); // n pairs 		 		// pair offsets orderd by coverage index-		int pair_set_offset = 10 + pairs_offset_length ();+		uint pair_set_offset = 10 + pairs_offset_length (); 		foreach (PairFormat1 k in pairs) { 			fd.add_ushort ((uint16) pair_set_offset); 			pair_set_offset += 2;@@ -154,23 +155,16 @@ class GposTable : Table { 		} 	} 	-	public int pairs_set_length () {-		int len = 0;+	public uint pairs_set_length () {+		uint len = 0; 		foreach (PairFormat1 p in pairs) {-			len += 2;-			foreach (Kern k in p.pairs) {-				len += 4;-			}+			len += 2 + 4 * p.pairs.length (); 		} 		return len; 	} 	-	public int pairs_offset_length () {-		int len = 0;-		foreach (PairFormat1 k in pairs) {-			len += 2;-		}-		return len;+	public uint pairs_offset_length () {+		return 2 * pairs.length (); 	}  	public int get_pair_index (int gid) {diff --git a/libbirdfont/OpenFontFormat/NameTable.vala b/libbirdfont/OpenFontFormat/NameTable.valaindex 45f4d50..f075811 100644--- a/libbirdfont/OpenFontFormat/NameTable.vala+++ b/libbirdfont/OpenFontFormat/NameTable.vala@@ -211,7 +211,9 @@ class NameTable : Table {  		// platform 1 		foreach (string s in text) {-			fd.add_str (s); +			fd.add_str (s);+			print (s);+			print ("\n"); 		} 		 		// platform 3diff --git a/libbirdfont/OpenFontFormat/load_font.c b/libbirdfont/OpenFontFormat/load_font.cindex b80d08e..ea4cf0f 100644--- a/libbirdfont/OpenFontFormat/load_font.c+++ b/libbirdfont/OpenFontFormat/load_font.c@@ -201,7 +201,7 @@ void create_contour (guint unicode, FT_Vector* points, char* flags, int* length, 			prev_is_curve = FALSE; 			f[j] = CUBIC_CURVE; 		} else {-			fprintf (stderr, "WARNING invalid point flags: %d index: %d.\n", flags[i], i);+			g_warning ("WARNING invalid point flags: %d index: %d.\n", flags[i], i); 			prev_is_curve = FALSE; 			f[j] = ON_CURVE; 		}@@ -512,7 +512,7 @@ GString* get_bf_contour_data (guint unicode, FT_Vector* points, char* flags, int 			i += 1; 		} else { 			g_string_printf (contour, "");-			fprintf (stderr, "WARNING Can not parse outline.\n");+			g_warning ("WARNING Can not parse outline.\n"); 			*err = 1; 			i++; 		}@@ -588,25 +588,25 @@ GString* get_kerning_data (FT_Face face, FT_Long gid, double units) { 	char_left = get_charcode (face, gid); 	 	if (char_left <= 31) {-		fprintf (stderr, "Ignoring kerning for control character.\n");+		g_warning ("Ignoring kerning for control character.\n"); 		return bf; 	} 	 	if (char_left == 0) {-		fprintf (stderr, "No character code could be found for left kerning value.\n");+		g_warning ("No character code could be found for left kerning value.\n"); 		return bf; 	} 	 	for (right = 0; right < face->num_glyphs; right++) { 		error = FT_Get_Kerning (face, gid, right, FT_KERNING_UNSCALED, &kerning); 		if (error) {-			fprintf (stderr, "Failed to obtain kerning value.\n");+			g_warning ("Failed to obtain kerning value.\n"); 			break; 		} 		 		char_right = get_charcode (face, right); 		if (char_left == 0) {-			fprintf (stderr, "No character code could be found for right kerning value.\n");+			g_warning ("No character code could be found for right kerning value.\n"); 			return bf; 		} @@ -627,7 +627,7 @@ int get_height (FT_Face face, guint unichar) {  	error = FT_Load_Glyph (face, index, FT_LOAD_DEFAULT | FT_LOAD_NO_SCALE); 	if (error) {-		fprintf (stderr, "Failed to obtain height. (%d)\n", error);+		g_warning ("Failed to obtain height. (%d)\n", error); 		return 0; 	} 		@@ -653,7 +653,7 @@ int get_descender (FT_Face face) { 	 	error = FT_Load_Glyph (face, index, FT_LOAD_DEFAULT | FT_LOAD_NO_SCALE); 	if (error) {-		fprintf (stderr, "Failed to obtain descender. (%d)\n", error);+		g_warning ("Failed to obtain descender. (%d)\n", error); 		return 0; 	} 	@@ -672,17 +672,27 @@ void append_description (GString* str, FT_SfntName* name_table_data) { 	if (name_table_data->encoding_id == 0) { 		g_string_append_len (str, name_table_data->string, name_table_data->string_len); 	} else if (name_table_data->encoding_id == 1) {-		utf8_str = g_convert (name_table_data->string, name_table_data->string_len, "utf-8", "ucs-2", &read, &written, &error);+		+		// Unicode BMP (UCS-2) is the right encoding+		// utf8_str = g_convert (name_table_data->string, name_table_data->string_len, "utf-8", "ucs-2", &read, &written, &error);+		+		g_warning ("CONVERT");+		+		// DELETE utf-16be+		utf8_str = g_convert (name_table_data->string, name_table_data->string_len, "utf-8", "ucs-2be", &read, &written, &error);+ 		if (error == NULL) { 			g_string_append (str, utf8_str); 			g_free (utf8_str); 		} else {-			fprintf (stderr, "Error in append_description: %s\n", error->message);+			g_warning ("Error in append_description: %s\n", error->message); 			g_error_free (error); 		} 	} else {-		fprintf (stderr, "Encoding %u is not supported.\n", name_table_data->encoding_id);+		g_warning ("Encoding %u is not supported.\n", name_table_data->encoding_id); 	}+	+	g_warning ("name_table_data->encoding_id: %d, plat: %d str: %s \n", name_table_data->encoding_id, name_table_data->platform_id, str->str);	 }  /** Convert font to bf format.@@ -765,14 +775,14 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { 	for (i = 0; i < face->num_glyphs; i++) { 		error = FT_Load_Glyph (face, i, FT_LOAD_DEFAULT | FT_LOAD_NO_SCALE); 		if (error) {-			fprintf (stderr, "Freetype failed to load glyph %d.\n", (int)i);-			fprintf (stderr, "FT_Load_Glyph error %d\n", error);+			g_warning ("Freetype failed to load glyph %d.\n", (int)i);+			g_warning ("FT_Load_Glyph error %d\n", error); 			*err = error; 			return bf; 		}  		if (face->glyph->format != ft_glyph_format_outline) {-			fprintf (stderr, "Freetype error no outline found in glyph.\n");+			g_warning ("Freetype error no outline found in glyph.\n"); 			*err = 1; 			return bf; 		}@@ -823,7 +833,7 @@ int validate_font (FT_Face face) { 	error = FT_OpenType_Validate (face, FT_VALIDATE_BASE | FT_VALIDATE_GDEF | FT_VALIDATE_GPOS | FT_VALIDATE_GSUB | FT_VALIDATE_JSTF, &BASE_table, &GDEF_table, &GPOS_table, &GSUB_table, &JSTF_table);  	if (error) {-		fprintf (stderr, "Freetype validation error %d\n", error);+		g_warning ("Freetype validation error %d\n", error); 		return error; 	}  	@@ -850,28 +860,28 @@ GString* load_freetype_font (char* file, int* err) {  	error = FT_Init_FreeType (&library); 	if (error != OK) {-		fprintf (stderr, "Freetype init error %d.\n", error);+		g_warning ("Freetype init error %d.\n", error); 		*err = error; 		return bf; 	}  	error = FT_New_Face (library, file, 0, &face); 	if (error) {-		fprintf (stderr, "Freetype font face error %d\n", error);+		g_warning ("Freetype font face error %d\n", error); 		*err = error; 		return bf; 	}  	error = FT_Set_Char_Size (face, 0, 800, 300, 300); 	if (error) {-		fprintf (stderr, "Freetype FT_Set_Char_Size failed, error: %d.\n", error);+		g_warning ("Freetype FT_Set_Char_Size failed, error: %d.\n", error); 		*err = error; 		return bf; 	}  	bf = get_bf_font (face, file, &error); 	if (error != OK) {-		fprintf (stderr, "Failed to parse font.\n");+		g_warning ("Failed to parse font.\n"); 		*err = error; 		return bf;	 	}@@ -891,19 +901,19 @@ guint validate_freetype_font (char* file) { 	 	error = FT_Init_FreeType (&library); 	if (error != OK) {-		fprintf (stderr, "Freetype init error %d\n", error);+		g_warning ("Freetype init error %d\n", error); 		return FALSE; 	}  	error = FT_New_Face (library, file, 0, &face); 	if (error) {-		fprintf (stderr, "Freetype font face error %d\n", error);+		g_warning ("Freetype font face error %d\n", error); 		return FALSE; 	} 		 	error = validate_font (face); 	if (error) {-		fprintf (stderr, "Validation failed.\n", error);+		g_warning ("Validation failed.\n", error); 		return FALSE; 	} 

Contact

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