Clone in a terminal:
Commit 88de344
Johan Mattsson - 2014-09-13T16:05:14+00:00
88de34422e8aa0ded42b2853807d9d8b9b45a90bjohan.mattsson.m@gmail.com

Add Cmap subtable 0 for compability with Microsoft Word on Mac OS

Changed files (3)

Diff

diff --git a/libbirdfont/OpenFontFormat/Cmap.vala b/libbirdfont/OpenFontFormat/Cmap.valaindex 8b44da3..a7ab5a9 100644--- a/libbirdfont/OpenFontFormat/Cmap.vala+++ b/libbirdfont/OpenFontFormat/Cmap.vala@@ -86,30 +86,38 @@ public class CmapTable : Table { 	/** Character to glyph mapping */ 	public void process (GlyfTable glyf_table) throws GLib.Error { 		FontData fd = new FontData ();+		FontData cmap0_data; 		FontData cmap4_data; 		FontData cmap12_data;+		CmapSubtableFormat0 cmap0 = new CmapSubtableFormat0 (); 		CmapSubtableFormat4 cmap4 = new CmapSubtableFormat4 (); 		CmapSubtableFormat12 cmap12 = new CmapSubtableFormat12 (); 		uint16 n_encoding_tables; 			+		cmap0_data = cmap0.get_cmap_data (glyf_table); 		cmap4_data = cmap4.get_cmap_data (glyf_table); 		cmap12_data = cmap12.get_cmap_data (glyf_table); 		-		n_encoding_tables = 2;+		n_encoding_tables = 3; 		 		fd.add_u16 (0); // table version 		fd.add_u16 (n_encoding_tables); 		 		fd.add_u16 (3); // platform  		fd.add_u16 (1); // encoding (Format Unicode UCS-4)-		fd.add_ulong (20); // subtable offseet+		fd.add_ulong (28); // subtable offseet  		fd.add_u16 (3); // platform  		fd.add_u16 (10); // encoding-		fd.add_ulong (20 + cmap4_data.length ()); // subtable offseet-		+		fd.add_ulong (28 + cmap4_data.length ()); // subtable offseet++		fd.add_u16 (1); // platform +		fd.add_u16 (0); // encoding+		fd.add_ulong (28 + cmap4_data.length () + cmap12_data.length ()); // subtable offseet+				 		fd.append (cmap4_data); 		fd.append (cmap12_data);+		fd.append (cmap0_data);  		// padding 		fd.pad ();diff --git a/libbirdfont/OpenFontFormat/CmapSubtableFormat0.vala b/libbirdfont/OpenFontFormat/CmapSubtableFormat0.valanew file mode 100644index 0000000..0894dae--- /dev/null+++ b/libbirdfont/OpenFontFormat/CmapSubtableFormat0.vala@@ -0,0 +1,50 @@+/*+    Copyright (C) 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 +    published by the Free Software Foundation; either version 3 of the +    License, or (at your option) any later version.++    This library is distributed in the hope that it will be useful, but +    WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +    Lesser General Public License for more details.+*/++namespace BirdFont {++/** Format 0 cmap subtable */+public class CmapSubtableFormat0 : GLib.Object {+	+	public CmapSubtableFormat0 () {+	}+	+	public FontData get_cmap_data (GlyfTable glyf_table) throws GLib.Error {+		FontData fd = new FontData ();+		+		fd.add_u16 (0); // Format+		fd.add_u16 (262); // Length+		fd.add_u16 (0); // language+		+		for (uint i = 0; i < 256; i++) {+			fd.add (get_gid_for_unichar ((unichar) i, glyf_table));+		}++		return fd;+	}+	+	uint8 get_gid_for_unichar (unichar c, GlyfTable glyf_table) {+		uint32 indice = 0;+		foreach (Glyph g in glyf_table.glyphs) {+			if (g.unichar_code == c) {+				return (indice <= uint8.MAX) ? (uint8) indice : 0;+			}+			indice++;+		}+		return 0;		+	}+}++}+diff --git a/libbirdfont/OpenFontFormat/CmapSubtableFormat12.vala b/libbirdfont/OpenFontFormat/CmapSubtableFormat12.valaindex 8f9b9a0..cb5819d 100644--- a/libbirdfont/OpenFontFormat/CmapSubtableFormat12.vala+++ b/libbirdfont/OpenFontFormat/CmapSubtableFormat12.vala@@ -46,8 +46,8 @@ public class CmapSubtableFormat12 : GLib.Object { 		indice = first_assigned; 		foreach (UniRange u in ranges) { 			-			if (u.start >= 0xFFFFFFFF) {-				warning ("Glytph range not supported by CmapSubtableFormat12.");+			if (u.start >= 0xFFFFFFFF || u.stop >= 0xFFFFFFFF) {+				warning ("Glyph range not supported by CmapSubtableFormat12."); 			} else { 				fd.add_u32 (u.start); 				fd.add_u32 (u.stop);

Contact

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