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 _names_generator(filename):
with codecs.open(filename, 'r', encoding='utf-8') as f:
for line in f:
line = line.rstrip()
if line.startswith('0x'):
# uni chr
codepoint = google_fonts.get_codepoint_from_line(line)
name = filter_lists.get_name_by_unicode(codepoint)
if name is None:
prefix = 'u' if codepoint > 0xFFFF else 'uni'
name = '{0}{1:04X}'.format(prefix, codepoint)
yield name
elif line.startswith(' ' * 6):
# unencoded name
yield line.rsplit(' ', 1)[1]
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.')
sys.stderr = open(os.devnull, 'w')
dirpath = argv[1]
result = True
files = []
for font in fonts.Metadata(dirpath).fonts:
files.append(os.path.join(dirpath, font.filename))
for subset in fonts.Metadata(dirpath).subsets:
if subset == 'menu':
continue
(file1, file2, diff_size) = _LeastSimilarCoverage(files, subset)
if diff_size > FLAGS.max_diff_cps:
print('%s coverage for %s failed' % (dirpath, subset))
print('Difference of codepoints between %s & %s is %d' % (
file1, file2, diff_size))
result = False
if result:
print('%s passed subset coverage' % (dirpath))
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 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 main():
args = parser.parse_args()
response = requests.get(API_URL.format(args.key))
try:
webfontList = response.json()['items']
webfontListFamilyNames = [item['family'] for item in webfontList]
except (ValueError, KeyError):
sys.exit("Unable to load and parse"
" list of families from Google Web Fonts API.")
for dirpath, dirnames, filenames in os.walk(args.repo):
metadata_path = os.path.join(dirpath, 'METADATA.pb')
if not os.path.exists(metadata_path):
continue
metadata = FamilyProto()
text_data = open(metadata_path, "rb").read()
text_format.Merge(text_data, metadata)
try:
family = metadata.name
except KeyError:
print(('ERROR: "{}" does not contain'
' familyname info.').format(metadata_path),
file=sys.stderr)
continue
try:
index = webfontListFamilyNames.index(family)
webfontsItem = webfontList[index]
except ValueError:
print(('ERROR: Family "{}" could not be found'
' in Google Web Fonts API.').format(family))
def generate_filter_lists(filename):
# 'GF-{script}-rest.nam' => {script}-rest
basename = os.path.basename(filename).split('.', 1)[0].split('-', 2)[-1]
filerListFileName = '{0}.txt'.format(basename)
dirname = os.path.dirname(filename)
nice_names_filename = os.path.join(dirname, 'filter lists', 'nice names', filerListFileName)
prod_names_filename = os.path.join(dirname, 'filter lists', 'uni names', filerListFileName)
_mkdir(os.path.dirname(nice_names_filename))
_mkdir(os.path.dirname(prod_names_filename))
with codecs.open(nice_names_filename, 'w', encoding='utf-8') as niceNamesFile, \
codecs.open(prod_names_filename, 'w', encoding='utf-8') as prodNamesFile:
for name in _names_generator(filename):
print(filter_lists.translate_name(name, production_name=False), file=niceNamesFile)
print(filter_lists.translate_name(name, production_name=True), file=prodNamesFile)
def generate_filter_lists(filename):
# 'GF-{script}-rest.nam' => {script}-rest
basename = os.path.basename(filename).split('.', 1)[0].split('-', 2)[-1]
filerListFileName = '{0}.txt'.format(basename)
dirname = os.path.dirname(filename)
nice_names_filename = os.path.join(dirname, 'filter lists', 'nice names', filerListFileName)
prod_names_filename = os.path.join(dirname, 'filter lists', 'uni names', filerListFileName)
_mkdir(os.path.dirname(nice_names_filename))
_mkdir(os.path.dirname(prod_names_filename))
with codecs.open(nice_names_filename, 'w', encoding='utf-8') as niceNamesFile, \
codecs.open(prod_names_filename, 'w', encoding='utf-8') as prodNamesFile:
for name in _names_generator(filename):
print(filter_lists.translate_name(name, production_name=False), file=niceNamesFile)
print(filter_lists.translate_name(name, production_name=True), file=prodNamesFile)
entries = []
before = []
header = []
for line in f:
line = line.rstrip()
if (not entries and not before) and line.startswith('#'):
header.append(line)
continue
entry = None
if line.startswith('0x'):
# uni chr
codepoint = google_fonts.get_codepoint_from_line(line)
entry = (codepoint, None, line)
elif line.startswith(' '):
# unencoded name
name = filter_lists.translate_name(line.rsplit(' ', 1)[1])
entry = (None, name, line)
if entry is not None:
entry += (before, )
before = []
entries.append(entry)
else:
# these lines will stick before the next entry
before.append(line)
entries.sort(key=_sortkey_namelist_entries)
_print = lambda *args: print(*args,file=out)
map(_print, header)
for codepoint, name, original, item_before in entries:
map(_print, item_before)
if codepoint is not None:
def _reformat_namelist(f, out=None):
entries = []
before = []
header = []
for line in f:
line = line.rstrip()
if (not entries and not before) and line.startswith('#'):
header.append(line)
continue
entry = None
if line.startswith('0x'):
# uni chr
codepoint = google_fonts.get_codepoint_from_line(line)
entry = (codepoint, None, line)
elif line.startswith(' '):
# unencoded name
name = filter_lists.translate_name(line.rsplit(' ', 1)[1])
entry = (None, name, line)
if entry is not None:
entry += (before, )
before = []
entries.append(entry)
else:
# these lines will stick before the next entry
before.append(line)
entries.sort(key=_sortkey_namelist_entries)
_print = lambda *args: print(*args,file=out)