2022-02-06 14:07:02 +02:00
|
|
|
#!/usr/bin/env python3
|
2021-12-02 23:29:54 +02:00
|
|
|
# coding=utf8
|
2023-04-23 11:59:04 +02:00
|
|
|
#
|
|
|
|
# Usually called via
|
|
|
|
# $ fontforge query_names fontfile.tff 2>/dev/null
|
2021-12-02 23:29:54 +02:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os.path
|
|
|
|
import fontforge
|
|
|
|
|
|
|
|
###### Some helpers
|
|
|
|
|
|
|
|
def get_sfnt_dict(font):
|
|
|
|
"""Extract SFNT table as nice dict"""
|
|
|
|
return { k: v for l, k, v in font.sfnt_names }
|
|
|
|
|
|
|
|
def format_names(header, *stuff):
|
|
|
|
"""Unify outputs (with header)"""
|
2023-04-23 11:59:04 +02:00
|
|
|
f = '| {:50.50}|{:>2.2}| {:64.64}|{:>2.2}| {:64.64}|{:>2.2}| {:55.55}|{:>2.2}| {:30.30}|{:>2.2}| {:40.40}|{:>2.2}| {:40.40}|{:>2.2}|'
|
2021-12-02 23:29:54 +02:00
|
|
|
if header:
|
2023-04-23 11:59:04 +02:00
|
|
|
d = ''
|
|
|
|
return f.format(*stuff) + '\n' + f.format(d, d, d, d, d, d, d, d, d, d, d, d, d, d).replace(' ', '-')
|
2021-12-02 23:29:54 +02:00
|
|
|
return f.format(*stuff).rstrip()
|
|
|
|
|
|
|
|
###### Let's go!
|
|
|
|
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print('Usage: {} font_name [font_name ...]\n'.format(sys.argv[0]))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print('Examining {} font files'.format(len(sys.argv) - 1))
|
|
|
|
|
2023-04-23 11:59:04 +02:00
|
|
|
print(format_names(True, 'Filename', '', 'PS Name', '', 'Fullname', '', 'Family', '', 'Subfamily', '', 'Typogr. Family', '', 'Typogr. Subfamily', ''))
|
2021-12-02 23:29:54 +02:00
|
|
|
|
|
|
|
for filename in sys.argv[1:]:
|
|
|
|
fullfile = os.path.basename(filename)
|
|
|
|
fname = os.path.splitext(fullfile)[0]
|
|
|
|
|
|
|
|
font = fontforge.open(filename, 1)
|
|
|
|
sfnt = get_sfnt_dict(font)
|
2023-04-23 11:59:04 +02:00
|
|
|
psname = font.fontname
|
2021-12-02 23:29:54 +02:00
|
|
|
font.close()
|
|
|
|
|
|
|
|
sfnt_full = sfnt['Fullname']
|
|
|
|
sfnt_fam = sfnt['Family']
|
|
|
|
sfnt_subfam = sfnt['SubFamily']
|
|
|
|
sfnt_pfam = sfnt['Preferred Family'] if 'Preferred Family' in sfnt else ''
|
|
|
|
sfnt_psubfam = sfnt['Preferred Styles'] if 'Preferred Styles' in sfnt else ''
|
|
|
|
|
2023-04-23 11:59:04 +02:00
|
|
|
o2 = format_names(False,
|
|
|
|
fullfile, str(len(fullfile)),
|
|
|
|
psname, str(len(psname)),
|
|
|
|
sfnt_full, str(len(sfnt_full)),
|
|
|
|
sfnt_fam, str(len(sfnt_fam)),
|
|
|
|
sfnt_subfam, str(len(sfnt_subfam)),
|
|
|
|
# show length zero if a zero length string is stored, show nothing if nothing is stored:
|
|
|
|
sfnt_pfam, str(len(sfnt_pfam)) if 'Preferred Family' in sfnt else '',
|
|
|
|
sfnt_psubfam, str(len(sfnt_psubfam)) if 'Preferred Family' in sfnt else '')
|
2021-12-02 23:29:54 +02:00
|
|
|
|
|
|
|
print(o2)
|