2 # -*- coding: utf-8 -*-
5 Generates the Comic Mono font files based on Comic Shanns font.
8 - vendor/comic-shanns.otf
9 - vendor/Cousine-Regular.ttf
12 - monospacifier: https://github.com/cpitclaudel/monospacifier/blob/master/monospacifier.py
13 - YosemiteAndElCapitanSystemFontPatcher: https://github.com/dtinth/YosemiteAndElCapitanSystemFontPatcher/blob/master/bin/patch
21 sys.setdefaultencoding('UTF8')
28 return float(font.capHeight)
30 def adjust_height(source, template, scale):
31 source.selection.all()
32 source.transform(psMat.scale(height(template) / height(source)))
33 for attr in ['ascent', 'descent',
34 'hhea_ascent', 'hhea_ascent_add',
36 'hhea_descent', 'hhea_descent_add',
37 'os2_winascent', 'os2_winascent_add',
38 'os2_windescent', 'os2_windescent_add',
39 'os2_typoascent', 'os2_typoascent_add',
40 'os2_typodescent', 'os2_typodescent_add',
42 setattr(source, attr, getattr(template, attr))
43 source.transform(psMat.scale(scale))
45 font = fontforge.open('vendor/comic-shanns.otf')
46 ref = fontforge.open('vendor/Cousine-Regular.ttf')
47 for g in font.glyphs():
49 category = unicodedata.category(unichr(uni)) if 0 <= uni <= sys.maxunicode else None
50 if g.width > 0 and category not in ['Mn', 'Mc', 'Me']:
52 if g.width != target_width:
53 delta = target_width - g.width
54 g.left_side_bearing += delta / 2
55 g.right_side_bearing += delta - g.left_side_bearing
56 g.width = target_width
58 font.familyname = 'Comic Mono'
59 font.version = '0.1.1'
60 font.comment = 'https://github.com/dtinth/comic-mono-font'
61 font.copyright = 'https://github.com/dtinth/comic-mono-font/blob/master/LICENSE'
63 adjust_height(font, ref, 0.875)
64 font.sfnt_names = [] # Get rid of 'Prefered Name' etc.
65 font.fontname = 'ComicMono'
66 font.fullname = 'Comic Mono'
67 font.generate('ComicMono.ttf')
70 font.fontname = 'ComicMono-Bold'
71 font.fullname = 'Comic Mono Bold'
73 font.changeWeight(32, "LCG", 0, 0, "squish")
74 font.generate('ComicMono-Bold.ttf')