RSS Feed

CJK fonts in Wine and also works with IBus input


CJK (Chinese, Japanese, Korean) fonts in Wine was really troublesome for me. Today, I have solved it totally. Before explaining the solution, just to say about the system environment I am using.

Arch Linux
wine 1.3.37
winetricks 20111115
ibus 1.4.0
ibus-pinyin 1.4.0
ibus-qt 1.3.1
ibus-table 1.3.9.20110827
ibus-table-extraphrase 1.3.9.20110827
ibus-table-wubi-git 20110410

Problem

I have installed all the fonts using winetricks with allfonts. I have also used winetricks to set fakechinese, fakejapanese, fakekorean. But none of these tricks work fine on my Wine.

Changing locale works fine, “env LANG=zh_CN.gbk wine notepad”. The menu is okay, but in some dialogs, some characters are still missing.

Wine notepad CJK problem

Wine notepad CJK problem

Solution

To solve it, make sure you have installed several fonts, from winetricks or from the package manager. I have installed allfonts from winetricks and other fonts using pacman. Wine is able to use external fonts.

In order to make the CJK fonts display properly, firstly, we need to know what type of system font is used in the different locale,

env LANG=zh_CN.gbk wine regedit

Then, we look into the “HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink” to check what is the system font that is used in this locale.

(I just found that, for the newer version of Wine, mine is 1.5.6, there is no registry key as mentioned above. But we can still get the information in “HKLM\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes“, look at the MS Shell Dlg.  It will show the font that used in the Windows Dialog.)

For my experience, I can see the following fonts in different locale

  • SimSun in zh_CN.gbk
  • PMingLiu in zh_TW.big5
  • MS UI Gothic in ja_JP.utf8
  • Lucida Sans Unicode, Tahoma, Microsoft Sans Serif.

Now, to make them work properly, we need to add the key “HKCU\Software\Wine\Fonts\Replacements” as mentioned here.

Then, add the string value with those system font name, such as SimSun, PMingLiu, MS UI Gothic.

For the data, we need to use the font name. The font name we can get from “HKCU\Software\Wine\Fonts\Cache”, see all the keys. We need to use the font name based on those key, not the “English Name”.

After setting this registry, we should able to read the fonts correctly.

My registry is

  • Lucida Sans Unicode = Lucida Console (external, get from ttf-mac-fonts)
  • Microsoft Sans Serif = MS Sans Serif (installed with wine)
  • MS UI Gothic = TakaoGothic (installed through winetricks)
  • PMingLiu = AR PL Ukai TW (external, get from ttf-arphic-ukai)
  • SimSun = AR PL Ukai CN (external, get from ttf-arphic-ukai)
  • Tahoma = Tahoma (installed through winetricks)

I am not sure does Tahoma setting is useless or not. But this setting works fine for me. Now, start the notepad with different locale, everything should work fine.

Now, after this setting, even the tray icon with CJK tooltip also works fine.

Wine Mini Thunder in system tray

IBus input method

I tried to play a game with traditional Chinese characters, namely Big5. In the game, I cannot input the Chinese characters with IBus input method. I asked in Wine Forum (here), but no one can answer me how to solve it. But today, after solving the CJK problem, I also manage to solve this IBus input problem.

Firstly, we must enable IBus to run properly, we must set the environment variables,

export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus

Some of the people mentioned that these environment variables can be  set in .xinitrc, .bashrc, or some other place. But in my case, they can only work in .xprofile.

The next thing, make sure ibus-daemon is started with “-x” or “–xim”.

ibus-daemon --xim

In my case, I just use the file “/etc/xdg/autostart/ibus.desktop”.

Now, the crucial part is Wine. If the locale is non-UTF8, then IBus will not work. Simply to say, IBus will work on UTF8 locale in Wine. Try it

env LANG=zh_TW.utf8 wine notepad

Now, we should able to enter any characters in notepad with IBus. Howevere, if it is zh_TW.big5 or zh_CN.gbk, IBus will not work.

Yes, this is the solution.

