Using Chinese on the department Linux machines

Under Construction


Under the framework of I18N, for I(nternationalizatio)N, Linux now can handle Chinese uniformly. Pre I18N, Chinese handling in the Unix/Linux world is quite awkward. We used CXTerm to do most of Chinese reading and input. The first program I grabbed and installed right after I came here was CXTerm. It's a fine piece of software, but it's begun to show its age. We also had to hack Netscape 4.x to display Chinese nicely. With I18N, however, if we are lucky, the following line will bring us Chinese rendering
 $ LC_ALL=zh_CN.gb2312 application_name
LC stands for locale. We don't have to use LC_ALL, which is too radical for purists. LANG=zh_CN.gb2312 would do the job. You might have guessed what zh_CN.gb2312 is already.
  1. Character sets: what are GB2312, GBK, BIG5 and ISO-10464?
  2. Encodings: what are EUC, HZ, ISO-2022 and UTF8?
  3. Fonts: X bitmap (pcf), TrueType, OpenType, Type 1, Adobe CID-keyed

How to Read Chinese

  1. Console

    Logging on Chinese BBS or reading mails using Pine, we rely on a Chinese savvy console to display Chinese. The console programs coming with Gnome (gnome-terminal) and KDE (konsole) are both I18N aware. To make them display Chinese:

     $ LC_ALL=zh_CN.gb2312 gnome-terminal
    My personal favorite is rxvt, simply because I've been using it for quite a while. The good old xterm knows about multi-byte languages, but not GB2312 (now I'm talking about encoding), AFAIK. You'll need a UTF8 font to use Chinese in xterm and I see no reason for such trouble.
  2. Fonts

    Talking about fonts, I have some bitmap Chinese fonts installed in /u/bh/fonts and some truetype fonts in /u/bh/fonts/truetype. The SongTi comes with Windows (simsun.ttf) looks not bad, though I've seen much better ones. To use these fonts, add the following to your .xsession

     xset fp+ /u/bh/fonts,/u/bh/fonts/truetype
  3. Web browser

    Recent versions of Mozilla display Chinese very well. The department version is built with XFT. If you want to use truetype fonts, add

    to your ~/.fonts.conf.
  4. PostScript

    The case for PostScript is a little complicated. The good news is that you can actually open the file and edit it. PostScript treats Chinese (somewhat) like western languages. You still use findfont to specify a font and show to put the characters on paper (screen). An example would be

    /SimSun-Medium-GBK-EUC-V findfont 60 scalefont setfont
    500 700 moveto (¥ij) show
    What complicates matters is that there are multiple encodings for Chinese. When we talk about GB2312, which is a national standard of character set, we usually imply an EUC encoding. We also have different writing conventions (horizontal and vertical). Hence the EUC and V in the above font specifier. Now the good news is that if you don't have SimSun-Medium, you can edit the file and change it to a font you have, say STSong-Light, which, BTW, is a light-weight Song font cast by Sinotype, a foundry in Changzhou, Jiangsu and which is more pleasing than SimSun. The substituter must have the same char-map as the substitute-e.

    If you have a PostScript file with Chinese characters in it and you can't see them correctly, I can probably help.

  5. PDF

    PDFs are easier than PostScript. Try acroread in /u/bh/linux/Acrobat5/bin/.

  6. CD-ROM with Chinese file names
    $ mount -o iocharset=gb2312 /mnt/cdrom
    You'll need the root privilege to do that, though.

How to Input Chinese

This is probably the weakest link in Linux Chinese handling. There are several options, none of which is quite satisfactory. I have the venerable Chinput installed in /u/bh/linux/bin/. To use it, supposing you're using BASH,
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/u/bh/linux/lib:/u/bh/linux/lib/unicon2
$ LC_ALL=zh_CN.gb2312 /u/bh/linux/bin/chinput
$ export XMODIFIERS=@im=Chinput
Now you if want to input Chinese in any I18N compliant application, say Mozilla, you do
 $ LC_ALL=zh_CN.gb2312 mozilla
CTRL-SPACE activates the input window.

Rxvt doesn't understand the XMODIFIERS directive. You need to tell it through command line:

 $ LC_ALL=zh_CN.gb2312 /u/bh/linux/bin/rxvt -im Chinput
Other choices of input methods include XCIN, Fcitx and Scim. Do an Internet search if you want to try them out.

How to Print Chinese

  1. Typesetting with LaTeX

    I have a very out-of-date page about CJK-LaTeX. It needs significant updating, especially how to use truetype Chinese fonts.

  2. Printing from a web browser

    Mozilla (and its offspring Firefox) does printing by converting the web page into a PostScript file first, which makes printing Chinese in Mozilla the same as printing Chinese PS files. Look at /usr/lib/mozilla-version/defaults/pref/unix.js, you'll see a line like the following

    pref("print.postscript.nativefont.zh-CN", "MSungGBK-Light-GBK2K-H");
    If you've read the above description about PS fonts, you know that Mozilla uses the font MSungGBK-Light with the CMap GBK2K-H (H meaning horizontal). And if you open the PS file generated by Mozilla, you'll find
    /Unicode2NativeDictzh-CN 0 dict def
    /zh-CN_ls {
      /NativeFont /MSungGBK-Light-GBK2K-H def
      /UCS2Font /Courier def
      /Unicode2NativeDict Unicode2NativeDictzh-CN def
      /unicodeshow1 { real_unicodeshow } bind def
      /unicodeshow2 { real_unicodeshow_native } bind def
    } bind def
    That's how Mozilla uses the font. Unfortunately, this font name is configured to point to an uninstalled TTF font,as of this writing. We need to override the font, say to Song-Medium, which is a font I installed. To make a long story short, do the following. Add
    export GS_LIB=/u/bh/fonts/truetype/;
    to your .profile. In your Mozilla profile directory, create user.js if it's not there (don't edit prefs.js directly) and put
    pref("print.postscript.nativefont.zh-CN", "Song-Medium-GBK2K-H");
    in it. You still can't print directly from Mozilla though, because the Chinese fonts are not embedded in the PS file generated by Mozilla. You need to use ps2ps to transform the PS file and send the transformed one to the printer. If you print Chinese a lot, which I doubt, you might want to write a script as your printing command for the browser.

    Konquerer behaves similarly.

  3. Printing PostScript/PDF

Programming Chinese

  1. Using X-Windows
  2. Using GTK
  3. Using FreeType
  4. Java
  5. Tcl/Tk

I wanna know more!

You bet there is more. The best reference is CJKV Information Processing, not surprisingly, published by O'Reilly. It's a shame that it's written by an American who, I dare say, doesn't know much Chinese (He does know quite some Japanese).

Valid HTML 4.01!