Tuesday, July 14, 2009

Far east font rendering in Wine

If you use Wine on Linux, BSD or Solaris and your trying to render your native language fonts you might have noticed just how slow Wine renders far east fonts. This doesn't just happen to far east languages it can also apply to western languages as well. Below is four reasons why this happens and solutions.

1). Reason:
Wine uses traditional protocol for communication between client and server, and it seems that iptables is disabled in linux/wine.
execute command "iptables -I INPUT -s -j ACCEPT"

2). Reason:
Locale problem, lots of Linux distributions use utf-8 for Chinese locale, and wine will firstly try to search/request the utf-8 font sets which do not exist in ./wine/drive_c/windows/fonts. Then wine will request other font sets that suits other locale(language environment) one by one (image how many languages their are in the world).
Execute command "env LANG=en_US wine your_program" or "env LANG=zh_CN wine your_program", to tell wine which language locale you want to use. (zh_CN is the Chinese locale in Linux)

3). Reason:
GKB font sets, maybe it is a bug while wine is very slow to request GKB font sets. (GKB font sets are used to display simplified Chinese fonts and traditional Chinese fonts, but it is not the national standard in China. Simplified Chinese fonts are used in mainland China, and traditional Chinese fonts are used in Hongkong/Taiwan/...).
Action 1: delete the comments about GKB in /usr/share/X11/locale/zh_CN.UTF-8/XLC_LOCALE
Action 2: execute command "sed -i "s/^[^#]*GBK/\#Marked for GBK--- &/g "/usr/share/X11/locale/zh_CN.UTF-8/XLC_LOCALE >/dev/null" to let wine not continue to use/request GBK fonts.

4). Reason: No fonts in ~/.wine/drive_c/windows/fonts (actually that is a null folder at the beginning, nothing to suit Chinese environment in wine)
Copy the font file simsun.ttc (the default Chinese font in Chinese version of $MS Windows system) from XP to ~/.wine/drive_c/windows/fonts, and then save the following contents as fonts.reg:

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"Arial CE,238"="simsun"
"Arial CYR,204"="simsun"
"Arial Greek,161"="simsun"
"Arial TUR,162"="simsun"
"Courier New"="simsun"
"Courier New CE,238"="simsun"
"Courier New CYR,204"="simsun"
"Courier New Greek,161"="simsun"
"Courier New TUR,162"="simsun"
"MS Sans Serif"="simsun"
"MS Shell Dlg"="simsun"
"MS Shell Dlg 2"="simsun"
"Times New Roman CE,238"="simsun"
"Times New Roman CYR,204"="simsun"
"Times New Roman Greek,161"="simsun"
"Times New Roman TUR,162"="simsun"
"Tms Rmn"="simsun"

Then execute the command "regedit ~/.wine/fonts.reg", so wine can be very well displayed as in Windows Chinese environment and much faster than before.

Sub Pixel Font Rendering

As of Wine 1.1.12 support for subpixel font rendering was added into Wine, there are some registry changes you need to make for sub pixel font rendering to work.
[HKEY_CURRENT_USER\Control Panel\Desktop]
Font rendering performance

Font rendering performance at least on nvidia and ati video cards is 50 times faster if you enable font smoothing. (set it to rgb or bgr, gray is not that much faster). The easiest way to enable font smoothing in Wine is to download WineTricks and apply the settings with it.

Thanks to Axel Xia and Roderick Colenbrander

No comments: