in reply to Re: Chinese font problem in Perl/Tk
in thread Chinese fonts problem in Perl/Tk

Thanks zentara. I tried it out and saw a lot of basic fonts on different Solaris and Linux boxes, but didn't see any Asian characters in there. So without ever specifying a font in my script, I'm wondering what font it chose and how it managed to display (almost all of) the Chinese characters.

I guess I need to ask even more basic questions:

I've added some fontCreate stuff from a Slaven Rezic example I saw somewhere and now call out a specific font. But I still don't see how to specify anything differently to get the missing Chinese characters to appear.

Modified code follows. (It works fine in Windows, so run in Unix to see the problem).

(Example removed. Refer to code at beginning of thread -- shockers)

Replies are listed 'Best First'.
Re^3: Chinese font problem in Perl/Tk
by Courage (Parson) on Jan 06, 2005 at 13:46 UTC
    I use Arial Unicode MS from within Perl and Tk applications, see http://mini.net/tcl//11392 for explanations about font itself and http://www.vkonovalov.ru/perlce-tcltk.htm on my few screenshots within Perl+Tcl::Tk using it...

    Must be able using it on Linux as well, although I did not tried namely that font there, because my Tk Unicode apps run on Linux w/o problems even without that font (however I don't have enough Chinese knowledge to notice errors :)

    Best regards,
    Courage, the Cowardly Dog

      Thanks Courage.

      My script is working 100% okay in Windows anyway. The problem is some of the characters displaying properly in Windows are not displaying properly in Solaris/Linux.

      Looking at http://mini.net/tcl/11392, there may be issues using Arial Unicode MS on Solaris/Linux systems and I'm not sure where in those Solaris/Linux boxes I'd put it.

      If you have a spare moment, you can try running my script on your Linux box to see if all the Chinese characters appear properly. Could be you have additional fonts loaded, but if it's the standard Linux installation, it'd be interesting to see if you get the same problem.

      BTW, even though I'm an ABC Chinese, I can't read a lick of Chinese. I have to get someone else to give me the Chinese and then I convert it to the 16-bit codes.

      The errors with Solaris/Linux appear on the screen as 16-bit codes (eg, \x{6c2e}) instead of the actual Chinese character. From the menu, start with CONFIG->Chinese, then click on EVENT ENTRY. (It will need Tk804. With Tk800, everything appears as garbage).
        due to some concrete difficulties I can't try your code within required configuration right now. I can try later.

        However could you please provide screenshot with a problem?

        Best regards,
        Courage, the Cowardly Dog

        now I gained access to linux machine, tried your script but unfortunately my perlTk is 800, so no luck.

        BUT I extracted unicode text, made it Tcl and now you can see all fonts are okay (at least on mandrake10), where I did not did any font setup.

        See screenshot at http://vkonovalov.ru/tcltk-misc/a,tcl.jpg

        here is Tk code:

        pack [text .t] .t insert end " No Operator (61) \u5F85\u64CD\u4F5C\u54E1 Power Down (63) \u96FB\u6E90\u4E2D\u65B7 Contactor Repair (124) \u4FEE\u593E\u8173 Change Cleaning Disk (125) \u66F4\u63DB\u786C\u789F Change Loadboard (127) \u66F4\u63DB\u6E2C\u8A66\u677F Change LN2 (128) \u66F4\u63DB\u6DB2\u614B\u6C2E"
        I don't remember though, did I or not installed Chinese support from rpmdrake...

        Best regards,
        Courage, the Cowardly Dog

Re^3: Chinese font problem in Perl/Tk
by zentara (Cardinal) on Jan 06, 2005 at 12:03 UTC
    but didn't see any Asian characters in there. So without ever specifying a font in my script, I'm wondering what font it chose and how it managed to display (almost all of) the Chinese characters.

    I admit I am not very familiar with unicode and asian fonts. I do remember, however, that when I build and install Tk, one of the tests it runs thru is to fill up a window with alot of asian characters, even though I don't have any asian fonts installed. It probably does it just like you did, specifying the unicode characters with Encode? One of the test scripts in the root of the Tk source tree is called "chfont" and it displays asian characters.

    use strict; use Tk; use Encode qw(decode); my $face = (@ARGV) ? shift : 'fixed'; my @headers = <DATA>; my $mw = MainWindow->new; foreach my $text (@headers) { my $str = decode('MIME-Header' => $text); $mw->Label(-text => $str, -font => [$face,14])->pack; } MainLoop; __DATA__ From: =?Big5?B?qfq8dw==?= <tukb122@ms12.url.com.tw> Subject:=?big5?Q?=A9_=A4b=A5=D8=BF=FD=A7=F3=B7s!!?= Subject: =?Big5?B?o7Ck+S4uLi4uLi4uLi4uLi4uLi4uLg==?= From: =?Big5?B?tW6//bdqtE2k3sC6?= <twpalm@pchome.com.tw> Subject: =?Big5?B?rf6xeqq6uvSvuLVuv/23arRNpN7Aug==?= Subject:=?big5?Q?=A7K=B6O=A5=F4=A5=B4=A4=A4=B4=E4=AA=F8=B3~=B9q=B8=DC? += Subject:=?big5?Q? =A4u=A7@=B2=D6=A4F=A4@=A4=D1=BA=D6=A7Q=B0e=B5=B9=A7A + ^0^ =A6A=A6=B8=B7P=C1=C2=BE=E3=B2z=B3o=A5=F7=B8=EA=AE=C6=AA=BA=A4H +!!! ?= Subject:=?big5?Q? =A4u=A7@=B2=D6=A4F=A4@=A4=D1=BA=D6=A7Q=B0e=B5=B9=A7A + ^0^ =A6A=A6=B8=B7P=C1=C2=BE=E3=B2z=B3o=A5=F7=B8=EA=AE=C6=AA=BA=A4H +!!! ?= Subject:=?big5?Q? =A4u=A7@=B2=D6=A4F=A4@=A4=D1=BA=D6=A7Q=B0e=B5=B9=A7A + ^0^ =A6A=A6=B8=B7P=C1=C2=BE=E3=B2z=B3o=A5=F7=B8=EA=AE=C6=AA=BA=A4H +!!! ?=

    I'm not really a human, but I play one on earth. flash japh
      Good idea, zentara. I thought for sure I could take the "chfont" test script and plug in my problem characters-codes to see if they displayed properly.

      But before I had a chance to try that, I ran the code you attached and, lo and behold -- it has similar problems:

      • worked on Windows (except for the "\xA9" appearing when run on each OS)
      • had problems on Solaris 2.6, Solaris 2.8, and Linux with four of the Asian characters appearing as "\x{54ea}", "\x{60a8}", "\x{4f60}", and "\x{4efd}" instead of the Asian character.


      I couldn't find chfont.pl in the Tk directories (ActivePerl distribution) on Linux nor Solaris 2.8. But I did run the widget demo on both Linux and Solaris 2.8. The Traditional Chinese, Hebrew, Japanese, and Korean fonts appeared properly. I think the Russian appeared okay. Some of the Greek characters appeared okay and some didn't. But none of the Arabic and Simplified Chinese characters appeared properly.

      Looking at its code, it specified a helvetica font like I was using.

      (UPDATE: I've discovered this doesn't run by itself. You need to run widget and choose the "Labels and Unicode Text" demo. And not just any perl's widget, but ActivePerl's 5.8.x widget. I couldn't find a Unicode Text demo in CPAN's perl 5.8.5)

      # unicodeout.pl use vars qw/$TOP/; use subs qw/unicodeadd/; sub unicodeout { # This demonstration script shows how you can produce output (in l +abel # widgets) using many different alphabets. my($demo) = @_; $TOP = $MW->WidgetDemo( -name => $demo, -text => 'This is a sample of Perl/Tk\'s support for langu +ages that use non-Western character sets. However, what you will act +ually seebelow depends largely on what character sets you have instal +led, and what you see for characters that are not present varies grea +tly between platforms as well. The strings are written in Perl Unico +de characters using the \\x{XXXX} escape sequence so as to do so in a + portable fashion.', -title => 'Unicode Label Demonstration', -iconname => 'unicodeout', ); my $unicode_wait = $TOP->Label( -text => 'Please wait while loading fonts...', -font => 'Helvetica 12 italic', )->pack; $TOP->update; # Processing when some characters are missing might take a while, +so make # sure we're displaying something in the meantime. $TOP->Busy; unicodeadd $TOP, 'Arabic', "\x{FE94}\x{FEF4}\x{FE91}\x{FEAE}\x{FECC}\x{FEDF}\x{FE8D}\x{FE94}\ +x{FEE4}\x{FEE0}\x{FEDC}\x{FEDF}\x{FE8D}"; unicodeadd $TOP, "Trad. Chinese", "\x{4E2D}\x{570B}\x{7684}\x{6F22 +}\x{5B57}"; unicodeadd $TOP, "Simpl. Chinese", "\x{6C49}\x{8BED}"; unicodeadd $TOP, 'Greek', "\x{0395}\x{03BB}\x{03BB}\x{03B7}\x{03BD}\x{03B9}\x{03BA}\x{03AE}\ +x{03B3}\x{03BB}\x{03CE}\x{03C3}\x{03C3}\x{03B1}"; unicodeadd $TOP, 'Hebrew', "\x{05DD}\x{05D9}\x{05DC}\x{05E9}\x{05D5}\x{05E8}\x{05D9}\x{05DC}\ +x{05D9}\x{05D0}\x{05E8}\x{05E9}\x{05D9}"; unicodeadd $TOP, 'Japanese', "\x{65E5}\x{672C}\x{8A9E}\x{306E}\x{3072}\x{3089}\x{304C}\x{306A}\ +x{6F22}\x{5B57}\x{3068}\x{30AB}\x{30BF}\x{30AB}\x{30CA}"; unicodeadd $TOP, 'Korean', "\x{B300}\x{D55C}\x{BBFC}\x{AD6D}\x{C758}\x{D55C}\x{AE00}"; unicodeadd $TOP, 'Russian', "\x{0420}\x{0443}\x{0441}\x{0441}\x{043A}\x{0438}\x{0439}\x{044F}\ +x{0437}\x{044B}\x{043A}"; # We're done processing, so change things back to normal running. $unicode_wait->destroy; $TOP->Unbusy; } # end unicodeout sub unicodeadd { my ($w, $language, @args) = @_; my $sample = join('', @args); my $l1 = $w->Label(-text => "$language: ", qw/-anchor nw -pady 0/) +; my $l2 = $w->Label(-text => $sample, qw/-anchor nw -width 30 -pady + 0/); $l1->grid($l1, $l2, qw/-sticky ew -pady 0/); $l1->gridConfigure(qw/-padx 1m/); } # end unicodeadd 1;
        I think its time you posted this on the newsgroup comp.lang.perl.tk where the international experts read.

        I'm not really a human, but I play one on earth. flash japh