From abf7dc65681ff66b201c66b0a3213bbccb7c5dcf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 22 Apr 2015 01:12:05 -0700 Subject: [PATCH] If Unicode-compatible name failed to decode, write unicode="False" --- Lib/fontTools/ttLib/tables/_n_a_m_e.py | 2 +- Lib/fontTools/ttLib/tables/_n_a_m_e_test.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py index 187536c61..6856bb9a1 100644 --- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py +++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py @@ -152,7 +152,7 @@ class NameRecord(object): ("langID", hex(self.langID)), ] - if not self.encodingIsUnicodeCompatible(): + if unistr is None or not self.encodingIsUnicodeCompatible(): attrs.append(("unicode", unistr is not None)) writer.begintag("namerecord", attrs) diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e_test.py b/Lib/fontTools/ttLib/tables/_n_a_m_e_test.py index 380a3068a..93772dae9 100644 --- a/Lib/fontTools/ttLib/tables/_n_a_m_e_test.py +++ b/Lib/fontTools/ttLib/tables/_n_a_m_e_test.py @@ -47,6 +47,14 @@ class NameRecordTest(unittest.TestCase): '' ], self.toXML(name)) + def test_toXML_utf16be_broken(self): + name = self.makeName(b"\0F\0o\0o\0", 111, 0, 2, 7) + self.assertEqual([ + '', + ' �F�o�o�', + '' + ], self.toXML(name)) + def test_toXML_macroman(self): name = self.makeName("Foo Italic", 222, 1, 0, 7) # MacRoman self.assertEqual([