Commit 88de344
Add Cmap subtable 0 for compability with Microsoft Word on Mac OS
Changed files (3)
modifiedlibbirdfont/OpenFontFormat/Cmap.valaaddedlibbirdfont/OpenFontFormat/CmapSubtableFormat0.valamodifiedlibbirdfont/OpenFontFormat/CmapSubtableFormat12.vala
Diff
@@ -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 ();new file mode 100644@@ -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; + }+}++}+@@ -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);