Skip to content

Instantly share code, notes, and snippets.

@phineas-pta
Last active September 11, 2023 13:17
Show Gist options
  • Save phineas-pta/c5089de5d465815581a8f0d2c8fb9504 to your computer and use it in GitHub Desktop.
Save phineas-pta/c5089de5d465815581a8f0d2c8fb9504 to your computer and use it in GitHub Desktop.
font khải thể cho chữ hán cổ - kaiti fonts for classical chinese texts

python tools to work with fonts file

ref:

tools:

fonttools cross-platform python pip install "fonttools[woff,unicode]"

extract fonts in collections

from fontTools.ttLib.ttCollection import TTCollection
ttc = TTCollection("ukai.ttc")
for f in ttc:
   name = f["name"].getDebugName(1) # 1 or 4
   # name ID explaination: https://learn.microsoft.com/en-us/typography/opentype/spec/name#name-ids
   f.save(f"{name}.ttf")
   f.flavor = "woff2"
   f.save(f"{name}.woff2")

convert ttf/otf to woff2

from fontTools.ttLib.woff2 import compress
compress("filename.otf", "filename.woff2")

CLI: python -m fontTools.ttLib.woff2 compress file.ttf [-o filename.woff2]

<head><style>
@font-face { font-family: "ChineseFont"; src: url("Adobe Kaiti Std.otf") format("opentype"); }
body { font-family: "ChineseFont"; font-size: 700%; }
.yolo { font-family: monospace; font-size: initial; }
</style></head>
<body>
<span class="yolo">Simplified Chinese</span> 义礼说选<br />
<span class="yolo">Traditional Chinese</span> 義禮說選<br />
<span class="yolo">CJK ext A</span> 㡛㬐㖧䵍<br />
<span class="yolo">CJK ext B</span> 𣚣䶅𪘆𦞕<br />
<span class="yolo">CJK ext C</span> 𪢨𪪖𫔺𫜴<br />
<span class="yolo">CJK ext D</span> 𫝀𫞂𫝻𫠝<br />
<span class="yolo">CJK ext E</span> 𫠫𬚚𬳕𬺡<br />
妙法蓮華經卷第一<br />
後秦龜茲國三藏法師鳩摩羅什奉詔譯<br />
妙法蓮華經敘品第一<br />
如是我聞。一時佛住王舍城耆闍崛山中,與大比丘眾萬二千人俱。<br />
皆是阿羅漢,諸漏已盡,無復煩惱,逮得己利,盡諸有結,心得自在。<br />
其名曰:阿若憍陳如摩訶迦葉優樓頻螺迦葉迦耶迦葉那提迦葉舍利弗大目揵連摩訶迦旃延阿樓馱劫賓那憍梵波提離婆多畢陵伽婆蹉薄拘羅摩訶拘絺羅難陀孫陀羅難陀富樓那彌多羅尼子須菩提阿難羅睺羅,如是眾所知識,大阿羅漢等。<br />
復有學無學二千人摩訶波闍波提比丘尼,與眷屬六千人俱。羅睺羅母耶輸陀羅比丘尼,亦與眷屬俱。<br />
菩薩摩訶薩八萬人,皆於阿耨多羅三藐三菩提不退轉,皆得陀羅尼,樂說辯才,轉不退轉法輪,供養無量百千諸佛,於諸佛所,植眾德本,常為諸佛之所稱歎,以慈修身,善入佛慧,通達大智,到於彼岸,名稱普聞無量世界,能度無數百千眾生。<br />
其名曰:文殊師利菩薩觀世音菩薩得大勢菩薩常精進菩薩不休息菩薩寶掌菩薩藥王菩薩勇施菩薩寶月菩薩月光菩薩滿月菩薩大力菩薩無量力菩薩越三界菩薩跋陀婆羅菩薩彌勒菩薩寶積菩薩導師菩薩,如是等菩薩摩訶薩,八萬人俱。<br />
爾時釋提桓因,與其眷屬二萬天子俱。復有名月天子普香天子寶光天子四大天王與其眷屬,萬天子俱。自在天子大自在天子,與其眷屬,三萬天子俱。娑婆世界主,梵天王尸棄大梵,光明大梵等,與其眷屬,萬二千天子俱。<br />
有八龍王:難陀龍王跋難陀龍王娑伽羅龍王和脩吉龍王德叉迦龍王阿那婆達多龍王摩那斯龍王優缽羅龍王等,各與若干百千眷屬俱。<br />
有四緊那羅王:法緊那羅王妙法緊那羅王大法緊那羅王持法緊那羅王,各與若干百千眷屬俱。<br />
有四乾闥婆王:樂乾闥婆王樂音乾闥婆王美乾闥婆王美音乾闥婆王,各與若干百千眷屬俱。<br />
有四阿修羅王:婆稚阿修羅王佉羅騫馱阿修羅王毘摩質多羅阿修羅王羅睺阿修羅王,各與若干百千眷屬俱。<br />
有四迦樓羅王:大威德迦樓羅王大身迦樓羅王大滿迦樓羅王如意迦樓羅王,各與若干百千眷屬俱。<br />
韋提希子,阿闍世王,與若干百千眷屬俱。各禮佛足,退坐一面。<br />
爾時世尊,四眾圍繞,供養恭敬,尊重讚歎,為諸菩薩說大乘經,名無量義,教菩薩法,佛所護念。佛說此經已,結加趺坐,入於無量義處三昧,身心不動。<br />
是時天雨曼陀羅華摩訶曼陀羅華曼殊沙華摩訶曼殊沙華,而散佛上及諸大眾,普佛世界六種震動。<br />
爾時會中比丘比丘尼優婆塞優婆夷。天龍夜叉乾闥婆阿修羅迦樓羅緊那羅摩睺羅伽人非人,及諸小王轉輪聖王。<br />
是諸大眾,得未曾有,歡喜合掌,一心觀佛。爾時佛放眉間白毫相光,照東方萬八千世界,靡不周遍,下至阿鼻地獄,上至阿迦尼吒天。<br />
於此世界盡見彼土六趣眾生,又見彼土現在諸佛,及聞諸佛所說經法,并見彼諸比丘比丘尼優婆塞優婆夷,諸修行得道者。<br />
復見諸菩薩摩訶薩,種種因緣種種信解種種相貌,行菩薩道。復見諸佛般涅槃者。復見諸佛般涅槃後,以佛舍利起七寶塔。<br />
爾時彌勒菩薩作是念:今者世尊現神變相,以何因緣而有此瑞?今佛世尊入于三昧,是不可思議,現希有事。當以問誰?誰能答者?<br />
復作此念:是文殊師利法王之子,已曾親近供養過去無量諸佛,必應見此希有之相,我今當問。<br />
爾時比丘比丘尼優婆塞優婆夷,及諸天龍鬼神等,咸作此念:是佛光明神通之相,今當問誰?<br />
爾時彌勒菩薩欲自決疑。又觀四眾比丘比丘尼優婆塞優婆夷。及諸天龍鬼神等,眾會之心。<br />
而問文殊師利言:以何因緣而有此瑞,神通之相。放大光明照于東方萬八千土。悉見彼佛國界莊嚴。於是彌勒菩薩,欲重宣此義,以偈問曰:
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment