Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(argv):
if len(argv) != 2 or not os.path.isdir(argv[1]):
sys.exit('Must have one argument, a directory containing font files.')
dirpath = argv[1]
cps = set()
for f in _GetFontFiles(dirpath):
cps.update(fonts.CodepointsInFont(os.path.join(dirpath, f)))
for f in _GetFontFiles(dirpath):
diff = cps - fonts.CodepointsInFont(os.path.join(dirpath, f))
if bool(diff):
print('%s failed' % (f))
for c in diff:
print('0x%04X' % (c))
else:
print('%s passed' % (f))
path: Path to directory containing font.
name: The name of the family.
font: A font record from a METADATA.pb.
ttf: A fontTools.ttLib.TTFont for the font.
Returns:
A list of ResultMessageTuple for tests performed.
"""
results = []
style = font.style
weight = font.weight
full_font_file = os.path.join(path, font.filename)
expectations = [('family', fonts.NAME_FAMILY, name),
('postScriptName', fonts.NAME_PSNAME, fonts.FilenameFor(
name, style, weight)), ('fullName', fonts.NAME_FULLNAME,
fonts.FullnameFor(
name, style, weight))]
for (friendly_name, name_id, expected) in expectations:
# If you have lots of name records they should ALL have the right value
actuals = fonts.ExtractNames(ttf, name_id)
for (idx, actual) in enumerate(actuals):
results.append(
ResultMessageTuple(expected == actual,
'%s %s/%d \'name\' %s[%d] expected %s, got %s' %
(name, style, weight, friendly_name, idx, expected,
actual), full_font_file,
_FixBadNameRecord(friendly_name, name_id,
expected)))
# should have at least one actual
Args:
path: Path to directory containing font.
name: The name of the family.
font: A font record from a METADATA.pb.
ttf: A fontTools.ttLib.TTFont for the font.
Returns:
A list of ResultMessageTuple for tests performed.
"""
results = []
style = font.style
weight = font.weight
full_font_file = os.path.join(path, font.filename)
expectations = [('family', fonts.NAME_FAMILY, name),
('postScriptName', fonts.NAME_PSNAME, fonts.FilenameFor(
name, style, weight)), ('fullName', fonts.NAME_FULLNAME,
fonts.FullnameFor(
name, style, weight))]
for (friendly_name, name_id, expected) in expectations:
# If you have lots of name records they should ALL have the right value
actuals = fonts.ExtractNames(ttf, name_id)
for (idx, actual) in enumerate(actuals):
results.append(
ResultMessageTuple(expected == actual,
'%s %s/%d \'name\' %s[%d] expected %s, got %s' %
(name, style, weight, friendly_name, idx, expected,
actual), full_font_file,
_FixBadNameRecord(friendly_name, name_id,
expected)))