Clone in a terminal:
Commit a4afd74
Johan Mattsson - 2015-06-15T18:38:45+00:00
a4afd74309dce4f3a49a325bfa36607ce1aff2c9johan.mattsson.m@gmail.com

Generate mac specific truetype fonts

Changed files (5)

Diff

diff --git a/libbirdfont/ExportSettings.vala b/libbirdfont/ExportSettings.valaindex dc6cb48..550e3f9 100644--- a/libbirdfont/ExportSettings.vala+++ b/libbirdfont/ExportSettings.vala@@ -19,6 +19,7 @@ namespace BirdFont {  public class ExportSettings : TableLayout { 	TextArea file_name;+	TextArea file_name_mac; 	CheckBox ttf; 	CheckBox eot; 	CheckBox svg;@@ -54,7 +55,22 @@ public class ExportSettings : TableLayout { 		 		widgets.add (file_name); 		focus_ring.add (file_name);++		widgets.add (new Text (t_("File Name") + " Mac", label_size, label_margin));+		+		file_name_mac = new LineTextArea (label_size);+		file_name_mac.margin_bottom = margin; 		+		fn = get_file_name_mac (font);+		file_name_mac.set_text (fn);+		file_name_mac.text_changed.connect ((t) => {+			Font f = BirdFont.get_current_font ();+			f.settings.set_setting ("file_name_mac", t);+		});+		+		widgets.add (file_name_mac);+		focus_ring.add (file_name_mac);+ 		folder = (!) font.get_folder ().get_path (); 		Text folder_row = new Text (t_("Folder") + ": "  + folder, label_size, label_margin); 		folder_row.margin_bottom = 20 * MainWindow.units;@@ -120,6 +136,16 @@ public class ExportSettings : TableLayout { 		return n; 	} +	public static string get_file_name_mac (Font font) {+		string n = font.settings.get_setting ("file_name_mac");+		+		if (n == "") {+			n = font.full_name + " Mac";+		}+		+		return n;+	}+	 	public static bool export_ttf_setting (Font f) { 		return f.settings.get_setting ("export_ttf") != "false"; 	}diff --git a/libbirdfont/ExportTool.vala b/libbirdfont/ExportTool.valaindex f0c1ea4..9ef6603 100644--- a/libbirdfont/ExportTool.vala+++ b/libbirdfont/ExportTool.vala@@ -391,11 +391,13 @@ os.put_string ( 	public static bool export_ttf_font_path (File folder, bool use_export_settings = true) { 		Font current_font = BirdFont.get_current_font (); 		File ttf_file;+		File ttf_file_mac; 		File eot_file; 		bool done = true; 		 		try { 			ttf_file = get_child (folder, ExportSettings.get_file_name (current_font) + ".ttf");+			ttf_file_mac  = get_child (folder, ExportSettings.get_file_name_mac (current_font) + ".ttf"); 			eot_file = get_child (folder, ExportSettings.get_file_name (current_font) + ".eot");  			printd (@"Writing TTF fonts to $((!) ttf_file.get_path ())\n");@@ -404,11 +406,15 @@ os.put_string ( 				ttf_file.delete (); 			} +			if (ttf_file_mac.query_exists ()) {+				ttf_file_mac.delete ();+			}+			 			if (eot_file.query_exists ()) { 				eot_file.delete (); 			} 						-			write_ttf ((!) ttf_file.get_path ());+			write_ttf ((!) ttf_file.get_path (), (!) ttf_file_mac.get_path ()); 			 			if (!use_export_settings || ExportSettings.export_eot_setting (current_font)) { 				write_eot ((!) ttf_file.get_path (), (!) eot_file.get_path ());@@ -457,13 +463,14 @@ os.put_string ( 		return true; 	} -	static void write_ttf (string ttf) {+	static void write_ttf (string ttf, string ttf_mac) { 		OpenFontFormatWriter fo = new OpenFontFormatWriter (); 		Font f = BirdFont.get_current_font (); 		File file = (!) File.new_for_path (ttf);+		File file_mac = (!) File.new_for_path (ttf_mac); 		 		try {-			fo.open (file);+			fo.open (file, file_mac); 			fo.write_ttf_font (f); 			fo.close (); 		} catch (Error e) {diff --git a/libbirdfont/OpenFontFormat/DirectoryTable.vala b/libbirdfont/OpenFontFormat/DirectoryTable.valaindex f42bbd3..fd03a12 100644--- a/libbirdfont/OpenFontFormat/DirectoryTable.vala+++ b/libbirdfont/OpenFontFormat/DirectoryTable.vala@@ -1,5 +1,5 @@ /*-    Copyright (C) 2012, 2013, 2014 Johan Mattsson+    Copyright (C) 2012 2013 2014 Johan Mattsson      This library is free software; you can redistribute it and/or modify      it under the terms of the GNU Lesser General Public License as @@ -86,6 +86,12 @@ public class DirectoryTable : OtfTable { 		process_directory (); // this table 	} +	public void process_mac ()  throws GLib.Error {+		os_2_table.process_mac (glyf_table, hmtx_table);+		offset_table.process ();+		process_directory (); // this table+	}+ 	public Gee.ArrayList<OtfTable> get_tables () { 		if (tables.size == 0) { 			tables.add (offset_table);diff --git a/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala b/libbirdfont/OpenFontFormat/OpenFontFormatWriter.valaindex 5783eb9..eab770f 100644--- a/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala+++ b/libbirdfont/OpenFontFormat/OpenFontFormatWriter.vala@@ -17,6 +17,7 @@ namespace BirdFont { public class OpenFontFormatWriter : Object  {  	DataOutputStream os;+	DataOutputStream os_mac; 	DirectoryTable directory_table; 	 	public static Font font;@@ -29,15 +30,14 @@ public class OpenFontFormatWriter : Object  { 		return font; 	} 	-	public void open (File file) throws Error {-		assert (!is_null (file));-		-		if (file.query_exists ()) {+	public void open (File ttf, File ttf_mac) throws Error {+		if (ttf.query_exists () || ttf_mac.query_exists ()) { 			warning ("File exists in export."); 			throw new FileError.EXIST("OpenFontFormatWriter: file exists."); 		} 		-		os = new DataOutputStream(file.create (FileCreateFlags.REPLACE_DESTINATION));+		os = new DataOutputStream(ttf.create (FileCreateFlags.REPLACE_DESTINATION));+		os_mac = new DataOutputStream(ttf_mac.create (FileCreateFlags.REPLACE_DESTINATION)); 	} 	 	public void write_ttf_font (Font nfont) throws Error {@@ -49,7 +49,7 @@ public class OpenFontFormatWriter : Object  { 		 		font = nfont; 				-		directory_table.process ();	+		directory_table.process (); 		tables = directory_table.get_tables ();  		dl = directory_table.get_font_file_size ();@@ -68,10 +68,23 @@ public class OpenFontFormatWriter : Object  { 				os.put_byte (data[j]); 			} 		}+		+		directory_table.process_mac ();++		foreach (OtfTable t in tables) {+			fd = t.get_font_data ();+			data = fd.table_data;+			l = fd.length_with_padding ();+			+			for (int j = 0; j < l; j++) {+				os_mac.put_byte (data[j]);+			}+		} 	} 	 	public void close () throws Error { 		os.close ();+		os_mac.close (); 	} } diff --git a/libbirdfont/OpenFontFormat/Os2Table.vala b/libbirdfont/OpenFontFormat/Os2Table.valaindex 4d1ff1e..76f260a 100644--- a/libbirdfont/OpenFontFormat/Os2Table.vala+++ b/libbirdfont/OpenFontFormat/Os2Table.vala@@ -35,8 +35,16 @@ public class Os2Table : OtfTable { 	 	public override void parse (FontData dis) throws Error { 	}-	+ 	public void process (GlyfTable glyf_table, HmtxTable hmtx_table) {+		process_table (glyf_table, hmtx_table, false);+	}+	+	public void process_mac (GlyfTable glyf_table, HmtxTable hmtx_table) {+		process_table (glyf_table, hmtx_table, true);+	}+		+	public void process_table (GlyfTable glyf_table, HmtxTable hmtx_table, bool mac) { 		FontData fd = new FontData (); 		Font font = OpenFontFormatWriter.get_current_font (); 		int16 ascender;@@ -112,8 +120,7 @@ public class Os2Table : OtfTable { 		 		ascender = (int16) rint (font.top_limit * HeadTable.UNITS); 		descender = (int16) rint (font.bottom_limit * HeadTable.UNITS);--		+	 		fd.add_16 (ascender); // sTypoAscender 		fd.add_16 (descender); // sTypoDescender 		fd.add_16 (100); // sTypoLineGap@@ -128,9 +135,15 @@ public class Os2Table : OtfTable { 		} 		 		pages.get_pages (font, out codepage1, out codepage2);-		fd.add_u32 (codepage1); // ulCodePageRange1 Bits 0-31-		fd.add_u32 (codepage2); // ulCodePageRange2 Bits 32-63-+		+		if (mac) {+			fd.add_u32 (1); // ulCodePageRange1 Bits 0-31 (this value is only used fontbook) +			fd.add_u32 (0); // ulCodePageRange2 Bits 32-63			+		} else {+			fd.add_u32 (codepage1); // ulCodePageRange1 Bits 0-31 (this value is used by Word on Windows)+			fd.add_u32 (codepage2); // ulCodePageRange2 Bits 32-63+		}+		 		fd.add_16 (ascender); // sHeight 		fd.add_16 (ascender); // sCapHeight @@ -144,7 +157,6 @@ public class Os2Table : OtfTable { 	 		this.font_data = fd; 	}- }  }

Contact

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