手でTrueTypeインストラクションを書いてみる。ttx
でdumpした時の書式で書く。
PUSHB[ ] 30 /* threshold of point size */ MPS[ ] GT[ ] /* if (30 > current_ppem) */ IF [ ] SVTCA[0] /* set vectors to the y-axis */ PUSHB[ ] 11 /* point number */ PUSHW[ ] 3200 /* coordinate value (50.0 in F26Dot6) */ SCFS[ ] /* Sets Coordinate */ PUSHB[ ] 12 /* point number */ PUSHW[ ] 3200 /* coordinate value (50.0 in F26Dot6) */ SCFS[ ] /* Sets Coordinate */ EIF[ ]
よく分からんけど、30ppemより小さいサイズの時に11番目と12番目のポイントをY座標方向に50.0のとこに移動させる・・・気持ちのグリフインストラクションを書いてみた。あんまりよく分からないから見栄えが変化したらいいやくらいで。maxp
に適当にスタックサイズとかの値入ってないとインストラクションが無視されるかもしれないのでttfautohint
で適当にインストラクションを当ててから上記に差し替える。これはfontTools
を使って
glyf = ttFont["glyf"] g = glyf[gname] with open(instruction_txt) as f: content = [line.strip() for line in f.readlines()] g.fromXML("instructions", None, [("assembly", None, content)], ttFont)
みたいなことをすればできる。
以下のように各種サイズで文字列を書き出す適当なHTMLを書いてWindowsのChromeで見たら変化が出た。(macOSのCoreTextだとインストラクションは無視されると思うのでWindowsで確認する)