Skip to content

Commit f86a8b8

Browse files
authored
Create build-serif-ttf.py
Build Serif TrueType ,issue #25 .
1 parent 62cae5d commit f86a8b8

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

build-serif-ttf.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os, json
2+
from shutil import copy, rmtree
3+
4+
os.system('chmod +x ./main/otfcc/*')
5+
6+
shurl=[
7+
"https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/Japanese/SourceHanSerif-Bold.otf",
8+
"https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/Japanese/SourceHanSerif-ExtraLight.otf",
9+
"https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/Japanese/SourceHanSerif-Heavy.otf",
10+
"https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/Japanese/SourceHanSerif-Light.otf",
11+
"https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/Japanese/SourceHanSerif-Medium.otf",
12+
"https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/Japanese/SourceHanSerif-Regular.otf",
13+
"https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/Japanese/SourceHanSerif-SemiBold.otf"
14+
]
15+
os.makedirs('./src')
16+
for u1 in shurl:
17+
os.system(f'wget -P src {u1} || exit 1')
18+
19+
tocl01='python3 ./main/sourcehantocl.py'
20+
os.makedirs(f'./fonts01')
21+
for item in os.listdir('./src'):
22+
if item.lower().split('.')[-1]=='otf':
23+
os.system(f"{tocl01} ./src/{item} ./fonts01/{item} s2")
24+
rmtree('./src')
25+
26+
os.system(f"otf2ttf ./fonts01/*")
27+
cfg=json.load(open(os.path.join(os.path.abspath(os.path.dirname(__file__)), './main/config.json'), 'r', encoding = 'utf-8'))
28+
fnm=cfg['fontName'].replace(' ', '')
29+
30+
fod='Serif'
31+
os.makedirs(f'./fonts/{fnm}{fod}')
32+
os.makedirs(f'./fonts/{fnm}{fod}TC')
33+
os.makedirs(f'./fonts/{fnm}{fod}SC')
34+
os.makedirs(f'./fonts/{fnm}{fod}JP')
35+
os.makedirs(f'./fonts/{fnm}{fod}TTCs')
36+
os.makedirs(f'./fonts/{fnm}{fod}FANTI_TTFs')
37+
copy('./LICENSE.txt', f'./fonts/{fnm}{fod}/')
38+
copy('./LICENSE.txt', f'./fonts/{fnm}{fod}TC/')
39+
copy('./LICENSE.txt', f'./fonts/{fnm}{fod}SC/')
40+
copy('./LICENSE.txt', f'./fonts/{fnm}{fod}JP/')
41+
copy('./LICENSE.txt', f'./fonts/{fnm}{fod}TTCs/')
42+
copy('./LICENSE.txt', f'./fonts/{fnm}{fod}FANTI_TTFs/')
43+
44+
tocl='python3 ./main/toclmul.py'
45+
tootc='otf2otc -o'
46+
for item in os.listdir('./fonts01'):
47+
if item.lower().split('.')[-1]=='ttf':
48+
aan=item.replace('SourceHan', fnm)
49+
fn1, fn2=aan.split('-')
50+
os.system(f"{tocl} ./fonts01/{item} ./fonts/{fn1} 2")
51+
flst=[
52+
f'./fonts/{fn1}/{fn1}-{fn2}',
53+
f'./fonts/{fn1}/{fn1}TC-{fn2}',
54+
f'./fonts/{fn1}/{fn1}SC-{fn2}',
55+
f'./fonts/{fn1}/{fn1}JP-{fn2}',
56+
f'./fonts/{fn1}/{fn1}ST-{fn2}',
57+
f'./fonts/{fn1}/{fn1}HW-{fn2}',
58+
f'./fonts/{fn1}/{fn1}HWTC-{fn2}',
59+
f'./fonts/{fn1}/{fn1}HWSC-{fn2}',
60+
f'./fonts/{fn1}/{fn1}HWJP-{fn2}',
61+
f'./fonts/{fn1}/{fn1}HWST-{fn2}'
62+
]
63+
flstall=' '.join(flst)
64+
os.system(f"{tootc} ./fonts/{fn1}TTCs/{fn1}-{fn2.split('.')[0]}.ttc {flstall}")
65+
66+
os.system(f'mv ./fonts/{fnm}{fod}/*TC* ./fonts/{fnm}{fod}TC/')
67+
os.system(f'mv ./fonts/{fnm}{fod}/*SC* ./fonts/{fnm}{fod}SC/')
68+
os.system(f'mv ./fonts/{fnm}{fod}/*JP* ./fonts/{fnm}{fod}JP/')
69+
os.system(f'mv ./fonts/{fnm}{fod}/*ST* ./fonts/{fnm}{fod}FANTI_TTFs/')
70+
71+
os.system(f'7z a {fnm}{fod}TTCs.7z ./fonts/{fnm}{fod}TTCs/*')
72+
otfs=[
73+
f'./fonts/{fnm}{fod}',
74+
f'./fonts/{fnm}{fod}TC',
75+
f'./fonts/{fnm}{fod}SC',
76+
f'./fonts/{fnm}{fod}JP',
77+
f'./fonts/{fnm}{fod}FANTI_TTFs'
78+
]
79+
otff=' '.join(otfs)
80+
os.system(f'7z a {fnm}{fod}TTFs.7z {otff} -mx=9 -mfb=256 -md=256m')
81+
82+
rmtree('./fonts')

0 commit comments

Comments
 (0)