chiark / gitweb /
WIP island determination; pixmap resolver now corrupts the database, yay!
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 17 Jun 2009 21:19:26 +0000 (22:19 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 17 Jun 2009 21:19:26 +0000 (22:19 +0100)
pctb/yppsc-ocr-resolver

index a733e734a28b17f247e1cf0fe770f9b37f66198f..2ba7c01655246745e45679d8d4f59e883318eddb 100755 (executable)
@@ -87,7 +87,7 @@ static unsigned char csr_bits[] = {
     button .d.pe.ok -text OK
     pack .d.pe.grid .d.pe.ok -side left
 
     button .d.pe.ok -text OK
     pack .d.pe.grid .d.pe.ok -side left
 
-    pack .d.mi .d.got .d.ctx -side top
+    pack .d.mi .d.ctx -side top
     pack .d
 
     frame .help
     pack .d
 
     frame .help
@@ -396,63 +396,49 @@ proc recursor {} {
     recursor/$cur_mode
 }
 
     recursor/$cur_mode
 }
 
-
-#---------- database read and write ----------
-
-# OUT OF DATE
-# database format:
-# series of glyphs:
-#   <context> <ncharacters> <hex>...
-#   width
-#   <hex-bitmap>
-
-# $database($context 0x<bits> 0x<bits>...) = $hex
-
-set database_header {# ypp-sc-tools pctb font v1}
+#---------- database read and write common wrapper ----------
 
 proc db_getsl {f} {
     if {[gets $f l] < 0} { error "unexpected db eof" }
     return $l
 }
 
 proc db_getsl {f} {
     if {[gets $f l] < 0} { error "unexpected db eof" }
     return $l
 }
-    
-proc read_database {} {
-    global database database_header rows database_fn
+
+proc read_database {fn} {
+    global reqkind database database_fn
+    upvar #0 database_magic/$reqkind magic
     catch { unset database }
     catch { unset database }
-    set database_fn ./charset-$rows.txt
+
+    set database_fn $fn
     if {![file exists $database_fn]} return
     set f [open $database_fn r]
     if {![file exists $database_fn]} return
     set f [open $database_fn r]
-    if {[string compare [db_getsl $f] $database_header]} { error "$l ?" }
-    if {([db_getsl $f])+0 != $rows} { error "wrong h ?" }
+    if {[string compare [db_getsl $f] $magic]} { error "$l $reqkind ?" }
+
+    read_database_header/$reqkind $f
     while 1 {
     while 1 {
-       set context [db_getsl $f]
-       if {![string length $context]} continue
-       if {[regexp {^\#} $context]} continue
-       if {![string compare . $context]} break
-
-       set bm $context
-       set strq [db_getsl $f]
-       while 1 {
-           set l [db_getsl $f]
-           if {![string length $l]} break
-           lappend bm [format %x 0x$l]
-       }
-       set database($bm) $strq
+       set l1 [db_getsl $f]
+    
+       if {![string length $l1]} continue
+       if {[regexp {^\#} $l1]} continue
+       if {![string compare . $l1]} break
+
+       read_database_entry/$reqkind $f $l1
     }
     close $f
 }
 
 proc write_database {} {
     }
     close $f
 }
 
 proc write_database {} {
-    global database rows database_fn database_header
+    global reqkind database_fn database
+    upvar #0 database_magic/$reqkind magic
+    
+    set f [open $database_fn.new w]
+    puts $f $magic
+
+    write_database_header/$reqkind $f
+
     set ol {}
     foreach bm [array names database] {
     set ol {}
     foreach bm [array names database] {
-       set strq $database($bm)
-       set o "[lindex $bm 0]\n$strq\n"
-       foreach x [lrange $bm 1 end] { append o "$x\n" }
-       
-       lappend ol $o
+       append ol [format_database_entry/$reqkind $bm $database($bm)]
     }
     }
-    set f [open $database_fn.new w]
-    puts $f "$database_header\n$rows\n"
     foreach o [lsort $ol] {
        puts $f $o
     }
     foreach o [lsort $ol] {
        puts $f $o
     }
@@ -461,6 +447,71 @@ proc write_database {} {
     file rename -force $database_fn.new $database_fn
 }
 
     file rename -force $database_fn.new $database_fn
 }
 
+#---------- pixmap database read and write ----------
+
+set database_magic/pixmap {# ypp-sc-tools pctb pixmaps v1}
+
+proc read_database_header/pixmap {f} { }
+proc read_database_entry/pixmap {f def} {
+    global database
+
+    set im ""
+    
+    set p3 [db_getsl $f];       append im $p3    "\n"
+    if {[string compare $p3 P3]} { error "$p3 ?" }
+
+    set wh [db_getsl $f];       append im $wh    "\n";   manyset $wh w h
+    set depth [db_getsl $f];    append im $depth "\n"
+
+    for {set y 0} {$y < $h} {incr y} {
+       set line [db_getsl $f]; append im $line  "\n"
+    }
+    set database($im) $def
+}
+proc write_database_header/pixmap {f} { }
+proc format_database_entry/pixmap {im def} {
+    return "$im\n$def"
+}
+
+#---------- character database read and write ----------
+
+# OUT OF DATE
+# database format:
+# series of glyphs:
+#   <context> <ncharacters> <hex>...
+#   width
+#   <hex-bitmap>
+
+# $database($context 0x<bits> 0x<bits>...) = $hex
+
+set database_magic/char {# ypp-sc-tools pctb font v1}
+    
+proc read_database_header/char {f} {
+    global rows
+    if {([db_getsl $f])+0 != $rows} { error "wrong h ?" }
+}
+proc read_database_entry/char {f context} {
+    global database
+    set bm $context
+    set strq [db_getsl $f]
+    while 1 {
+       set l [db_getsl $f]
+       if {![string length $l]} break
+       lappend bm [format %x 0x$l]
+    }
+    set database($bm) $strq
+}
+
+proc write_database_header/char {f} {
+    puts $f "$rows\n"
+}
+proc format_database_entry/char {bm strq} {
+    global database rows
+    set o "[lindex $bm 0]\n$strq\n"
+    foreach x [lrange $bm 1 end] { append o "$x\n" }
+    return $o
+}
+
 proc dbkey {ctx l r} {
     global wordmap
     set bm $ctx
 proc dbkey {ctx l r} {
     global wordmap
     set bm $ctx
@@ -514,7 +565,7 @@ proc RETURN_RESULT {how what} {
     done/$mainkind
 }
 
     done/$mainkind
 }
 
-#---------- main progrm ----------
+#---------- main program ----------
 
 proc main/default {} {
     puts stderr "Do not run this program directly."
 
 proc main/default {} {
     puts stderr "Do not run this program directly."
@@ -524,18 +575,18 @@ proc done/default {} {
 }
 
 proc required {} {
 }
 
 proc required {} {
-    global glyphsdone unk_l unk_r unk_contexts
+    global reqkind
 
     fileevent stdin readable {}
     fconfigure stdin -blocking yes
     
 
     fileevent stdin readable {}
     fconfigure stdin -blocking yes
     
-    if {[gets stdin l]<0} {
+    if {[gets stdin reqkind]<0} {
        if {[eof stdin]} { fconfigure stdin -blocking yes; exit 0 }
        return
     }
     init_widgets
 
        if {[eof stdin]} { fconfigure stdin -blocking yes; exit 0 }
        return
     }
     init_widgets
 
-    required/$l
+    required/$reqkind
 }
 
 
 }
 
 
@@ -572,11 +623,19 @@ proc pixmap_maybe_ok {} {
     }
 }
 proc pixmap_ok {} {
     }
 }
 proc pixmap_ok {} {
+    global database ppm pixmap_selcol pixmap_selrow mainkind alloptions
     foreach_pixmap_col col {
        .d.pe.grid.l$col configure -state disabled
     }
     .d.pe.ok configure -state disabled
     helptext {{{ Processing }}}
     foreach_pixmap_col col {
        .d.pe.grid.l$col configure -state disabled
     }
     .d.pe.ok configure -state disabled
     helptext {{{ Processing }}}
+    manyset [lrange $alloptions [expr {$pixmap_selcol*3}] end] \
+       colname coldesc rows
+    manyset [lrange $rows [expr {$pixmap_selrow*2}] end] \
+       rowname rowdesc
+    set database($ppm) "$colname - $coldesc"
+    write_database
+    done/$mainkind
 }
 
 proc required/pixmap {} {
 }
 
 proc required/pixmap {} {
@@ -594,15 +653,15 @@ proc required/pixmap {} {
 
     set alloptions [exec ./yppsc-resolver-pixoptions $unk_what]
 
 
     set alloptions [exec ./yppsc-resolver-pixoptions $unk_what]
 
-    #read_database_pixmaps
+    read_database ./pixmaps.txt
 
     set mulcols [image width image/main]
     set mulrows [image height image/main]
     resize_widgets_core
     place forget .d.mi.csr_0
     place forget .d.mi.csr_1
 
     set mulcols [image width image/main]
     set mulrows [image height image/main]
     resize_widgets_core
     place forget .d.mi.csr_0
     place forget .d.mi.csr_1
-    .d.ctx configure -height 0
-    pack forget .d.csr
+
+    pack forget .d.csr .d.got
     pack .d.pe -side top -before .d.mi -pady 10
 
     eval destroy [winfo children .d.pe.grid]
     pack .d.pe -side top -before .d.mi -pady 10
 
     eval destroy [winfo children .d.pe.grid]
@@ -627,7 +686,7 @@ proc required/pixmap {} {
 }
 
 proc required/char {} {
 }
 
 proc required/char {} {
-    global mulrows
+    global mulrows glyphsdone unk_l unk_r unk_contexts rows
     
     must_gets stdin l
 
     
     must_gets stdin l
 
@@ -649,8 +708,9 @@ proc required/char {} {
     .d.ctx configure -height $maxh
     pack forget .d.pe
     pack .d.csr -side top -before .d.mi
     .d.ctx configure -height $maxh
     pack forget .d.pe
     pack .d.csr -side top -before .d.mi
+    pack .d.got .d.ctx -side top -after .d.mi
 
 
-    read_database
+    read_database ./charset-$rows.txt
     draw_glyphsdone
     startup_cursor
 }
     draw_glyphsdone
     startup_cursor
 }