-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkoruri.py
120 lines (96 loc) · 3.87 KB
/
koruri.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env fontforge -lang=py -script
# -*- coding: utf-8 -*-
import fontforge
from datetime import date
# Open Sans のあるディレクトリのパス
opensans_path = "./opensans"
# Roboto のあるディレクトリのパス
roboto_path = "./roboto"
# M+ のあるディレクトリのパス
mplus_path = "./mplus"
# Koruri を生成するディレクトリのパス
# 同じディレクトリに一時ファイルも生成される
koruri_path = "./koruri"
# フォントリスト
# Open Sans ファイル名, Roboto ファイル名, M+ ファイル名, Koruri ウェイト
font_list = [
("OpenSans-Light.ttf", "Roboto-Light.ttf", "mplus-1p-light.ttf", "Light"),
("OpenSans-Regular.ttf", "Roboto-Regular.ttf", "mplus-1p-regular.ttf", "Regular"),
("OpenSans-SemiBold.ttf", "Roboto-Medium.ttf", "mplus-1p-medium.ttf", "Semibold"),
("OpenSans-Bold.ttf", "Roboto-Bold.ttf", "mplus-1p-bold.ttf", "Bold"),
("OpenSans-ExtraBold.ttf", "Roboto-Black.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, rb, mp, weight) in font_list:
op_path = "{0}/{1}".format(opensans_path, op)
rb_path = "{0}/{1}".format(roboto_path, rb)
mp_path = "{0}/{1}".format(mplus_path, mp)
ko_path = "{0}/Koruri-{1}.ttf".format(koruri_path, weight)
generate_koruri(op_path, rb_path, mp_path, ko_path, weight, version)
def koruri_sfnt_names(weight, version):
return (
('English (US)', 'Copyright',
'''\
Koruri: Copyright (c) 2013- lindwurm.
Open Sans: Copyright (c) 2011 Google Corporation.
Roboto: Copyright (c) 2012- Google.
M+ OUTLINE FONTS: Copyright (C) 2002- 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', 'https://koruri.github.io'),
('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, ('antialias', 'symmetric-smoothing')),
)
def generate_koruri(op_path, rb_path, mp_path, ko_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)
# Fancy Colon を Roboto からコピーする
rbfont = fontforge.open(rb_path)
# Fancy Colon をコピー
rbfont.selection.select(0xee01)
rbfont.copy()
font.selection.select(0xee01)
font.paste()
# Fancy Colon を U+A789 にコピー
font.selection.select(0xee01)
font.copy()
font.selection.select(0xa789)
font.paste()
# フォント情報の設定
font.sfnt_names = koruri_sfnt_names(weight, version)
font.os2_vendor = "maud"
# Grid Fittingの設定
font.gasp = koruri_gasp()
# TTF の生成
font.generate(ko_path, '', ('short-post', 'opentype', 'PfEd-lookups'))
if __name__ == '__main__':
main()