2019-05-06 05:42:00 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-06-07 11:05:30 +00:00
|
|
|
"""
|
|
|
|
Generates the Comic Mono font files based on Comic Shanns font.
|
2019-05-06 05:42:00 +00:00
|
|
|
|
2019-06-07 11:05:30 +00:00
|
|
|
Required files:
|
|
|
|
- vendor/comic-shanns.otf
|
|
|
|
- vendor/Cousine-Regular.ttf
|
|
|
|
|
|
|
|
Based on:
|
|
|
|
- monospacifier: https://github.com/cpitclaudel/monospacifier/blob/master/monospacifier.py
|
|
|
|
- YosemiteAndElCapitanSystemFontPatcher: https://github.com/dtinth/YosemiteAndElCapitanSystemFontPatcher/blob/master/bin/patch
|
|
|
|
"""
|
2019-05-06 05:42:00 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
reload(sys)
|
|
|
|
sys.setdefaultencoding('UTF8')
|
|
|
|
|
|
|
|
import fontforge
|
|
|
|
import psMat
|
|
|
|
import unicodedata
|
|
|
|
|
|
|
|
def height(font):
|
|
|
|
return float(font.capHeight)
|
|
|
|
|
2019-06-07 11:05:30 +00:00
|
|
|
def adjust_height(source, template, scale):
|
2019-05-06 05:42:00 +00:00
|
|
|
source.selection.all()
|
|
|
|
source.transform(psMat.scale(height(template) / height(source)))
|
|
|
|
for attr in ['ascent', 'descent',
|
|
|
|
'hhea_ascent', 'hhea_ascent_add',
|
|
|
|
'hhea_linegap',
|
|
|
|
'hhea_descent', 'hhea_descent_add',
|
|
|
|
'os2_winascent', 'os2_winascent_add',
|
|
|
|
'os2_windescent', 'os2_windescent_add',
|
|
|
|
'os2_typoascent', 'os2_typoascent_add',
|
|
|
|
'os2_typodescent', 'os2_typodescent_add',
|
|
|
|
]:
|
|
|
|
setattr(source, attr, getattr(template, attr))
|
2019-06-07 11:05:30 +00:00
|
|
|
source.transform(psMat.scale(scale))
|
2019-05-06 05:42:00 +00:00
|
|
|
|
2019-06-07 11:05:30 +00:00
|
|
|
font = fontforge.open('vendor/comic-shanns.otf')
|
|
|
|
ref = fontforge.open('vendor/Cousine-Regular.ttf')
|
2019-05-06 05:42:00 +00:00
|
|
|
for g in font.glyphs():
|
|
|
|
uni = g.unicode
|
|
|
|
category = unicodedata.category(unichr(uni)) if 0 <= uni <= sys.maxunicode else None
|
|
|
|
if g.width > 0 and category not in ['Mn', 'Mc', 'Me']:
|
|
|
|
target_width = 510
|
|
|
|
if g.width != target_width:
|
|
|
|
delta = target_width - g.width
|
|
|
|
g.left_side_bearing += delta / 2
|
|
|
|
g.right_side_bearing += delta - g.left_side_bearing
|
|
|
|
g.width = target_width
|
|
|
|
|
2019-06-07 11:05:30 +00:00
|
|
|
font.familyname = 'Comic Mono'
|
|
|
|
font.version = '0.1.1'
|
|
|
|
font.comment = 'https://github.com/dtinth/comic-mono-font'
|
|
|
|
font.copyright = 'https://github.com/dtinth/comic-mono-font/blob/master/LICENSE'
|
|
|
|
|
|
|
|
adjust_height(font, ref, 0.875)
|
2019-05-06 05:42:00 +00:00
|
|
|
font.sfnt_names = [] # Get rid of 'Prefered Name' etc.
|
2019-06-07 11:05:30 +00:00
|
|
|
font.fontname = 'ComicMono'
|
|
|
|
font.fullname = 'Comic Mono'
|
|
|
|
font.generate('ComicMono.ttf')
|
|
|
|
|
|
|
|
font.selection.all()
|
|
|
|
font.fontname = 'ComicMono-Bold'
|
|
|
|
font.fullname = 'Comic Mono Bold'
|
|
|
|
font.weight = 'Bold'
|
|
|
|
font.changeWeight(32, "LCG", 0, 0, "squish")
|
2019-06-07 11:05:38 +00:00
|
|
|
font.generate('ComicMono-Bold.ttf')
|