Android meets TTC!

Toby Tso
汚音屋 × UJAM

--

Android 終於支援 TTC!

在 2015 年年底的時候, Android 引入 ttcIndex 屬性 (Google Git), 隨後將其改為 index 屬性 (Google Git).

在 2016 年 8 月, Android Nougat 正式版釋出的時候, 令人驚訝地, 其不再內建 NotoSansSC-Regular.otf, NotoSansTC-Regular.otf, NotoSansJP-Regular.otf, NotoSansKR-Regular.otf, 而是將牠們何為一體, 採用了 NotoSansCJK-Regular.ttc 這個 OpenType Collection.

ttcIndex/index 和 TTC 有什麼關係?

TTC 是字型集合檔案格式. 一個 TTC 可以包含數個獨立的字型檔. 如 Android Nougat 內建的 NotoSansCJK-Regular.ttc 就同時包含了如下字型:

NotoSansCJKjp-Regular
NotoSansCJKkr-Regular
NotoSansCJKtc-Regular
NotoSansCJKsc-Regular
NotoSansMonoCJKjp-Regular
NotoSansMonoCJKkr-Regular
NotoSansMonoCJKtc-Regular
NotoSansMonoCJKsc-Regular

是不是超厲害?

但 Android 本身就沒有那麼厲害了. Android 是讀不懂字型中包含的地區資訊和字重資訊的. 因此需要由 Android 的字型設定檔 (/system/etc/fonts.xml) 來告訴牠.

譬如說 /system/etc/fonts.xml 內 341 至 343 行 (行數以 Nexus/Pixel 中的資料為準):

即是在告訴 Android:「當語言為『zh-Hant (繁體中文)』的時候, 使用 NotoSansCJK-Regular.ttc 內包含的第 3 個 (index="3") 字型 (即 NotoSansCJKtc-Regular) 來顯示.」

如何知曉 TTC 內各個字型的 ttcIndex/index 為何值?

這裡採用小林劍 (Ken Lunde) 提供的一個 Python 程式: otc2otf.py.

如果我們執行 python otc2otf.py NotoSansCJK-Regular.ttc, 那麼命令列介面將會列出 NotoSansCJK-Regular.ttc 內的每一個字型, 以牠們的 ttcIndex/index 值排序.

font 0 offset: 44/0x0000002C. NotoSansCJKjp-Regular, 即代表 ttcIndex/index0 的字型為 NotoSansCJKjp-Regular.

同理, font 1 offset: 296/0x00000128. NotoSansCJKkr-Regular 即代表 ttcIndex/index1 的字型為 NotoSansCJKkr-Regular.

--

--