2 # -*- coding: utf-8 -*-
4 """Update the glyph metrics so that they all really have the same size."""
7 # - monospacifier: https://github.com/cpitclaudel/monospacifier/blob/master/monospacifier.py
8 # - YosemiteAndElCapitanSystemFontPatcher: https://github.com/dtinth/YosemiteAndElCapitanSystemFontPatcher/blob/master/bin/patch
15 sys.setdefaultencoding('UTF8')
22 return float(font.capHeight)
24 def adjust_height(source, template):
25 source.selection.all()
26 source.transform(psMat.scale(height(template) / height(source)))
27 for attr in ['ascent', 'descent',
28 'hhea_ascent', 'hhea_ascent_add',
30 'hhea_descent', 'hhea_descent_add',
31 'os2_winascent', 'os2_winascent_add',
32 'os2_windescent', 'os2_windescent_add',
33 'os2_typoascent', 'os2_typoascent_add',
34 'os2_typodescent', 'os2_typodescent_add',
36 setattr(source, attr, getattr(template, attr))
37 source.transform(psMat.scale(0.9))
39 font = fontforge.open('comic-shanns.otf')
40 ref = fontforge.open('vendor/Menlo.ttc')
41 for g in font.glyphs():
43 category = unicodedata.category(unichr(uni)) if 0 <= uni <= sys.maxunicode else None
44 if g.width > 0 and category not in ['Mn', 'Mc', 'Me']:
46 if g.width != target_width:
47 delta = target_width - g.width
48 g.left_side_bearing += delta / 2
49 g.right_side_bearing += delta - g.left_side_bearing
50 g.width = target_width
52 adjust_height(font, ref)
53 font.sfnt_names = [] # Get rid of 'Prefered Name' etc.
54 font.fontname = 'Comic Shanns dtinth'
55 font.familyname = 'Comic Shanns dtinth'
56 font.fullname = 'Comic Shanns dtinth'
57 font.generate('comic-shanns-dtinth.otf')