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():
if len(sys.argv) != 2 or sys.argv[1][-4:] != ".ttf":
sys.exit('Usage: {} fontfile.ttf'.format(sys.argv[0]))
expected = set()
for nam_file in NAM_FILES:
nam_filepath = os.path.join(NAM_DIR, nam_file)
expected.update(CodepointsInNamelist(nam_filepath))
filename = sys.argv[1]
diff = expected - CodepointsInFont(filename)
print(filename),
if bool(diff):
print('missing'),
for c in sorted(diff):
print('0x%04X' % (c)),
else:
print('OK')
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))
def _InconsistentSubsetSupport(file1, file2, subsetcps):
"""Returns difference in number of codepoints supported.
Args:
file1: Name of font file
file2: Name of font file
subsetcps: Complete set of codepoints to be supported
Returns:
Difference in number of codepoints between file1 and file2.
"""
supportcps1 = len(subsetcps.intersection(fonts.CodepointsInFont(file1)))
supportcps2 = len(subsetcps.intersection(fonts.CodepointsInFont(file2)))
return abs(supportcps1 - supportcps2)
def DiffCoverage(font_filename1, font_filename2, subset):
"""Prints a comparison of the coverage of a given subset by two fonts.
Args:
font_filename1: The first font to compare.
font_filename2: The second font to compare.
subset: The lowercase name of the subset to compare coverage of.
"""
f1cps = fonts.CodepointsInFont(font_filename1)
f2cps = fonts.CodepointsInFont(font_filename2)
if subset != 'all':
subset_cps = fonts.CodepointsInSubset(subset)
f1cps &= subset_cps
f2cps &= subset_cps
else:
subset_cps = None
subset_cp_str = ('/%d' % len(subset_cps)) if subset_cps is not None else ''
print(' %s %+d (%d%s => %d%s)' % (
subset, len(f2cps) - len(f1cps), len(f1cps), subset_cp_str, len(f2cps),
subset_cp_str))
def _InconsistentSubsetSupport(file1, file2, subsetcps):
"""Returns difference in number of codepoints supported.
Args:
file1: Name of font file
file2: Name of font file
subsetcps: Complete set of codepoints to be supported
Returns:
Difference in number of codepoints between file1 and file2.
"""
supportcps1 = len(subsetcps.intersection(fonts.CodepointsInFont(file1)))
supportcps2 = len(subsetcps.intersection(fonts.CodepointsInFont(file2)))
return abs(supportcps1 - supportcps2)
def DiffCoverage(font_filename1, font_filename2, subset):
"""Prints a comparison of the coverage of a given subset by two fonts.
Args:
font_filename1: The first font to compare.
font_filename2: The second font to compare.
subset: The lowercase name of the subset to compare coverage of.
"""
f1cps = fonts.CodepointsInFont(font_filename1)
f2cps = fonts.CodepointsInFont(font_filename2)
if subset != 'all':
subset_cps = fonts.CodepointsInSubset(subset)
f1cps &= subset_cps
f2cps &= subset_cps
else:
subset_cps = None
subset_cp_str = ('/%d' % len(subset_cps)) if subset_cps is not None else ''
print(' %s %+d (%d%s => %d%s)' % (
subset, len(f2cps) - len(f1cps), len(f1cps), subset_cp_str, len(f2cps),
subset_cp_str))