Monday, July 30, 2007

Solving unreadable Simplified Chinese text on Gentoo

It's been a while I have been facing font display issues with Simplified Chinese text in my Gentoo machine. Main reason being the fact that without special fontconfig configuration, it tends to mix Sungti (宋体) and Kaiti (楷体) fonts to display Simplify Chinese text. Not only it's aesthetically unpleasing to see two different fonts on the same line, Kaiti is extremely hard to read under small font sizes due to font hinting. Worst being sometimes you can only see a character space filled random pixels (due to the line too thin to be rendered on screen after hinting) and it's pretty annoying to enlarge your font-sizes just to read those characters.

The solution can be found in this Chinese article that I had found online. For those who aren't all that proficient in Chinese, here's my own translation to it:


Title: Font problem in Gentoo

by yangtse (?)

Q: I'm using SimSun font in my Gentoo machine. But I don't like how the English alphabets looked in SimSun, is it possible to set the English alphabets to be displayed using other fonts, while still having Chinese characters displayed using SimSun font?

A: Yes. That's how it's usually done. But most users don't use SimSun; use Uming and WenQuanYi instead.

In /etc/fonts/local.conf, configure the fonts that you wanted in the serif, sans-serif and monospace font family: Specifying your font of choice for Roman characters first, then specify the Chinese fonts that you wanted next. Then configure KDE or GNOME to use these fonts as the default display font.

Please refer to my /etc/fonts/local.conf configuration:

<?xml version="1.0"?>
<fontconfig>
<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>DejaVu Serif</family>
<family>AR PL ShanHeiSun Uni</family>
<family>WenQuanYi Bitmap Song</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Bitstream Vera Sans</family>
<family>DejaVu Sans</family>
<family>AR PL ShanHeiSun Uni</family>
<family>WenQuanYi Bitmap Song</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>DejaVu Sans Mono</family>
<family>AR PL ShanHeiSun Uni</family>
<family>WenQuanYi Bitmap Song</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
<edit mode="assign" name="autohint">
<bool>false</bool>
</edit>
<edit name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font">
<test name="family" compare="contains">
<string>Song</string>
<string>Sun</string>
<string>Kai</string>
<string>Ming</string>
</test>
<test name="weight" compare="less_eq">
<int>100</int>
</test>
<test compare="more_eq" target="pattern" name="weight">
<int>180</int>
</test>
<edit mode="assign" name="embolden">
<bool>true</bool>
</edit>
</match>
<match target="font">
<test name="family" compare="contains">
<string>Song</string>
<string>Sun</string>
<string>Kai</string>
<string>Ming</string>
</test>
<edit name="globaladvance">
<bool>false</bool>
</edit>
<edit name="spacing">
<int>0</int>
</edit>
<edit name="hinting">
<bool>true</bool>
</edit>
<edit name="autohint">
<bool>false</bool>
</edit>
<edit name="antialias" mode="assign">
<bool>true</bool>
</edit>
<test name="pixelsize" compare="less_eq">
<int>18</int>
</test>
<edit name="antialias" mode="assign">
<bool>false</bool>
</edit>
</match>
</fontconfig>

Q: Where can I find these fonts?
A: Please emerge these packages: media-fonts/wqy-bitmapfont, media-fonts/arphicfonts



Additional steps

Once you have copied and saved the above /etc/fonts/local.conf file, perform the following command to refresh the font cache:
fc-cache -fv

You'd have to restart your applications in order to see the effect.

[Original article link]