1# unicodeout.rb -- 2# 3# This demonstration script shows how you can produce output (in label 4# widgets) using many different alphabets. 5# 6# based on Tcl/Tk8.4.4 widget demos 7 8if defined?($unicodeout_demo) && $unicodeout_demo 9 $unicodeout_demo.destroy 10 $unicodeout_demo = nil 11end 12 13$unicodeout_demo = TkToplevel.new {|w| 14 title("Unicode Label Demonstration") 15 iconname("unicodeout") 16 positionWindow(w) 17} 18 19base_frame = TkFrame.new($unicodeout_demo).pack(:fill=>:both, :expand=>true) 20 21TkLabel.new(base_frame, 22 :font=>$font, :wraplength=>'5.4i', :justify=>:left, 23 :text=><<EOL).pack(:side=>:top) 24This is a sample of Tk's support for languages that use non-Western \ 25character sets. However, what you will actually see below depends \ 26largely on what character sets you have installed, and what you see \ 27for characters that are not present varies greatly between platforms as well. \ 28Please try to click the 'See Code' button, \ 29and click the 'Rerun Demo' button after editing \ 30(the source file is not changed) \ 31the definition of @@font on the Unicodeout_SampleFrame class. 32The strings are written in Tcl using UNICODE characters \ 33using the \\uXXXX escape so as to do so in a portable fashion. 34 35ATTENTION: 36The strings are converted to the encoded string objects \ 37(completed to rewrite Tcl's escapes) by Tk::UTF8_String method. \ 38And the Tk::UTF8_String objects are passed to the label widgets. 39EOL 40 41TkFrame.new(base_frame){|f| 42 pack(:side=>:bottom, :fill=>:x, :pady=>'2m') 43 44 TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ 45 $unicodeout_demo.destroy 46 $unicodeout_demo = nil 47 }).pack(:side=>:left, :expand=>true) 48 49 TkButton.new(f, :text=>'See Code', :width=>15, :command=>proc{ 50 showCode 'unicodeout' 51 }).pack(:side=>:left, :expand=>true) 52} 53 54wait_msg = TkLabel.new(base_frame, 55 :text=>"Please wait while loading fonts...", 56 :font=>"Helvetica 12 italic").pack 57 58class Unicodeout_SampleFrame < TkFrame 59 @@font = $font 60 # @@font = 'Helvetica 14' 61 # @@font = 'Courier 12' 62 # @@font = 'clearlyu 16' 63 # @@font = 'fixed 12' 64 # @@font = 'Times 12' 65 # @@font = 'Newspaper 12' 66 # @@font = '{New century schoolbook} 12' 67 68 def initialize(base) 69 super(base) 70 grid_columnconfig(1, :weight=>1) 71 end 72 73 def add_sample(lang, *args) 74 sample_txt = Tk::UTF8_String(args.join('')) 75 l = TkLabel.new(self, :font=>@@font, :text=>lang+':', 76 :anchor=>:nw, :pady=>0) 77 #s = TkLabel.new(self, :font=>@@font, :text=>sample_txt, 78 s = TkLabel.new(self, :font=>TkFont.new(@@font), :text=>sample_txt, 79 :anchor=>:nw, :width=>30, :pady=>0) 80 Tk.grid(l, s, :sticky=>:ew, :pady=>0) 81 l.grid_config(:padx, '1m') 82 end 83end 84f = Unicodeout_SampleFrame.new(base_frame) 85f.pack(:expand=>true, :fill=>:both, :padx=>'2m', :pady=>'1m') 86 87# Processing when some characters are missing might take a while, so make 88# sure we're displaying something in the meantime... 89 90oldCursor = $unicodeout_demo.cursor 91$unicodeout_demo.cursor('watch') 92Tk.update 93 94f.add_sample('Arabic', 95 '\uFE94\uFEF4\uFE91\uFEAE\uFECC\uFEDF\uFE8D\uFE94', 96 '\uFEE4\uFEE0\uFEDC\uFEDF\uFE8D') 97f.add_sample('Trad. Chinese', '\u4E2D\u570B\u7684\u6F22\u5B57') 98f.add_sample('Simpl. Chinese', '\u6C49\u8BED') 99f.add_sample('Greek', 100 '\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AE ', 101 '\u03B3\u03BB\u03CE\u03C3\u03C3\u03B1') 102f.add_sample('Hebrew', 103 '\u05DD\u05D9\u05DC\u05E9\u05D5\u05E8\u05D9 ', 104 '\u05DC\u05D9\u05D0\u05E8\u05E9\u05D9') 105f.add_sample('Japanese', 106 '\u65E5\u672C\u8A9E\u306E\u3072\u3089\u304C\u306A, ', 107 '\u6F22\u5B57\u3068\u30AB\u30BF\u30AB\u30CA') 108f.add_sample('Korean', '\uB300\uD55C\uBBFC\uAD6D\uC758 \uD55C\uAE00') 109f.add_sample('Russian', 110 '\u0420\u0443\u0441\u0441\u043A\u0438\u0439 ', 111 '\u044F\u0437\u044B\u043A') 112 113wait_msg.destroy 114$unicodeout_demo.cursor(oldCursor) 115