2013-10-17 14:05:27 +00:00
|
|
|
#!/usr/bin/env python
|
2007-12-30 09:13:51 +00:00
|
|
|
import sys
|
|
|
|
import fileinput
|
|
|
|
|
|
|
|
def main(argv):
|
2009-10-24 04:41:59 +00:00
|
|
|
fonts = {}
|
|
|
|
for line in fileinput.input():
|
|
|
|
f = line.strip().split(' ')
|
|
|
|
if not f: continue
|
|
|
|
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'):
|
|
|
|
k = {'Ascender':'Ascent', 'Descender':'Descent'}.get(k,k)
|
|
|
|
props[k] = float(f[1])
|
|
|
|
elif k in ('FontName', 'FamilyName', 'Weight'):
|
|
|
|
k = {'FamilyName':'FontFamily', 'Weight':'FontWeight'}.get(k,k)
|
|
|
|
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]))
|
2014-06-15 03:14:33 +00:00
|
|
|
print ('# -*- python -*-')
|
|
|
|
print ('FONT_METRICS = {')
|
2009-10-24 04:41:59 +00:00
|
|
|
for (fontname,(props,chars)) in fonts.iteritems():
|
2014-06-15 03:14:33 +00:00
|
|
|
print (' %r: %r,' % (fontname, (props,chars)))
|
|
|
|
print ('}')
|
2009-10-24 04:41:59 +00:00
|
|
|
return 0
|
2007-12-30 09:13:51 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__': sys.exit(main(sys.argv))
|