2013-10-17 14:05:27 +00:00
|
|
|
#!/usr/bin/env python
|
2016-11-08 19:01:11 +00:00
|
|
|
|
2007-12-30 09:13:51 +00:00
|
|
|
import sys
|
|
|
|
import fileinput
|
|
|
|
|
2019-07-17 00:18:42 +00:00
|
|
|
|
2007-12-30 09:13:51 +00:00
|
|
|
def main(argv):
|
2009-10-24 04:41:59 +00:00
|
|
|
fonts = {}
|
|
|
|
for line in fileinput.input():
|
|
|
|
f = line.strip().split(' ')
|
2019-12-29 20:20:20 +00:00
|
|
|
if not f:
|
|
|
|
continue
|
2009-10-24 04:41:59 +00:00
|
|
|
k = f[0]
|
|
|
|
if k == 'FontName':
|
|
|
|
fontname = f[1]
|
|
|
|
props = {'FontName': fontname, 'Flags': 0}
|
|
|
|
chars = {}
|
|
|
|
fonts[fontname] = (props, chars)
|
|
|
|
elif k == 'C':
|
|
|
|
cid = int(f[1])
|
|
|
|
if 0 <= cid and cid <= 255:
|
|
|
|
width = int(f[4])
|
|
|
|
chars[cid] = width
|
|
|
|
elif k in ('CapHeight', 'XHeight', 'ItalicAngle',
|
|
|
|
'Ascender', 'Descender'):
|
2019-12-29 20:20:20 +00:00
|
|
|
k = {'Ascender': 'Ascent', 'Descender': 'Descent'}.get(k, k)
|
2009-10-24 04:41:59 +00:00
|
|
|
props[k] = float(f[1])
|
|
|
|
elif k in ('FontName', 'FamilyName', 'Weight'):
|
2019-12-29 20:20:20 +00:00
|
|
|
k = {'FamilyName': 'FontFamily', 'Weight': 'FontWeight'}.get(k, k)
|
2009-10-24 04:41:59 +00:00
|
|
|
props[k] = f[1]
|
|
|
|
elif k == 'IsFixedPitch':
|
|
|
|
if f[1].lower() == 'true':
|
|
|
|
props['Flags'] = 64
|
|
|
|
elif k == 'FontBBox':
|
|
|
|
props[k] = tuple(map(float, f[1:5]))
|
2019-12-29 20:20:20 +00:00
|
|
|
print('# -*- python -*-')
|
|
|
|
print('FONT_METRICS = {')
|
2020-01-04 15:47:07 +00:00
|
|
|
for (fontname, (props, chars)) in fonts.items():
|
|
|
|
print(' {!r}: {!r},'.format(fontname, (props, chars)))
|
2019-12-29 20:20:20 +00:00
|
|
|
print('}')
|
2009-10-24 04:41:59 +00:00
|
|
|
return 0
|
2007-12-30 09:13:51 +00:00
|
|
|
|
2019-12-29 20:20:20 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|