3 proc manyset {list args} {
4 foreach val $list var $args {
17 while {[gets $f l] >= 0} {
18 if {![regexp {^"(.*)",$} $l dummy l]} {
23 manyset $l cols rows colours cpp
26 set mulcols [expr {$cols*$mul+$inter}]
27 set mulrows [expr {$rows*$mul+$inter}]
28 append o "\"$mulcols $mulrows 9 1\",\n"
29 for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 }
30 } elseif {$y==-2} { # first pixel
41 } elseif {$y==-1} { # 2nd pixel but we've already printed ours
43 set ybit [expr {1<<$y}]
47 foreach c [split $l ""] {
49 if {$x >= $unk_l && $x <= $unk_r} {
53 foreach {min max context got} $foolist {
55 if {$x >= $min && $x <= $max} {
56 set how [lindex {a b} $ab]
65 set p [string toupper $how]
66 incr wordmap($x) $ybit
68 default { error "$c ?" }
70 append ol "[string repeat $p [expr {$mul-$inter}]][
71 string repeat + $inter]"
72 append olh [string repeat + $mul]
78 set olhn [string repeat $olh $inter]
79 if {!$y} { append o $olhn }
80 append o [string repeat $ol [expr {$mul-1}]]
85 set data [exec xpmtoppm << $o]
86 image create photo main_image -data $xpm
94 frame .d -width $mulcols -height [expr {$csrh+$mulrows+$gotsh}]
97 image create bitmap main_image
98 label .d.mi -image $mi -borderwidth 0
100 frame .d.csr -bg black -width $mulcols -height $csrh
101 frame .d.got -bg black -width $mulcols -height $gotsh
103 foreach {min max context got} $foolist {
104 frame .d.got.m$min -bd 0 -background \#888
105 label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0
106 pack .d.got.m$min.l -padx 1 -pady 1
107 place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0
110 set imcsr [image create bitmap -data \
111 {#define csr_width 11
112 #define csr_height 11
113 static unsigned char csr_bits[] = {
114 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x21, 0x04, 0x22, 0x02, 0x25, 0x05,
115 0xaa, 0x02, 0x74, 0x01, 0xa8, 0x00, 0x70, 0x00, 0x20, 0x00};
119 label .d.csr.csr.l -image $imcsr -compound left
120 entry .d.csr.csr.e -bd 0
121 pack .d.csr.csr.l -side left
123 frame .d.csr_0 -bg white -height $mulrows -width 1
124 frame .d.csr_1 -bg white -height $mulrows -width 1
126 place .d.csr -x 0 -y 0
127 place .d.mi -x 0 -y $csrh
128 place .d.got -x 0 -y [expr {$csrh+$mulrows}]
134 set cur_already [expr {[llength $foolist]/4-1}]
135 set cur_mode 1 ;# one of: 0 1 already text
138 set cur_1 [expr {$unk_r+1}]
143 if {![string compare $t $last_ht]} return
144 eval destroy [grid slaves .help]
145 set y 0; foreach l $t {
146 set x 0; foreach c $l {
147 set w .help.at${x}x${y}
149 grid $w -row $y -column $x -padx 5
157 proc recursor/0 {} { recursor//01 0 }
158 proc recursor/1 {} { recursor//01 1 }
159 proc recursor//01 {z1} {
160 global mul rhsmost_max cols foolist
162 .d.csr.csr.l configure -text {adjust}
163 place .d.csr.csr -x [expr {$cur*$mul - 7}]
164 bind_key space { othercursor }
165 bind_leftright cur_$z1 0 [expr {$cols-1}]
166 if {[llength $foolist]} {
167 bind_key Tab { set cur_mode already; recursor }
172 if {$cur_0 != $cur_1} {
178 {{<- ->} {move cursor, adjusting area to define}}
179 {Space {switch to moving other cursor}}
180 {Return {confirm location, enter letter(s)}}
181 {Tab {switch to correcting earlier ocr}}
184 proc othercursor {} {
186 set cur_mode [expr {!$cur_mode}]
190 proc recursor/text {} {
192 {Return {confirm entry of new glyph}}
193 {Escape {abandon entry}}
196 .d.csr.csr.l configure -text {define:}
197 pack .d.csr.csr.e -side left
200 binary scan [.d.csr.csr.e get] h* hex
201 if {[string length $hex]} {
202 RETURN_RESULT DEFINE "$cur_0 $cur_1 $hex"
207 pack forget .d.csr.csr.e
213 proc recursor/already {} {
216 global cur_already mul
217 global foolist cur_already mul
218 .d.csr.csr.l configure -text {correct}
219 set rmax [lindex $foolist [expr {$cur_already*4}]]
220 place .d.csr.csr -x [expr {$rmax*$mul-3}]
223 bind_leftright cur_already 0 [expr {[llength $foolist]/4-1}]
224 bind_key Tab { bind_key Delete {}; set cur_mode 1; recursor }
226 RETURN_RESULT DELETE [lrange $foolist \
227 [expr $cur_already*4] \
228 [expr $cur_already*4+1]]
231 {{<- ->} {move cursor, selecting glyph to correct}}
232 {Del {clear this glyph from the recognition database}}
233 {Tab {switch to selecting area to define as new glyph}}
237 proc bind_key {k proc} {
239 bind . <Key-$k> $proc
240 set keybindings($k) [expr {!![string length $proc]}]
242 proc unbind_all_keys {} {
244 foreach k [array names keybindings] { bind_key $k {} }
247 proc bind_leftright {var min max} {
248 bind_key Left [list leftright $var $min $max -1]
249 bind_key Right [list leftright $var $min $max +1]
251 proc leftright {var min max inc} {
255 if {$vnew < $min || $vnew > $max} return
261 global csrh cur_mode cur_0 cur_1 mul
263 place .d.csr_$z1 -y $csrh -x [expr {[set cur_$z1] * $mul}]
271 # <context> <ncharacters> <hex>...
275 # $database($context 0x<bits> 0x<bits>...) = $hex
277 proc read_database {} {
279 set f [open database r]
280 while {[gets $f l] >= 0} {
281 if {![regexp {^(\w+) (\d+) ([0-9a-f]{2}+)$} $l \
282 dummy context strl strh]} {
285 binary scan $strw h* strh
286 if {[string length $strh] != $strl*2} { error "$strh $strl" }
287 gets $f l; set width [format %d $l]
289 for {set x 0} {$x < $width} {incr x} {
290 gets $f l; lappend bm [format %x 0x$l]
292 set database($bm) $strh
296 proc write_database {} {
299 foreach bm [array names database] {
300 set strh $database($bm)
301 set strs [binary format h* $strh]
302 set strdo [format "%d %s" [expr {[string length $strh]/2}] $strh]
303 set o "[lindex $bm 0] $strdo\n"
304 append o [format "%d\n" [expr {[llength $bm]-1}]]
305 foreach x [lrange $bm 1 end] { append o "$x\n" }
308 foreach o [lsort $ol] {
313 proc update_database/DEFINE {c0 c1 strh} {
314 global foolist unk_l unk_context wordmap database
315 if {$c0 > $c1} { manyset [list $c0 $c1] c1 c0 }
317 set ncontext $unk_context
319 foreach {l r context got} $foolist {
320 if {$l==$c0} { set ncontext $context; break }
322 if {![exists ncontext]} {
323 puts stderr "must start at letter LHS!"
328 for {set x $c0} {$x < $c1} {incr x} {
329 lappend bm [format %x $wordmap($x)]
331 set database($bm) $strh
336 proc RETURN_RESULT {how what} {
337 place forget .d.csr.csr
338 pack forget .d.csr.csr.e
339 helptext {{{ Processing }}}
343 eval update_database/$how $what
346 # bind . <Key-space> {}
360 set f [open text.xpm]