Updated 2011-07-04 17:38:10 by RLE

Richard Suchenwirth - By popular demand, here's a little Korean editor that offers all 2350 Hangul from KSC5601/Unicode 1.0. Such many keys could have been put in one scrollable keyboard widget, but I thought it more ergonomic to distribute them depending on the initial consonant jamo (letter, or doubled letter) to 19 distinct keyboards, one of which will be shown if you select that jamo. So, the editor has

  • a minimal menu, containing Open..., Save..., Exit
  • a text widget
  • a Jamo button bar to select initial consonant
  • a Hangul keyboard implemented as text widget

See also Hanglish, Keyboard widget. No warranty, but enjoy!
 set font {{Bitstream Cyberbit} 11} ;# or whichever you have
 wm title . "HangulType 0.1"
 set intro "
  \u394B\u3558\u3CA0\u3883\u39C5 Welcome to HangulType 0.1! (Richard Suchenwirth 2001)
  Click one of the white Jamo (consonant) buttons
  to get buttons for Hangul starting with that Jamo here.
  Keyboard keys may be used for all other characters.
 . config -menu [menu .m]
 menu .m.file
 .m.file add command -label Open.. -command {Open .t}
 .m.file add command -label Save.. -command {Save .t}
 .m.file add separator
 .m.file add command -label Exit -command exit
 .m add cascade -label File -menu .m.file

 proc Open w {
    set fn [tk_getOpenFile -defaultext .txt]
    if {$fn!=""} {
        set f [open $fn]
        fconfigure $f -encoding unicode
        $w delete 1.0 end
        set txt [read $f [file size $fn]]
        regsub \uFEFF $txt "" txt
        $w insert end $txt
        close $f
 proc Save w {
    set fn [tk_getSaveFile -defaultext .txt]
    if {$fn!=""} {
        set f [open $fn w]
        fconfigure $f -encoding unicode
        puts -nonewline $f \uFEFF
        puts -nonewline $f [$w get 1.0 end]
        close $f
 text .t -font $font -height 8 -wrap word
 frame .f
 set n 0
 foreach {key range} {
    \u3131 0x3400-0x34aa \u3132 0x34ab-0x3522
    \u3134 0x3523-0x35af \u3137 0x35b0-0x362f
    \u3138 0x3639-0x3685 \u3139 0x3686-0x3704
    \u3141 0x3705-0x3785 \u3142 0x3786-0x3806
    \u3143 0x3807-0x384f \u3145 0x3850-0x38f2
    \u3146 0x38f3-0x3948 \u3147 0x3949-0x3a18
    \u3148 0x3a19-0x3a9f \u3149 0x3aa0-0x3af1
    \u314a 0x3af2-0x3b61 \u314b 0x3b62-0x3bcc
    \u314c 0x3bcd-0x3c36 \u314d 0x3c37-0x3c9f
    \u314e 0x3ca0-0x3d2d
 } {
    button .f.[incr n] -text $key -command "keys .k $range" \
        -bg white -font $font -pady 0
 proc keys {w range} {
    $w config -state normal -cursor watch; update
    $w delete 1.0 end
    regexp {(.+)-(.+)} $range -> from to
    for {set i [expr $from]} {$i<=$to} {incr i} {
        set c [subst \\u[format %04.4X $i]]
        button $w.$i -text $c -font $::font\
            -command ".t insert insert $c" -pady 0
        $w window create end -window $w.$i
    $w config -state disabled -cursor hand2
 eval pack [winfo children .f] -side left
 pack .t .f -fill x
 text .k -height 17 -font $font -bg gray -setgrid 1
 pack .k -fill both -expand true
 .k insert end $intro
 .k config -state disabled
 focus .t

Known problem: The editor runs fine with the Bitstream Cyberbit font [1], but I was unable to write a file in EUC-KR encoding, which should be the most natural for Korea. The problem is that the frequent 2350 Hangul are twice in Unicode, on pages 34..3D in Unicode 1.0. I used that because it has nice contiguous ranges (good for the keyboard). In newer Unicode versions, the giant set of >14000 Hangul was put to pages AC..D7. Cyberbit can deal with both sub-encodings, but Tcl's euc-kr encoding table seems not to support the older set. Therefore, unicode (UTF-16) was taken as encoding here. With leading byte order mark (\uFEFF), such files can also be opened and printed with Notepad (on WinNT, at least - if you also select Cyberbit as font there).