3 proc manyset {list args} {
4 foreach val $list var $args {
28 while {[gets $f l] >= 0} {
29 if {![regexp {^"(.*)",$} $l dummy l]} {
34 manyset $l cols rows colours cpp
37 set mulcols [expr {$cols*$mul+$inter}]
38 set mulrows [expr {$rows*$mul+$inter}]
39 append o "\"$mulcols $mulrows 9 1\",\n"
40 for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 }
41 } elseif {$y==-2} { # first pixel
52 } elseif {$y==-1} { # 2nd pixel but we've already printed ours
54 set ybit [expr {1<<$y}]
58 foreach c [split $l ""] {
60 if {$x >= $unk_l && $x <= $unk_r} {
64 foreach {min max context got} $foolist {
66 if {$x >= $min && $x <= $max} {
67 set how [lindex {a b} $ab]
76 set p [string toupper $how]
77 incr wordmap($x) $ybit
79 default { error "$c ?" }
81 append ol "[string repeat $p [expr {$mul-$inter}]][
82 string repeat + $inter]"
83 append olh [string repeat + $mul]
89 set olhn [string repeat $olh $inter]
90 if {!$y} { append o $olhn }
91 append o [string repeat $ol [expr {$mul-1}]]
99 set xpm [exec xpmtoppm << $o]
104 frame .d -width $mulcols -height [expr {$csrh+$mulrows+$gotsh}]
106 set mi [image create photo -data $xpm]
107 label .d.mi -image $mi -borderwidth 0
109 frame .d.csr -bg black -width $mulcols -height $csrh
110 frame .d.got -bg black -width $mulcols -height $gotsh
112 foreach {min max context got} $foolist {
113 frame .d.got.m$min -bd 0 -background \#888
114 label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0
115 pack .d.got.m$min.l -padx 1 -pady 1
116 place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0
119 set imcsr [image create bitmap -data \
120 {#define csr_width 11
121 #define csr_height 11
122 static unsigned char csr_bits[] = {
123 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x21, 0x04, 0x22, 0x02, 0x25, 0x05,
124 0xaa, 0x02, 0x74, 0x01, 0xa8, 0x00, 0x70, 0x00, 0x20, 0x00};
128 label .d.csr.csr.l -image $imcsr -compound left
129 entry .d.csr.csr.e -bd 0
130 pack .d.csr.csr.l -side left
132 frame .d.csr_0 -bg white -height $mulrows -width 1
133 frame .d.csr_1 -bg white -height $mulrows -width 1
135 place .d.csr -x 0 -y 0
136 place .d.mi -x 0 -y $csrh
137 place .d.got -x 0 -y [expr {$csrh+$mulrows}]
143 set cur_already [expr {[llength $foolist]/4-1}]
144 set cur_mode 1 ;# one of: 0 1 already text
147 set cur_1 [expr {$unk_r+1}]
152 if {![string compare $t $last_ht]} return
153 eval destroy [grid slaves .help]
154 set y 0; foreach l $t {
155 set x 0; foreach c $l {
156 set w .help.at${x}x${y}
158 grid $w -row $y -column $x -padx 5
166 proc recursor/0 {} { recursor//01 0 }
167 proc recursor/1 {} { recursor//01 1 }
168 proc recursor//01 {z1} {
169 global mul rhsmost_max cols foolist
171 .d.csr.csr.l configure -text {adjust}
172 place .d.csr.csr -x [expr {$cur*$mul - 7}]
173 bind_key space { othercursor }
174 bind_leftright cur_$z1 0 [expr {$cols-1}]
175 if {[llength $foolist]} {
176 bind_key Tab { set cur_mode already; recursor }
181 if {$cur_0 != $cur_1} {
187 {{<- ->} {move cursor, adjusting area to define}}
188 {Space {switch to moving other cursor}}
189 {Return {confirm location, enter letter(s)}}
190 {Tab {switch to correcting earlier ocr}}
193 proc othercursor {} {
195 set cur_mode [expr {!$cur_mode}]
199 proc recursor/text {} {
201 {Return {confirm entry of new glyph}}
202 {Escape {abandon entry}}
205 .d.csr.csr.l configure -text {define:}
206 pack .d.csr.csr.e -side left
209 binary scan [.d.csr.csr.e get] h* hex
210 if {[string length $hex]} {
211 RETURN_RESULT DEFINE "$cur_0 $cur_1 $hex"
216 pack forget .d.csr.csr.e
222 proc recursor/already {} {
225 global cur_already mul
226 global foolist cur_already mul
227 .d.csr.csr.l configure -text {correct}
228 set rmax [lindex $foolist [expr {$cur_already*4}]]
229 place .d.csr.csr -x [expr {$rmax*$mul-3}]
232 bind_leftright cur_already 0 [expr {[llength $foolist]/4-1}]
233 bind_key Tab { bind_key Delete {}; set cur_mode 1; recursor }
235 RETURN_RESULT DELETE [lrange $foolist \
236 [expr $cur_already*4] \
237 [expr $cur_already*4+1]]
240 {{<- ->} {move cursor, selecting glyph to correct}}
241 {Del {clear this glyph from the recognition database}}
242 {Tab {switch to selecting area to define as new glyph}}
246 proc bind_key {k proc} {
248 bind . <Key-$k> $proc
249 set keybindings($k) [expr {!![string length $proc]}]
251 proc unbind_all_keys {} {
253 foreach k [array names keybindings] { bind_key $k {} }
256 proc bind_leftright {var min max} {
257 bind_key Left [list leftright $var $min $max -1]
258 bind_key Right [list leftright $var $min $max +1]
260 proc leftright {var min max inc} {
264 if {$vnew < $min || $vnew > $max} return
270 global csrh cur_mode cur_0 cur_1 mul
272 place .d.csr_$z1 -y $csrh -x [expr {[set cur_$z1] * $mul}]
280 # <context> <ncharacters> <hex>...
284 # $database($context 0x<bits> 0x<bits>...) = $hex
286 proc read_database {} {
288 set f [open database r]
289 while {[gets $f l] >= 0} {
290 if {![regexp {^(\w+) (\d+) ([0-9a-f]{2}+)$} $l \
291 dummy context strl strh]} {
294 binary scan $strw h* strh
295 if {[string length $strh] != $strl*2} { error "$strh $strl" }
296 gets $f l; set width [format %d $l]
298 for {set x 0} {$x < $width} {incr x} {
299 gets $f l; lappend bm [format %x 0x$l]
301 set database($bm) $strh
305 proc write_database {} {
308 foreach bm [array names database] {
309 set strh $database($bm)
310 set strs [binary format h* $strh]
311 set strdo [format "%d %s" [expr {[string length $strh]/2}] $strh]
312 set o "[lindex $bm 0] $strdo\n"
313 append o [format "%d\n" [expr {[llength $bm]-1}]]
314 foreach x [lrange $bm 1 end] { append o "$x\n" }
317 foreach o [lsort $ol] {
322 proc update_database/DEFINE {c0 c1 strh} {
323 global foolist unk_l unk_context wordmap database
324 if {$c0 > $c1} { manyset [list $c0 $c1] c1 c0 }
326 set ncontext $unk_context
328 foreach {l r context got} $foolist {
329 if {$l==$c0} { set ncontext $context; break }
331 if {![exists ncontext]} {
332 puts stderr "must start at letter LHS!"
337 for {set x $c0} {$x < $c1} {incr x} {
338 lappend bm [format %x $wordmap($x)]
340 set database($bm) $strh
345 proc RETURN_RESULT {how what} {
346 place forget .d.csr.csr
347 pack forget .d.csr.csr.e
348 helptext {{{ Processing }}}
352 eval update_database/$how $what
355 # bind . <Key-space> {}