return None if no unicode cmap subtables were found
This commit is contained in:
parent
113f9cc498
commit
4e8295920a
@ -703,7 +703,8 @@ class TTFont(object):
|
||||
return glyphs
|
||||
|
||||
def getBestCmap(self, cmapPreferences=((3, 10), (0, 4), (3, 1), (0, 3))):
|
||||
"""Return the 'best' unicode cmap dictionary available in the font.
|
||||
"""Return the 'best' unicode cmap dictionary available in the font,
|
||||
or None, if no unicode cmap subtable is available.
|
||||
|
||||
By default it will search for the following (platformID, platEncID)
|
||||
pairs:
|
||||
|
@ -39,7 +39,8 @@ class table__c_m_a_p(DefaultTable.DefaultTable):
|
||||
return None # not found
|
||||
|
||||
def getBestCmap(self, cmapPreferences=((3, 10), (0, 4), (3, 1), (0, 3))):
|
||||
"""Return the 'best' unicode cmap dictionary available in the font.
|
||||
"""Return the 'best' unicode cmap dictionary available in the font,
|
||||
or None, if no unicode cmap subtable is available.
|
||||
|
||||
By default it will search for the following (platformID, platEncID)
|
||||
pairs:
|
||||
@ -50,7 +51,7 @@ class table__c_m_a_p(DefaultTable.DefaultTable):
|
||||
cmapSubtable = self.getcmap(platformID, platEncID)
|
||||
if cmapSubtable is not None:
|
||||
return cmapSubtable.cmap
|
||||
raise ValueError("None of the requested cmap subtables were found")
|
||||
return None # None of the requested cmap subtables were found
|
||||
|
||||
def buildReversed(self):
|
||||
"""Returns a reverse cmap such as {'one':{0x31}, 'A':{0x41,0x391}}.
|
||||
|
@ -67,6 +67,7 @@ class CmapSubtableTest(unittest.TestCase):
|
||||
cmap.tables = [c4, c12]
|
||||
self.assertEqual(cmap.getBestCmap(), {0x10314: 'u10314'})
|
||||
self.assertEqual(cmap.getBestCmap(cmapPreferences=[(3, 1)]), {0x0041:'A', 0x0391:'A'})
|
||||
self.assertEqual(cmap.getBestCmap(cmapPreferences=[(0, 4)]), None)
|
||||
|
||||
def test_font_getBestCmap(self):
|
||||
c4 = self.makeSubtable(4, 3, 1, 0)
|
||||
@ -79,6 +80,7 @@ class CmapSubtableTest(unittest.TestCase):
|
||||
font["cmap"] = cmap
|
||||
self.assertEqual(font.getBestCmap(), {0x10314: 'u10314'})
|
||||
self.assertEqual(font.getBestCmap(cmapPreferences=[(3, 1)]), {0x0041:'A', 0x0391:'A'})
|
||||
self.assertEqual(font.getBestCmap(cmapPreferences=[(0, 4)]), None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user