tz / pipeline /subset.py
Ethscriptions's picture
奥德彪语录:素材管线——镜头切分/转码、43 条配音+逐字时间轴、字体子集、四平台文案(推送 #2)
dc35ea3 verified
Raw History Blame Contribute Delete
1.61 kB
import os, glob, subprocess, sys
src='/workspaces/frontend/src'
chars=set()
for p in glob.glob(src+'/**/*.*',recursive=True):
if p.endswith(('.ts','.tsx','.json','.css')):
chars|=set(open(p,encoding='utf-8').read())
chars|=set(open('/workspaces/space/奥德彪语录.md',encoding='utf-8').read())
ascii_=''.join(chr(i) for i in range(32,127))
chars|=set(ascii_)|set(',。;:?!、“”‘’「」『』《》()—…·№→↘←↑↓●▌❚∞×÷+-=%/')
text=''.join(sorted(c for c in chars if c.isprintable()))
open('/tmp/tools/charset.txt','w',encoding='utf-8').write(text)
print('chars',len(text))
out='/workspaces/frontend/public/fonts'; os.makedirs(out,exist_ok=True)
F='/tmp/fonts/'
jobs=[('NotoSerifSC[wght].ttf','NotoSerifSC.woff2',True),('NotoSansSC[wght].ttf','NotoSansSC.woff2',True),
('MaShanZheng-Regular.ttf','MaShanZheng.woff2',True),('ZhiMangXing-Regular.ttf','ZhiMangXing.woff2',True),
('BebasNeue-Regular.ttf','BebasNeue.woff2',False),('CormorantGaramond[wght].ttf','CormorantGaramond.woff2',False),
('CormorantGaramond-Italic[wght].ttf','CormorantGaramondItalic.woff2',False),('SpaceMono-Regular.ttf','SpaceMono.woff2',False)]
for a,b,cjk in jobs:
args=['/tmp/venv/bin/pyftsubset',F+a,'--flavor=woff2','--output-file='+out+'/'+b,'--layout-features=*','--no-hinting']
if cjk: args.append('--text-file=/tmp/tools/charset.txt')
else: args.append('--unicodes=U+0020-007E,U+00A0-00FF,U+2010-2027,U+2030-205E,U+2116,U+2190-21FF,U+25CF,U+221E,U+00D7')
subprocess.run(args,check=True)
print(b, os.path.getsize(out+'/'+b)//1024,'KB')