The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Create name table entry in macroman encoding for old applications

These changes was commited to the Birdfont repository Sun, 23 Aug 2015 10:09:38 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 23 Aug 2015 10:09:38 +0000 (12:09 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 23 Aug 2015 10:09:38 +0000 (12:09 +0200)
commit 7ccd8f7ab8264bcdcad52846db7a8befdb8ef668
tree 316489560779b97e3989c07a94c482a5b03989cf
parent 6a94dbec5504461b4ddb1564a4c163c32d27c986
Create name table entry in macroman encoding for old applications

libbirdfont/OpenFontFormat/FontData.vala
libbirdfont/OpenFontFormat/NameTable.vala
--- a/libbirdfont/OpenFontFormat/FontData.vala +++ b/libbirdfont/OpenFontFormat/FontData.vala @@ -354,15 +354,47 @@ // FIXME: gconvert it instead. while (s.get_next_char (ref index, out c)) { - c0 = (uint8) (c >> 8); - c1 = (uint8) (c - (c0 << 8)); - - if (little_endian) { - add (c1); - add (c0); + if (c < 0xFFFF - (1 << 16)) { + c0 = (uint8) (c >> 8); + c1 = (uint8) (c - (c0 << 8)); + + if (little_endian) { + add (c1); + add (c0); + } else { + add (c0); + add (c1); + } + } else if (c < 0xFFFF - (1 << 16)) { + int high = (0xFFC00 & c) >> 10; + int low = (0x03FF & c); + + high += 0xD800; + low += 0xDC00; + + c0 = (uint8) (high >> 8); + c1 = (uint8) (high - (c0 << 8)); + + if (little_endian) { + add (c1); + add (c0); + } else { + add (c0); + add (c1); + } + + c0 = (uint8) (low >> 8); + c1 = (uint8) (low - (c0 << 8)); + + if (little_endian) { + add (c1); + add (c0); + } else { + add (c0); + add (c1); + } } else { - add (c0); - add (c1); + continue; } l += 2; @@ -371,6 +403,31 @@ assert (l == 2 * s.char_count ()); } + public static uint utf16_strlen (string s) { + FontData fd = new FontData (); + fd.add_str_utf16 (s); + return fd.length_with_padding (); + } + + public void add_macroman_str (string s) { + int index = 0; + unichar c; + + while (s.get_next_char (ref index, out c)) { + if (32 <= c <= 127) { + add ((uint8) c); + } + + // FIXME: add other macroman characters + } + } + + public static uint macroman_strlen (string s) { + FontData fd = new FontData (); + fd.add_macroman_str (s); + return fd.length_with_padding (); + } + public void add_str (string s) { uint8[] data = s.data; for (int n = 0; n < data.length; n++) {
--- a/libbirdfont/OpenFontFormat/NameTable.vala +++ b/libbirdfont/OpenFontFormat/NameTable.vala @@ -250,7 +250,7 @@ for (int i = 0; i < num_records; i++) { t = (!) text.get (i); p = (!) type.get (i); - l = (uint16) t.length; + l = (uint16) FontData.macroman_strlen (t); fd.add_ushort (1); // platform fd.add_ushort (0); // encoding id @@ -264,7 +264,7 @@ for (int i = 0; i < num_records; i++) { t = (!) text.get (i); p = (!) type.get (i); - l = (uint16) (2 * t.char_count ()); // FIXME: handle UTF-16 in a better way, gconvert it. + l = (uint16) FontData.utf16_strlen (t); fd.add_ushort (3); // platform fd.add_ushort (1); // encoding id @@ -277,7 +277,7 @@ // platform 1 foreach (string s in text) { - fd.add_str (s); + fd.add_macroman_str (s); } // platform 3