Use utf_16_be instead of utf_16be
That's the canonical name. https://github.com/behdad/fonttools/issues/236
This commit is contained in:
parent
0ac019ca2c
commit
cc072eca9f
@ -8,13 +8,13 @@ import fontTools.encodings.codecs
|
|||||||
# Map keyed by platformID, then platEncID, then possibly langID
|
# Map keyed by platformID, then platEncID, then possibly langID
|
||||||
_encodingMap = {
|
_encodingMap = {
|
||||||
0: { # Unicode
|
0: { # Unicode
|
||||||
0: 'utf_16be',
|
0: 'utf_16_be',
|
||||||
1: 'utf_16be',
|
1: 'utf_16_be',
|
||||||
2: 'utf_16be',
|
2: 'utf_16_be',
|
||||||
3: 'utf_16be',
|
3: 'utf_16_be',
|
||||||
4: 'utf_16be',
|
4: 'utf_16_be',
|
||||||
5: 'utf_16be',
|
5: 'utf_16_be',
|
||||||
6: 'utf_16be',
|
6: 'utf_16_be',
|
||||||
},
|
},
|
||||||
1: { # Macintosh
|
1: { # Macintosh
|
||||||
# See
|
# See
|
||||||
@ -47,18 +47,18 @@ _encodingMap = {
|
|||||||
},
|
},
|
||||||
2: { # ISO
|
2: { # ISO
|
||||||
0: 'ascii',
|
0: 'ascii',
|
||||||
1: 'utf_16be',
|
1: 'utf_16_be',
|
||||||
2: 'latin1',
|
2: 'latin1',
|
||||||
},
|
},
|
||||||
3: { # Microsoft
|
3: { # Microsoft
|
||||||
0: 'utf_16be',
|
0: 'utf_16_be',
|
||||||
1: 'utf_16be',
|
1: 'utf_16_be',
|
||||||
2: 'shift_jis',
|
2: 'shift_jis',
|
||||||
3: 'gb2312',
|
3: 'gb2312',
|
||||||
4: 'big5',
|
4: 'big5',
|
||||||
5: 'euc_kr',
|
5: 'euc_kr',
|
||||||
6: 'johab',
|
6: 'johab',
|
||||||
10: 'utf_16be',
|
10: 'utf_16_be',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,10 +7,10 @@ class EncodingTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_encoding_unicode(self):
|
def test_encoding_unicode(self):
|
||||||
|
|
||||||
self.assertEqual(getEncoding(3, 0, None), "utf_16be") # MS Symbol is Unicode as well
|
self.assertEqual(getEncoding(3, 0, None), "utf_16_be") # MS Symbol is Unicode as well
|
||||||
self.assertEqual(getEncoding(3, 1, None), "utf_16be")
|
self.assertEqual(getEncoding(3, 1, None), "utf_16_be")
|
||||||
self.assertEqual(getEncoding(3, 10, None), "utf_16be")
|
self.assertEqual(getEncoding(3, 10, None), "utf_16_be")
|
||||||
self.assertEqual(getEncoding(0, 3, None), "utf_16be")
|
self.assertEqual(getEncoding(0, 3, None), "utf_16_be")
|
||||||
|
|
||||||
def test_encoding_macroman_misc(self):
|
def test_encoding_macroman_misc(self):
|
||||||
self.assertEqual(getEncoding(1, 0, 17), "mac_turkish")
|
self.assertEqual(getEncoding(1, 0, 17), "mac_turkish")
|
||||||
|
@ -2191,9 +2191,9 @@ def prune_pre_subset(self, options):
|
|||||||
namerecs = []
|
namerecs = []
|
||||||
for n in self.names:
|
for n in self.names:
|
||||||
if n.nameID in [1, 4]:
|
if n.nameID in [1, 4]:
|
||||||
n.string = ".\x7f".encode('utf_16be') if n.isUnicode() else ".\x7f"
|
n.string = ".\x7f".encode('utf_16_be') if n.isUnicode() else ".\x7f"
|
||||||
elif n.nameID in [2, 6]:
|
elif n.nameID in [2, 6]:
|
||||||
n.string = "\x7f".encode('utf_16be') if n.isUnicode() else "\x7f"
|
n.string = "\x7f".encode('utf_16_be') if n.isUnicode() else "\x7f"
|
||||||
elif n.nameID == 3:
|
elif n.nameID == 3:
|
||||||
n.string = ""
|
n.string = ""
|
||||||
elif n.nameID in [16, 17, 18]:
|
elif n.nameID in [16, 17, 18]:
|
||||||
|
@ -12,7 +12,7 @@ class CmapSubtableTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_toUnicode_utf16be(self):
|
def test_toUnicode_utf16be(self):
|
||||||
subtable = self.makeSubtable(0, 2, 7)
|
subtable = self.makeSubtable(0, 2, 7)
|
||||||
self.assertEqual("utf_16be", subtable.getEncoding())
|
self.assertEqual("utf_16_be", subtable.getEncoding())
|
||||||
self.assertEqual(True, subtable.isUnicode())
|
self.assertEqual(True, subtable.isUnicode())
|
||||||
|
|
||||||
def test_toUnicode_macroman(self):
|
def test_toUnicode_macroman(self):
|
||||||
|
@ -102,7 +102,7 @@ class NameRecord(object):
|
|||||||
return getEncoding(self.platformID, self.platEncID, self.langID, default)
|
return getEncoding(self.platformID, self.platEncID, self.langID, default)
|
||||||
|
|
||||||
def encodingIsUnicodeCompatible(self):
|
def encodingIsUnicodeCompatible(self):
|
||||||
return self.getEncoding(None) in ['utf_16be', 'ucs2be', 'ascii', 'latin1']
|
return self.getEncoding(None) in ['utf_16_be', 'ucs2be', 'ascii', 'latin1']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
try:
|
try:
|
||||||
@ -138,7 +138,7 @@ class NameRecord(object):
|
|||||||
encoding = self.getEncoding()
|
encoding = self.getEncoding()
|
||||||
string = self.string
|
string = self.string
|
||||||
|
|
||||||
if encoding == 'utf_16be' and len(string) % 2 == 1:
|
if encoding == 'utf_16_be' and len(string) % 2 == 1:
|
||||||
# Recover badly encoded UTF-16 strings that have an odd number of bytes:
|
# Recover badly encoded UTF-16 strings that have an odd number of bytes:
|
||||||
# - If the last byte is zero, drop it. Otherwise,
|
# - If the last byte is zero, drop it. Otherwise,
|
||||||
# - If all the odd bytes are zero and all the even bytes are ASCII,
|
# - If all the odd bytes are zero and all the even bytes are ASCII,
|
||||||
|
@ -14,7 +14,7 @@ class NameRecordTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_toUnicode_utf16be(self):
|
def test_toUnicode_utf16be(self):
|
||||||
name = self.makeName("Foo Bold", 111, 0, 2, 7)
|
name = self.makeName("Foo Bold", 111, 0, 2, 7)
|
||||||
self.assertEqual("utf_16be", name.getEncoding())
|
self.assertEqual("utf_16_be", name.getEncoding())
|
||||||
self.assertEqual("Foo Bold", name.toUnicode())
|
self.assertEqual("Foo Bold", name.toUnicode())
|
||||||
|
|
||||||
def test_toUnicode_macroman(self):
|
def test_toUnicode_macroman(self):
|
||||||
@ -29,7 +29,7 @@ class NameRecordTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_toUnicode_UnicodeDecodeError(self):
|
def test_toUnicode_UnicodeDecodeError(self):
|
||||||
name = self.makeName(b"\1", 111, 0, 2, 7)
|
name = self.makeName(b"\1", 111, 0, 2, 7)
|
||||||
self.assertEqual("utf_16be", name.getEncoding())
|
self.assertEqual("utf_16_be", name.getEncoding())
|
||||||
self.assertRaises(UnicodeDecodeError, name.toUnicode)
|
self.assertRaises(UnicodeDecodeError, name.toUnicode)
|
||||||
|
|
||||||
def toXML(self, name):
|
def toXML(self, name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user