0%

Mac TTC 字體匯出

緣起

在製作被審資料的時候字體遺失,結果我用Mac內建的 蘋方 ,因此趕快去找有沒有轉出字體的方法

安裝

Clone 一下 Adobe Font SDK

git clone https://github.com/adobe-type-tools/afdko
cd afdko

安裝他

python3 -m venv afdko_env
source afdko_env/bin/activate
pip3 install afdko

開始解壓縮 (file 改檔案名稱)

otc2otf <file>

轉換成Windows-capiticy

ttx -t cmap PingFangTC-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Ultralight.ttx
ttx -b -m PingFangTC-Ultralight.otf PingFangTC-Ultralight.ttx

重複幾次就好

如果以PingFang來說,可以直接用下面這段程式碼

# PingFangHK
ttx -t cmap PingFangHK-Light.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Light.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Light.ttx
ttx -b -m PingFangHK-Light.otf PingFangHK-Light.ttx

ttx -t cmap PingFangHK-Medium.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Medium.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Medium.ttx
ttx -b -m PingFangHK-Medium.otf PingFangHK-Medium.ttx

ttx -t cmap PingFangHK-Regular.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Regular.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Regular.ttx
ttx -b -m PingFangHK-Regular.otf PingFangHK-Regular.ttx

ttx -t cmap PingFangHK-Semibold.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Semibold.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Semibold.ttx
ttx -b -m PingFangHK-Semibold.otf PingFangHK-Semibold.ttx

ttx -t cmap PingFangHK-Thin.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Thin.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Thin.ttx
ttx -b -m PingFangHK-Thin.otf PingFangHK-Thin.ttx

ttx -t cmap PingFangHK-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangHK-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangHK-Ultralight.ttx
ttx -b -m PingFangHK-Ultralight.otf PingFangHK-Ultralight.ttx

# PingFangSC
ttx -t cmap PingFangSC-Light.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Light.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Light.ttx
ttx -b -m PingFangSC-Light.otf PingFangSC-Light.ttx

ttx -t cmap PingFangSC-Medium.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Medium.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Medium.ttx
ttx -b -m PingFangSC-Medium.otf PingFangSC-Medium.ttx

ttx -t cmap PingFangSC-Regular.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Regular.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Regular.ttx
ttx -b -m PingFangSC-Regular.otf PingFangSC-Regular.ttx

ttx -t cmap PingFangSC-Semibold.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Semibold.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Semibold.ttx
ttx -b -m PingFangSC-Semibold.otf PingFangSC-Semibold.ttx

ttx -t cmap PingFangSC-Thin.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Thin.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Thin.ttx
ttx -b -m PingFangSC-Thin.otf PingFangSC-Thin.ttx

ttx -t cmap PingFangSC-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangSC-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangSC-Ultralight.ttx
ttx -b -m PingFangSC-Ultralight.otf PingFangSC-Ultralight.ttx

# PingFangTC
ttx -t cmap PingFangTC-Light.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Light.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Light.ttx
ttx -b -m PingFangTC-Light.otf PingFangTC-Light.ttx

ttx -t cmap PingFangTC-Medium.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Medium.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Medium.ttx
ttx -b -m PingFangTC-Medium.otf PingFangTC-Medium.ttx

ttx -t cmap PingFangTC-Regular.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Regular.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Regular.ttx
ttx -b -m PingFangTC-Regular.otf PingFangTC-Regular.ttx

ttx -t cmap PingFangTC-Semibold.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Semibold.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Semibold.ttx
ttx -b -m PingFangTC-Semibold.otf PingFangTC-Semibold.ttx

ttx -t cmap PingFangTC-Thin.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Thin.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Thin.ttx
ttx -b -m PingFangTC-Thin.otf PingFangTC-Thin.ttx

ttx -t cmap PingFangTC-Ultralight.otf
sed -i '' 's/platformID="0" platEncID="3"/platformID="3" platEncID="1"/g' PingFangTC-Ultralight.ttx
sed -i '' 's/platformID="0" platEncID="4"/platformID="3" platEncID="10"/g' PingFangTC-Ultralight.ttx
ttx -b -m PingFangTC-Ultralight.otf PingFangTC-Ultralight.ttx

檔名帶有「#1」就是新生成的字型檔

[參考連結](蘋方移植 | by Toby Tso | 汚音屋 × UJAM | Medium)