Wine game with IBus CJK input

Wine game with IBus CJK input

About Allen Choong

A cognitive science student, a programmer, a philosopher, a Catholic.

9 responses »

  1. Both glad (but also slightly sad….) that I am not the only person with WINE (in my case, Crossover XI) and IBUS problems.

    In my case, IBUS ‘works’, but not with pinyin input. Even worse it seems to crash after a little bit of use in the WINE window, so that no more input is accepted. IBUS input continues to be accepted outside the WINE window application (in my case, the Wenlin Chinese dictionary), but is not accepted inside the WINE application, even after changing to a different input method, like English. A notepad run within the same ‘bottle’ as my Wenlin continues to work with IBUS, including Pinyin input!

    IBUS input can be started again, simply by choosing ‘restart’ from the IBUS menu.

    My GTK_IM_MODULES, XMODIFIERS and QT_IM_MODULE is the same as yours, /usr/share/applications/ibus.desktop is the same as yours, and so is LANG(at least inside of a bash terminal).

    Bit of a mystery.

    Reply
  2. Thank you so much! Your article helped me a lot to configure wine to write japanese in Microsoft Office.
    I found my self with another problem though, for I need the same program to be able to type spanish when ibus is not active. the LANG=ja_JP.UTF-8 configuration causes the program to deny any kind of character like ‘áéíóú’… I hope I can figure it out soon.

    Reply
    • To type áéíóú, what input method you are using? I afraid that you need to use IBus to input them, so that the output is coded as unicode.

      Reply
      • Thanks for such a fast response! I was finally able to get it to work, though I had to switch to scim imput method.

        The computer is runing Ubuntu and has Microsoft Office 2010 installed through wine, the keyboard has a spanish physical layout (with the “ñ” key), the current OS locale is es_BO and the final user needs to write in both japanese and spanish. Runing ibus xim server (ibus-daemon -x -d) with anthy added worked pretty well on regular windows (with both spanish and japanese) but wouldn’t work with Office (ibus-anthy showed the possibilities but the selected characters wouldn’t be “pasted” to the application). Adding the LANG=ja_JP.UTF-8 solved the “pasting” problem but denied the possibility to write áéíóú (putting ´a´e´i´o´u instead). Apparently the environment variable LANG kind of forced ibus to keep the japanese keyboard layout when anthy was not selected. A lot of questions through internet suggested that ibus doesn’t manage dead keys in xim applications very well, so I changed to scim and everything worked perfectly without further configuration!

        Even though I solved the problem I would like to understand why ibus behaved like that… Did I do something wrong while configuring it?

        What do you think?

      • About IBus, I am not using it for a long time, because too buggy. I already switched to fcitx for quite a long time.

  3. Hello Jorge, I’m currently in the same situation, but I couldn’t get ibus to type Japanese in MS Office 2010 under Wine. Did you install the “Japanese IME” pack when you installed Office in Wine?

    Reply
    • Hello Sven, I couldn’t install the Japanese IME since my installer had only english and spanish information (here in Bolivia it’s difficult to find really good things), but my trying hours showed me that the Japanese IME is not necessary. What kind of problem do you have? Can you type japanese in other programs? When you type inside MS Office, does the japanese symbols shows in a corner but doesn’t stick in the window?
      I forgot to mention the addition of the following key in the wine registry:
      in [HKEY_CURRENT_USER\Software\Wine\X11 Driver] add InputStyle=”overthespot”

      Reply
      • Hello Jorge, Thanks for your help. And thank you allencch for the original article.
        I’m using a Japanese version of MS Office 2010, and followed all the steps above. I still had the “pasting” problem that you mentioned even after adding the “overthespot” value to the registry key (ibus mozc/anthy was showing the Japanese options but not pasting to the main Office window).

        It seems only “env LANG=ja_JP.UTF-8” was not enough to make it work for me. I had to set “env LC_ALL=ja_JP.UTF-8” and now it works!

  4. xinitrc didn’t work because it is being read only by `xinit` script. Display Managers doesn’t do it.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: