diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2013-11-27 22:47:35 -0500 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2013-11-28 17:32:43 -0500 |
commit | 6962f0cfb2b7edfcfa1ff291e99fec756f06c6f8 (patch) | |
tree | 225626afcd188489a31c2ccf7287333fb8b0f714 /Lib/fontTools/ttLib/tables/_n_a_m_e.py | |
parent | 5f6418d9e1fa15a89dcec29cdc433ba2c99732c3 (diff) | |
download | fonttools-6962f0cfb2b7edfcfa1ff291e99fec756f06c6f8.tar.gz |
py23 XML encoding fixes
Name table entries that are Unicode are written out as native Unicode
now text in the XML now.
Diffstat (limited to 'Lib/fontTools/ttLib/tables/_n_a_m_e.py')
-rw-r--r-- | Lib/fontTools/ttLib/tables/_n_a_m_e.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py index 12a09646..001f74f9 100644 --- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py +++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py @@ -60,6 +60,7 @@ class table__n_a_m_e(DefaultTable.DefaultTable): if name.string in done: name.offset, name.length = done[name.string] else: + # TODO Convert to UTF-16? name.offset, name.length = done[name.string] = len(stringData), len(name.string) stringData = stringData + name.string data = data + sstruct.pack(nameRecordFormat, name) @@ -98,13 +99,13 @@ class NameRecord: ("langID", hex(self.langID)), ]) writer.newline() - if self.platformID == 0 or (self.platformID == 3 and self.platEncID in (0, 1)): + if self.platformID == 0 or (self.platformID == 3 and self.platEncID in (0, 1, 10)): + string = self.string if len(self.string) % 2: # no, shouldn't happen, but some of the Apple # tools cause this anyway :-( - writer.write16bit(self.string + "\0") - else: - writer.write16bit(self.string) + string = string + b'\0' + writer.writeutf16be(string) else: writer.write8bit(self.string) writer.newline() @@ -117,9 +118,11 @@ class NameRecord: self.platEncID = safeEval(attrs["platEncID"]) self.langID = safeEval(attrs["langID"]) s = strjoin(content).strip() - if self.platformID == 0 or (self.platformID == 3 and self.platEncID in (0, 1)): - self.string = s.encode("utf_16_be") + if self.platformID == 0 or (self.platformID == 3 and self.platEncID in (0, 1, 10)): + # This is the inverse of writeutf16be. + self.string = s.encode("utf-16-be") else: + # This is the inverse of write8bit... self.string = s.encode("latin1") def __lt__(self, other): |