Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
if not actuals:
path: A directory containing a METADATA.pb file.
Returns:
A list of ResultMessageTuple, one per validation performed.
"""
results = []
metadata = fonts.Metadata(path)
name = metadata.name
for font in metadata.fonts:
# We assume style/weight is correct in METADATA
style = font.style
weight = font.weight
values = [('name', name, font.name), ('filename', fonts.FilenameFor(
name, style, weight, '.ttf'), font.filename),
('postScriptName', fonts.FilenameFor(name, style, weight),
font.post_script_name), ('fullName', fonts.FullnameFor(
name, style, weight), font.full_name)]
for (key, expected, actual) in values:
if expected != actual:
results.append(
_SadResult('%s METADATA %s/%d %s expected %s, got %s' %
(name, style, weight, key, expected, actual), path,
_FixMetadata(style, weight, key, expected)))
if not results:
results.append(
_HappyResult('METADATA name consistently derived from "%s"' % name,
path))
return results