Based on the discussion with Just and anthrotype: Undo the changes in the name table and extend unittests. If there are inconsistencies in the name table, it's ok to create new name IDs, even if this might not be the most efficient way of creating the name table.
This commit is contained in:
parent
513307237b
commit
e968e8fd7f
@ -311,16 +311,6 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
|
|||||||
if nameID is not None:
|
if nameID is not None:
|
||||||
return nameID
|
return nameID
|
||||||
nameID = self._findUnusedNameID()
|
nameID = self._findUnusedNameID()
|
||||||
|
|
||||||
nameID_win = self.findMultilingualName(names, windows=True, mac=False)
|
|
||||||
nameID_mac = self.findMultilingualName(names, windows=False, mac=True)
|
|
||||||
if nameID_win and nameID_mac is None:
|
|
||||||
nameID = nameID_win
|
|
||||||
windows = False
|
|
||||||
if nameID_mac and nameID_win is None:
|
|
||||||
nameID = nameID_mac
|
|
||||||
mac = False
|
|
||||||
|
|
||||||
# TODO: Should minimize BCP 47 language codes.
|
# TODO: Should minimize BCP 47 language codes.
|
||||||
# https://github.com/fonttools/fonttools/issues/930
|
# https://github.com/fonttools/fonttools/issues/930
|
||||||
for lang, name in sorted(names.items()):
|
for lang, name in sorted(names.items()):
|
||||||
|
@ -1462,15 +1462,16 @@ def test_buildStatTable_name_duplicates():
|
|||||||
|
|
||||||
builder.buildStatTable(font_obj, AXES, windowsNames=True, macNames=True)
|
builder.buildStatTable(font_obj, AXES, windowsNames=True, macNames=True)
|
||||||
actual_names = [x.string for x in font_obj["name"].names]
|
actual_names = [x.string for x in font_obj["name"].names]
|
||||||
expected_names = ['Weight', 'Weight',
|
expected_names = ['Weight', 'Weight', 'Weight',
|
||||||
'ExtraLight', 'ExtraLight',
|
'ExtraLight', 'ExtraLight', 'ExtraLight',
|
||||||
'Light', 'Light',
|
'Light', 'Light', 'Light',
|
||||||
'Regular', 'Regular',
|
'Regular', 'Regular', 'Regular',
|
||||||
'Medium', 'Medium',
|
'Medium', 'Medium', 'Medium',
|
||||||
'Bold', 'Bold',
|
'Bold', 'Bold', 'Bold',
|
||||||
'ExtraBold', 'ExtraBold',
|
'ExtraBold', 'ExtraBold', 'ExtraBold',
|
||||||
'Black', 'Black']
|
'Black', 'Black', 'Black']
|
||||||
# Multiple name records were added by buildStatTable
|
# Because there is an inconsistency in the names add new name IDs
|
||||||
|
# for each platform -> windowsNames=True, macNames=True
|
||||||
assert sorted(expected_names) == sorted(actual_names)
|
assert sorted(expected_names) == sorted(actual_names)
|
||||||
|
|
||||||
|
|
||||||
|
@ -317,11 +317,24 @@ class NameTableTest(unittest.TestCase):
|
|||||||
font_obj["name"].names = []
|
font_obj["name"].names = []
|
||||||
|
|
||||||
font_obj["name"].setName('Weight', 270, 3, 1, 0x409)
|
font_obj["name"].setName('Weight', 270, 3, 1, 0x409)
|
||||||
|
font_obj["name"].setName('Weight', 270, 1, 0, 0)
|
||||||
names = {'en': 'Weight', }
|
names = {'en': 'Weight', }
|
||||||
nameID = font_obj["name"].addMultilingualName(names, minNameID=256)
|
nameID = font_obj["name"].addMultilingualName(names, minNameID=256)
|
||||||
|
|
||||||
self.assertEqual(270, nameID)
|
self.assertEqual(270, nameID)
|
||||||
|
|
||||||
|
font_obj["name"].removeNames(nameID=270, platformID=1) # remove Mac name
|
||||||
|
nameID = font_obj["name"].addMultilingualName(names, minNameID=256)
|
||||||
|
# Because there is an inconsistency in the names add a new name ID
|
||||||
|
self.assertEqual(271, nameID)
|
||||||
|
|
||||||
|
font_obj["name"].removeNames(platformID=3) # remove all Windows names
|
||||||
|
font_obj["name"].removeNames(platformID=1) # remove all Mac names
|
||||||
|
nameID = font_obj["name"].addMultilingualName(names, minNameID=256)
|
||||||
|
#Because there is no name ID with the name 'Weight',
|
||||||
|
# take the next available name ID -> minNameID=256
|
||||||
|
self.assertEqual(256, nameID)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_decompile_badOffset(self):
|
def test_decompile_badOffset(self):
|
||||||
# https://github.com/fonttools/fonttools/issues/525
|
# https://github.com/fonttools/fonttools/issues/525
|
||||||
|
Loading…
x
Reference in New Issue
Block a user