Skip to content

Instantly share code, notes, and snippets.

@lindwurm
Forked from mandel59/koruri.py
Last active Dec 17, 2015
Embed
What would you like to do?
Generate Script fo Koruri/VlKoruri.
#!/usr/bin/env fontforge -lang=py -script
# -*- coding: utf-8 -*-
import fontforge
from datetime import date
# Open Sans のあるディレクトリのパス
opensans_path = "./Open_Sans"
# M+ のあるディレクトリのパス
mplus_path = "./mplus"
# Koruri を生成するディレクトリのパス
# 同じディレクトリに一時ファイルも生成される
koruri_path = "./Koruri"
# .sfd を出力するディレクトリのパス
sfd_path ="./Koruri"
# フォントリスト
# Open Sans ファイル名, M+ ファイル名, Koruri ウェイト
# Open Sans は http://www.fontsquirrel.com/fonts/open-sans から
# 入手するとSemiboldとExtraBoldで表記ゆれがあって最悪.
font_list = [
("OpenSans-Light.ttf", "mplus-1p-light.ttf", "Light"),
("OpenSans-Regular.ttf", "mplus-1p-regular.ttf", "Regular"),
("OpenSans-Semibold.ttf", "mplus-1p-medium.ttf", "Semibold"),
("OpenSans-Bold.ttf", "mplus-1p-bold.ttf", "Bold"),
("OpenSans-ExtraBold.ttf", "mplus-1p-heavy.ttf", "Extrabold"),
]
def main():
# 縦書き対応
fontforge.setPrefs('CoverageFormatsAllowed', 1)
# バージョンを今日の日付から生成する
today = date.today()
version = "Koruri-{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(mplus_path, mp)
ko_path = "{0}/Koruri-{1}.ttf".format(koruri_path, weight)
sf_path = "{0}/Koruri-{1}".format(sfd_path, weight)
generate_koruri(op_path, mp_path, ko_path, sf_path, weight, version)
def koruri_sfnt_names(weight, version):
return (
('English (US)', 'Copyright',
'''\
Koruri: Copylight (c) 2015 lindwurm.
Open Sans: Copyright (c) 2011 Google Corporation.
M+ OUTLINE FONTS: Copyright (C) 2015 M+ FONTS PROJECT.'''),
('English (US)', 'Family', 'Koruri {0}'.format(weight)),
('English (US)', 'SubFamily', weight),
('English (US)', 'Fullname', 'Koruri-{0}'.format(weight)),
('English (US)', 'Version', version),
('English (US)', 'PostScriptName', 'Koruri-{0}'.format(weight)),
('English (US)', 'Vendor URL', 'http://koruri.lindwurm.biz'),
('English (US)', 'Preferred Family', 'Koruri'),
('English (US)', 'Preferred Styles', weight),
('Japanese', 'Preferred Family', 'Koruri'),
('Japanese', 'Preferred Styles', weight),
)
def koruri_gasp():
return (
(8, ('antialias',)),
(13, ('antialias', 'symmetric-smoothing')),
(65535, ('gridfit', 'antialias', 'symmetric-smoothing', 'gridfit+smoothing')),
)
def generate_koruri(op_path, mp_path, ko_path, sf_path, weight, version):
# M+ を開く
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 = koruri_sfnt_names(weight, version)
font.os2_vendor = "maud"
# Grid Fittingの設定
font.gasp = koruri_gasp()
# .sfd を出力
source = sf_path + ".sfd"
font.save(source)
# TTF の生成
font.generate(ko_path, '', ('short-post', 'opentype', 'PfEd-lookups'))
if __name__ == '__main__':
main()
#!/usr/bin/env fontforge -lang=py -script
# -*- coding: utf-8 -*-
import fontforge
from datetime import date
# Open Sans のあるディレクトリのパス
opensans_path = "./Open_Sans"
# VL P Gothic のあるディレクトリのパス
vlgothic_path = "./VLGothic"
# VlKoruriを生成するディレクトリのパス。事前に作成する必要あり。
# 同じディレクトリに一時ファイルも生成される
koruri_path = "./VlKoruri"
# .sfd を出力するディレクトリのパス
sfd_path ="./VlKoruri"
# フォントリスト
# Open Sans ファイル名, VL P Gothic ファイル名, VlKoruri ウェイト
font_list = [
("OpenSans-Regular.ttf", "VL-PGothic-Regular.ttf", "Regular"),
]
def main():
# 縦書き対応
fontforge.setPrefs('CoverageFormatsAllowed', 1)
# バージョンを今日の日付から生成する
today = date.today()
version = "VlKoruri-{0}".format(today.strftime("%Y%m%d"))
for (op, vl, weight) in font_list:
op_path = "{0}/{1}".format(opensans_path, op)
vl_path = "{0}/{1}".format(vlgothic_path, vl)
ko_path = "{0}/VlKoruri-{1}.ttf".format(koruri_path, weight)
sf_path = "{0}/VlKoruri-{1}".format(sfd_path, weight)
generate_koruri(op_path, vl_path, ko_path, sf_path, weight, version)
def koruri_sfnt_names(weight, version):
return (
('English (US)', 'Copyright',
'''\
VlKoruri:
Copylight (c) 2013-2014, lindwurm.
VL P Gothic:
Copyright(C) 1990-2003 Wada Laboratory, Univ. of Tokyo.
Copyright(C) 2003-2004 /efont/.
Copyright(C) 2005-2014 M+ FONTS PROJECT.
Copyright(C) 2006-2014 Project Vine.
Copyright(C) 2006-2014 Daisuke SUZUKI.
All rights reserved.
Open Sans:
Copyright (c) 2010-2011, Google Corporation.'''),
('English (US)', 'Family', 'VlKoruri {0}'.format(weight)),
('English (US)', 'SubFamily', weight),
('English (US)', 'Fullname', 'VlKoruri-{0}'.format(weight)),
('English (US)', 'Version', version),
('English (US)', 'PostScriptName', 'VlKoruri-{0}'.format(weight)),
('English (US)', 'Vendor URL', 'http://koruri.lindwurm.biz'),
('English (US)', 'Preferred Family', 'VlKoruri'),
('English (US)', 'Preferred Styles', weight),
('Japanese', 'Preferred Family', 'VlKoruri'),
('Japanese', 'Preferred Styles', weight),
)
def koruri_gasp():
return (
(8, ('antialias',)),
(13, ('antialias', 'symmetric-smoothing')),
(65535, ('gridfit', 'antialias', 'symmetric-smoothing', 'gridfit+smoothing')),
)
def generate_koruri(op_path, vl_path, ko_path, sf_path, weight, version):
# VL P Gothic を開く
font = fontforge.open(vl_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 = koruri_sfnt_names(weight, version)
font.os2_vendor = "maud"
# Grid Fittingの設定
font.gasp = koruri_gasp()
# .sfd を出力
source = sf_path + ".sfd"
font.save(source)
# TTF の生成
font.generate(ko_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