Created
June 6, 2015 07:19
-
-
Save lindwurm/883ad6afb86d4a22b144 to your computer and use it in GitHub Desktop.
Ohruri generate script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fontforge -lang=py -script | |
# -*- coding: utf-8 -*- | |
import fontforge | |
from datetime import date | |
# Open Sans のあるディレクトリのパス | |
opensans_path = "./Open_Sans" | |
# Mgen+ のあるディレクトリのパス | |
mgen_path = "./mgen" | |
# Ohruri を生成するディレクトリのパス | |
# 同じディレクトリに一時ファイルも生成される | |
ohruri_path = "./Ohruri" | |
# .sfd を出力するディレクトリのパス | |
sfd_path ="./Ohruri" | |
# フォントリスト | |
# Open Sans ファイル名, Mgen+ ファイル名, Ohruri ウェイト | |
# Open Sans は http://www.fontsquirrel.com/fonts/open-sans から | |
# 入手するとSemiboldとExtraBoldで表記ゆれがあって最悪. | |
font_list = [ | |
("OpenSans-Light.ttf", "mgenplus-1p-light.ttf", "Light"), | |
("OpenSans-Regular.ttf", "mgenplus-1p-regular.ttf", "Regular"), | |
("OpenSans-Semibold.ttf", "mgenplus-1p-medium.ttf", "Semibold"), | |
("OpenSans-Bold.ttf", "mgenplus-1p-bold.ttf", "Bold"), | |
("OpenSans-ExtraBold.ttf", "mgenplus-1p-heavy.ttf", "Extrabold"), | |
] | |
def main(): | |
# 縦書き対応 | |
fontforge.setPrefs('CoverageFormatsAllowed', 1) | |
# バージョンを今日の日付から生成する | |
today = date.today() | |
version = "Ohruri-{0}".format(today.strftime("%Y%m%d")) | |
for (op, mp, weight) in font_list: | |
op_path = "{0}/{1}".format(opensans_path, op) | |
mp_path = "{0}/{1}".format(mgen_path, mp) | |
oh_path = "{0}/Ohruri-{1}.ttf".format(ohruri_path, weight) | |
sf_path = "{0}/Ohruri-{1}".format(sfd_path, weight) | |
generate_ohruri(op_path, mp_path, oh_path, sf_path, weight, version) | |
def ohruri_sfnt_names(weight, version): | |
return ( | |
('English (US)', 'Copyright', | |
'''\ | |
Ohruri: Copylight (c) 2015 lindwurm. | |
Open Sans: Copyright (c) 2011 Google Corporation. | |
M+ OUTLINE FONTS: Copyright (C) 2015 M+ FONTS PROJECT. | |
Source Han Sans: Copyright(c) 2014 Adobe Systems Incorporated. All Rights Reserved. | |
'''), | |
('English (US)', 'Family', 'Ohruri {0}'.format(weight)), | |
('English (US)', 'SubFamily', weight), | |
('English (US)', 'Fullname', 'Ohruri-{0}'.format(weight)), | |
('English (US)', 'Version', version), | |
('English (US)', 'PostScriptName', 'Ohruri-{0}'.format(weight)), | |
('English (US)', 'Vendor URL', 'http://koruri.lindwurm.biz'), | |
('English (US)', 'Preferred Family', 'Ohruri'), | |
('English (US)', 'Preferred Styles', weight), | |
('Japanese', 'Preferred Family', 'Ohruri'), | |
('Japanese', 'Preferred Styles', weight), | |
) | |
def ohruri_gasp(): | |
return ( | |
(8, ('antialias',)), | |
(13, ('antialias', 'symmetric-smoothing')), | |
(65535, ('gridfit', 'antialias', 'symmetric-smoothing', 'gridfit+smoothing')), | |
) | |
def generate_ohruri(op_path, mp_path, oh_path, sf_path, weight, version): | |
# Mgen+ を開く | |
font = fontforge.open(mp_path) | |
# EMの大きさを2048に設定する | |
font.em = 2048 | |
# Open Sans を開く | |
opfont = fontforge.open(op_path) | |
# Open Sans に含まれるグリフを削除する | |
font.selection.none() | |
opfont.selection.all() | |
for glyph in opfont.selection.byGlyphs: | |
if glyph.glyphname in font: | |
font.selection.select(("more",), glyph.glyphname) | |
font.clear() | |
# Open Sans をマージする | |
font.mergeFonts(op_path) | |
# フォント情報の設定 | |
font.sfnt_names = ohruri_sfnt_names(weight, version) | |
font.os2_vendor = "maud" | |
# Grid Fittingの設定 | |
font.gasp = ohruri_gasp() | |
# .sfd を出力 | |
source = sf_path + ".sfd" | |
font.save(source) | |
# TTF の生成 | |
font.generate(oh_path, '', ('short-post', 'opentype', 'PfEd-lookups')) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment