Configuring the correct Japanese fonts for Windows GTK applications

On a previous blog, I discussed how win32 GTK/GTK+ programs are smart enough to choose a Japanese translation by default if your system’s language is set to Japanese. However, there’s one big shame that I concealed: it will not choose the fonts correctly.

Related to this problem is how the Unicode standard handles Japanese and Chinese characters. You see, the characters knows as kanji, used in Japan, historically comes from China. In fact, kanji literally means Han characters. But that happened more than a thousand years ago. Time always brings change, and now many characters are drawn differently in each countries.

On the image below, you can see how some Japanese characters (black) differs from the Chinese counterpart (blue):

Difference between Japanese and Chinese kanji glyphs

You can see that even the stroke count can differ!

Unicode, in its effort called Han Unification, insisted that Japanese, traditional Chinese, and Korean characters which historically were same must only get a codepoint. So there can’t be one Unicode character for the Japanese version of ‘close’ and another for the Chinese version. Any differences then must be achieved by fonts. So yes, in the screenshot above, the Japanese and Chinese characters are actually the same Unicode character, but rendered in OpenOffice.org with different fonts. And yes, that means you can’t display both Chinese and Japanese text in a simple text document (which can only use one font for the whole file), unless you happen to use only the characters which are country invariant.

Now, back to GTK. GTK programs use a configuration file called pango.aliases to select its fonts. Here’s a sample line:

sans = "arial,browallia new,mingliu,simhei,gulimche,ms gothic"

Now that line means that, if a character must be drawn on screen as a Sans-serif character (“sans”), then try to display it using the “arial” font which is first in the list. If the character isn’t on the system’s Arial font, then try “browallia new”. If it fails, try the next one, “mingliu”. And so on.

Problem comes when a static list like that meets the intricacies of Unicode’s Han unification. For probably a random reason, the configuration file of Windows GTK programs put Chinese fonts (mingliu etc.) before Japanese fonts (ms gothic etc.). So there you have it, a user interface of Japanese translation displayed using “Chinese” characters:

Inkscape using Japanese translation but Chinese characters!

If you’re like me, then that extra dot stroke on “chikai” will really get on your nerve.

The solution is a simple exercise of find and replace. Now find all files named pango.aliases on your hard drive, which most probably will be inside your Program Files folder. Each installed GTK program can have one, but they can also use the “shared” GTK’s. If you already know where your GTK programs are, the file is actually located in the etc\pango subfolder. Once found, replace the content with my hand-crafted version:

courier = "courier new,MS Mincho" 

tahoma = "tahoma,MS PGothic,browallia new,mingliu,simhei,gulimche,ms gothic,kartika,latha,mangal"
sans = "arial,MS PGothic,browallia new,mingliu,simhei,gulimche,ms gothic,kartika,latha,mangal"
serif = "times new roman,MS PMincho,angsana new,mingliu,simsun,gulimche,ms gothic,kartika,latha,mangal"
mono = "courier new,MS Mincho,courier monothai,mingliu,simsun,gulimche,ms gothic,kartika,latha,mangal"
monospace = "courier new,MS Mincho,courier monothai,mingliu,simsun,gulimche,ms gothic,kartika,latha,mangal"

Now your configuration will prefer Japanese fonts rather than Chinese ones. Talk about font discrimination! Here’s the result:

Inkscape using Japanese translation and the correct fonts

Ah, Japanese translation in Japanese fonts. No more wrong fonts. That feels better.

Tags: , , , , , , , , , , , , ,

6 Responses to “Configuring the correct Japanese fonts for Windows GTK applications”

  1. fred Says:

    Bookmarked will be visting regularly. Really like your stuff mate.

  2. Szabolcs Says:

    I have more or less the inverse problem. I’m learning Chinese (beginner), and I cannot persuade Firefox to use Chinese fonts.

    In Firefox one can configure different fonts for Chinese Simplified, Chinese Traditional and Japanese. Firefox will select the appropriate one to use if the content is language-tagged. However, if the content is not language-tagged, and there’s no CJK font specified by the webpage (only a Roman font), then Firefox will always use the Japanese font on my system. Which is both confusing for a beginner like me and quite annoying. (E.g. all of Google/Facebook uses Japanese fonts for CJK characters.)

    Do you know a solution to this problem, short of setting the whole OS (Windows) to a Chinese locale (would break my non-Unicode programs, and my Chinese is not good enough anyway), or setting Firefox do use a Chinese font for Japanese text (I wouldn’t want to do that either)?

    http://en.wikipedia.org/wiki/Han_unification#Examples_of_some_non-unified_Han_ideographs

  3. garcina cambogia Says:

    Key: The most successful business chower outside her singing.

  4. Henry Says:

    You post interesting content here. Your page deserves much more visitors.
    It can go viral if you give it initial boost, i know useful service that can help you, just
    type in google: svetsern traffic tips

  5. kamisori (@wafflekater) Says:

    Thank you. I have searched for this quite a bit. damned unicode… they could have done it right but chose to do it somehow kinda right -_-

    why can’t we have nice things?

  6. sabung ayam online Says:

    Aw, this was an exceptionally nice post. Spending some time and actual effort to produce a really good article… but what can I say… I put things off a whole lot and don’t manage to get nearly anything done.

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: