June 25, 2010

A hack to allow editing the charset and the lang in a font on fontconfig

Background

fontconfig is scanning a font and gathering the information to see what kind of character sets it's possible to support. being used to pick up the certain font according to  a request from a user. having said that all of the fonts doesn't necessarily have certain coverage of the glyphs for certain character sets. so given that missing glyphs are not a big deal or still looks good with a fallback font for them, there should be needs to use such fonts for the certain language anyway.

Syntax

After this hack, two elements are available. <charset> to update the character sets information a.k.a. FcCharSet and <langset> to update the language coverage information a.k.a. FcLangSet. in either case, the element has to have the language name that is available as orth file in fontconfig but without .orth suffix, as CDATA. it looks like:

<match target="scan"> <test name="family"> <string>HanaMin</string> </test> <edit name="charset" mode="assign" binding="strong"> <charset>ja</charset> </edit> <edit name="lang" mode="assign" binding="strong"> <langset>ja</langset> </edit> </match>

And you have to run fc-cache again to re-generate the fontconfig cache file because the above rule only affects the scan phase. then starting to match HanaMin for serif:lang=ja in this case. which originally has zh-hk, zh-mo and zh-tw coverage.

Code

See private git repo

No comments: