Common Questions about Tcl/Tk and Japanese language support

Purpose: to accumulate common questions (and hopefully answers!) relating to the use of Tk and Japanese language input, output, etc.

Jeffrey Hobbs revamped the information in this page on 19 Apr 2002 to reduce the confusion and clarify the latest state of support for Japanese in 8.3+. See also taiku goes multilingual for pure-Tcl input methods for several languages, including Japanese.


Tk 8.3.4+ has support for Windows IME and Linux XIM. In 8.3, this uses the root-window style, but 8.4 has support for "over-the-spot" style IME and XIM. This support was possible with significant assistance from Koichi Yamamoto and Keiichi Takahashi. Koichi has confirmed that the 8.4 support is known to work on Win95 to WinXP using Windows IME, Japanese Win9*, and the ATOK13 IME variants.

XIM on other machines may work in 8.4, but there is not much tester response at this point.


Larry Virden notes:

I've a user doing the same - except in his case (see in a comp.lang.tcl thread I _tried_ to start earlier) the Japanese is NOT being displayed fine... the font is pretty ugly compared to the patched version of Tk 4 previously being used...

I am needing the same information regarding input methods, adding Canna to the list ...

In my case, platform is SPARC Solaris 8.


More information from Jim Breen:

Re the rendering of Japanese characters:

The default is very ugly. I was able to improve it greatly by cranking up the point size, e.g.:

        set ntext [encoding convertfrom euc-jp "......"]

        font create gothicfont -family gothic -size 16
        label .jpl -text $ntext -font gothicfont

Strangely, when I moved it to 24pt, it went "blocky". Ir appears not the render TTFs. Odd, considering the Gothic font is a TTF.

Jeffrey Hobbs adds:

Jim found this to be a problem with the handling of TTF (TrueType fonts) locally on his X server. This was not a Tk problem.


Jim Breen later writes on news:comp.lang.tcl

I am working with files containing Japanese text in the "EUC-JP" encapsulation. For display in Tcl/Tk, I convert them to Unicode with 'set ublah [encoding convertfrom euc-jp $jblah]'.

This works fine where the Japanese is from the more common JIS X 0208 character set, but fails when the characters are from the supplementary JIS X 0212 set, which is encapsulated in EUC-JP as 3 bytes, the first being 0x8F. (The JIS X 0212 characters have all been in Unicode from 1.0.)

Is there something extra I have to do to get them converted, or is it really the case that the EUC-JP -> Unicode conversion in Tcl/Tk8.1 and later is incomplete? If the latter, in other words it is a bug, what is best way to get it fixed for the 8.4 stable release?

(I guess I'm not that surprised that the 6,000 characters in JIS X 0212 are not being handled, because they are not used that often, largely because the coding used by Microsoft (Shift-JIS) cannot encapsulate them. They *are* however in EUC-JP and Unicode, and should not be overlooked. See http://www.unicode.org/Public/MAPPINGS/EASTASIA/JIS/JIS0212.TXT

Jeffrey Hobbs replies:

This is known and encapsulated in the following bug report:

http://sourceforge.net/tracker/?func=detail&atid=110894&aid=219297&group_id=10894


Later in the discussion (not everything has reached me here yet), the following exchange occured on news:comp.lang.tcl :

 Date: Thu Mar 22 01:47:54 EST 2001
 From: [Ioi Lam] <[email protected]>

In case anyone is as confused as me about IME for Win32, there are 4 ways of inputing CJK (Chinese/Japanese/Korean) characters for Win32

(a) "old" IME: This is what you get when you buy a CJK edition of Windows (e.g., Japanese Edition of Windows 98). Tk already supports this today.

(b) 3rd party "wrapper" IME: in the old days, if you had an English Win95, you couldn't input CJK characters. To solve this, some 3rd party companies started selling so-called "wrapper" IMEs. Examples are UnionWay, TwinBridge, etc.

(c) Microsoft Global IME. As part of its instinct to destroy other people's business, Microsoft started (around the time of IE 4.0) giving away its own wrapper IME for English Windows. They call this Global IME. It works under Win95/98/NT. Apps can access Global IME with a COM API.

(d) Win2K IME. With Win2K, Microsoft decided Global IME is too much a hack, so they support yet another kind of IME. Any version of Win2K supports CJK IMEs. You just have to go into the Control Panel and enable them. This works almost the same way as the "old" IME in (a), except the user can change the input language on the fly, so you have to process extra events in order to support it.

So, what's TK's status? (a) is supported today. (d) works after my patch to handle the input language change events. (c) doesn't work, but I am willing (make that *very willing*) to work on it. (b) has too much variations so that's a bit tough.

As for testing my patch, I tested under Japanese Win98 to make sure it doesn't break (a). I then tested under English W2K with CJK IMEs installed, and it proved that (d) also works.

For sanity sake, I tested under plain English versions of Win98/NT/2K and nothing seems to break.

A side effect of this patch also gives you some of (b): my Chinese PenPower input tablet starts working under TK.

Jeff, if you have Win2K and want to taste the Joy of IME, I can send you a page on how to input Japanese :-)

Hope that's enough information.


Ioi Lam I've uploaded my instructions for setting W2k for inputting Japanese with TK

http://tixlibrary.sourceforge.net/i18n/tk_w2kime/

It's a similar process for setting up Chinese or Korean input.

At this page, you can also find a patched wish832d.exe that can handle CJK input on W2k.


Keiichi Takahashi wrote in c.l.t on 2001-12-11: With Tcl/Tk 8.3.4, XIM is working on RedHat Linux 7.2. On Solaris, and Compaq Digital UNIX (CDE), it is still not working though.


LV: Is there anyone in the community aware enough of the issues to be addressing what else is needed here? My primary platform is SPARC Solaris - however, my knowledge of the issues with XIM is virtually zero - and I have an urgent need for it. So I am willing to dig in and learn, under the tutulege of someone wiser than I.

LV Feb 16, 2005 - Tk 8.4.9 finally has the patches in that allow Tk XIM to work on SPARC Solaris! Wonderful.


BR (2003-09-28), A note on Japanese on Mac OS X: There is initial code and patches to do IMEs. It's not yet production-ready though. Also the current display engine is not quite up to the task, because it is still based on old (pre Mac OS X) APIs, which have severe limitations.


LV Tk XIM question - I have a user who wants a larger font used for the input method entry box. It _appears_ that the font and size is hard coded in generic/tkEvent.c . Is there a way to override the default font ?


Things Japanese - Arts and crafts of Tcl-Tk programming