The Birdfont Source Code
Fix errors in cmap subtable 4
These changes was commited to the Birdfont repository Sun, 06 Dec 2015 14:24:15 +0000.
Contributing
Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Fix errors in cmap subtable 4
--- a/libbirdfont/Font.vala
+++ b/libbirdfont/Font.vala
@@ -492,7 +492,7 @@
gc = new GlyphCollection (' ', "space");
- n = new Glyph ("space", ' ');
+ n = new Glyph (" ", ' ');
n.left_limit = 0;
n.right_limit = 27;
n.remove_empty_paths ();
--- a/libbirdfont/OpenFontFormat/Cmap.vala
+++ b/libbirdfont/OpenFontFormat/Cmap.vala
@@ -11,6 +11,7 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
+ using Gee;
namespace BirdFont {
@@ -86,40 +87,37 @@
/** 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);
+ ArrayList<CmapSubtable> cmap_tables = new ArrayList<CmapSubtable> ();
- n_encoding_tables = 3;
+ cmap0.generate_cmap_data (glyf_table);
+ cmap4.generate_cmap_data (glyf_table);
+ cmap12.generate_cmap_data (glyf_table);
+
+ cmap_tables.add(cmap0);
+ cmap_tables.add(cmap4);
+ cmap_tables.add(cmap12);
+
+ n_encoding_tables = (uint16) cmap_tables.size;
fd.add_u16 (0); // table version
fd.add_u16 (n_encoding_tables);
- fd.add_u16 (1); // platform
- fd.add_u16 (0); // encoding
- fd.add_ulong (28); // subtable offseet
+ uint subtable_offset = 4 + 8 * cmap_tables.size;
+ foreach (CmapSubtable subtable in cmap_tables) {
+ fd.add_u16 (subtable.get_platform ());
+ fd.add_u16 (subtable.get_encoding ());
+ fd.add_ulong (subtable_offset);
+ subtable_offset += subtable.get_cmap_data ().length ();
+ }
- fd.add_u16 (3); // platform
- fd.add_u16 (1); // encoding (Format Unicode UCS-4)
- fd.add_ulong (28 + cmap0_data.length ()); // subtable offseet
-
- fd.add_u16 (3); // platform
- fd.add_u16 (10); // encoding
- fd.add_ulong (28 + cmap0_data.length () + cmap4_data.length ()); // subtable offseet
-
- fd.append (cmap0_data);
- fd.append (cmap4_data);
- fd.append (cmap12_data);
+ foreach (CmapSubtable subtable in cmap_tables) {
+ fd.append (subtable.get_cmap_data ());
+ }
- // padding
fd.pad ();
this.font_data = fd;
--- /dev/null
+++ b/libbirdfont/OpenFontFormat/CmapSubtable.vala
@@ -1,1 +1,28 @@
+ /*
+ Copyright (C) 2015 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 {
+
+ public abstract class CmapSubtable : GLib.Object {
+ public abstract ushort get_platform ();
+ public abstract ushort get_encoding ();
+
+ public abstract void generate_cmap_data (GlyfTable glyf_table)
+ throws GLib.Error;
+
+ public abstract FontData get_cmap_data ();
+ }
+
+ }
--- a/libbirdfont/OpenFontFormat/CmapSubtableFormat0.vala
+++ b/libbirdfont/OpenFontFormat/CmapSubtableFormat0.vala
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014 Johan Mattsson
+ Copyright (C) 2014 2015 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
@@ -15,23 +15,37 @@
namespace BirdFont {
/** Format 0 cmap subtable */
- public class CmapSubtableFormat0 : GLib.Object {
+ public class CmapSubtableFormat0 : CmapSubtable {
+ FontData cmap_data = new FontData ();
public CmapSubtableFormat0 () {
}
- public FontData get_cmap_data (GlyfTable glyf_table) throws GLib.Error {
+ public override ushort get_platform () {
+ return 1;
+ }
+
+ public override ushort get_encoding () {
+ return 0;
+ }
+
+ public override FontData get_cmap_data () {
+ return cmap_data;
+ }
+
+ public override void generate_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
+ fd.add_u16 (0); // Language
for (uint i = 0; i < 256; i++) {
fd.add (get_gid_for_unichar ((unichar) i, glyf_table));
}
- return fd;
+ cmap_data = fd;
}
uint8 get_gid_for_unichar (unichar c, GlyfTable glyf_table) {
--- a/libbirdfont/OpenFontFormat/CmapSubtableFormat12.vala
+++ b/libbirdfont/OpenFontFormat/CmapSubtableFormat12.vala
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012, 2013, 2014 Johan Mattsson
+ Copyright (C) 2012 2013 2014 2015 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
@@ -15,12 +15,26 @@
namespace BirdFont {
/** Format 12 cmap subtable */
- public class CmapSubtableFormat12 : GLib.Object {
+ public class CmapSubtableFormat12 : CmapSubtable {
+
+ FontData cmap_data;
public CmapSubtableFormat12 () {
+ }
+
+ public override ushort get_platform () {
+ return 3;
+ }
+
+ public override ushort get_encoding () {
+ return 10;
+ }
+
+ public override FontData get_cmap_data () {
+ return cmap_data;
}
- public FontData get_cmap_data (GlyfTable glyf_table) throws GLib.Error {
+ public override void generate_cmap_data (GlyfTable glyf_table) throws GLib.Error {
GlyphRange glyph_range = new GlyphRange ();
Gee.ArrayList<UniRange> ranges;
FontData fd = new FontData ();
@@ -59,9 +73,9 @@
}
}
- return fd;
+ cmap_data = fd;
}
}
}
--- a/libbirdfont/OpenFontFormat/CmapSubtableFormat4.vala
+++ b/libbirdfont/OpenFontFormat/CmapSubtableFormat4.vala
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012, 2013, 2014 Johan Mattsson
+ Copyright (C) 2012 2013 2014 2015 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
@@ -15,16 +15,29 @@
namespace BirdFont {
/** Format 4 cmap subtable */
- public class CmapSubtableFormat4 : GLib.Object {
+ public class CmapSubtableFormat4 : CmapSubtable {
public uint32 offset;
uint16 format = 0;
HashTable <uint64?, unichar> table = new HashTable <uint64?, unichar> (int64_hash, int_equal);
uint16 length = 0;
+ FontData cmap_data = new FontData ();
public CmapSubtableFormat4 () {
}
+ public override ushort get_platform () {
+ return 3;
+ }
+
+ public override ushort get_encoding () {
+ return 1;
+ }
+
+ public override FontData get_cmap_data () {
+ return cmap_data;
+ }
+
public uint get_length () {
return table.size ();
}
@@ -174,7 +187,7 @@
if (glyph_id_array != null) delete glyph_id_array;
}
- public FontData get_cmap_data (GlyfTable glyf_table) throws GLib.Error {
+ public override void generate_cmap_data (GlyfTable glyf_table) throws GLib.Error {
FontData fd = new FontData ();
GlyphRange glyph_range = new GlyphRange ();
Gee.ArrayList<UniRange> ranges;
@@ -190,8 +203,7 @@
uint32 index;
uint32 first_assigned;
- first_assigned = 1;
-
+ first_assigned = 1;
foreach (GlyphCollection g in glyf_table.glyphs) {
if (!g.is_unassigned () && g.get_unicode_character () < 0xFFFF) {
glyph_range.add_single (g.get_unicode_character ());
@@ -234,7 +246,7 @@
fd.add_ushort (0); // Reserved
// start codes
- index = first_assigned; // since first glyph are notdef, null and nonmarkingreturn
+ index = first_assigned;
foreach (UniRange u in ranges) {
if (u.start >= 0xFFFF) {
warning ("Not implemented yet.");
@@ -251,7 +263,7 @@
if ((u.start - index) > 0xFFFF && u.start > index) {
warning ("Need range offset.");
} else {
- fd.add_ushort ((uint16) (index - u.start));
+ fd.add_short ((int16) (index - u.start));
index += u.length ();
}
}
@@ -269,9 +281,9 @@
// FIXME: implement the rest of type 4 (mind gid_length in length field)
- return fd;
+ cmap_data = fd;
}
}
}
--- a/libbirdfont/OpenFontFormat/Os2Table.vala
+++ b/libbirdfont/OpenFontFormat/Os2Table.vala
@@ -141,7 +141,7 @@
// usWinDescent (not like sTypoDescender)
win_descent = hhea_table.get_windescent ();
if (win_descent < 0) {
- warning (@"usWinDescent is unsigned, can not write $(-win_descent) to the field.");
+ warning (@"usWinDescent is unsigned, can not write $(win_descent) to the field.");
fd.add_u16 (0);
} else {
fd.add_u16 (-win_descent);