% strimj::text Hallo -font Schwabacher
@@@@@ @@ @@
@@@@@@ @@@ @@@
@@@@@ @@@@ @@@@
@@@@@@ @@@@@ @@@@@
@@@@@@ @@@ @@@
@@@@@@ @@@ @@@
@@@@@@ @@@ @@@
@@@@@ @@@ @@@ @@@ @@@@
@@@@@@ @@@@@@ @@@ @@@ @@@@@@
@@@@@ @ @@@@@@@@@ @@@ @@@ @@@@@@@@
@@@@@ @@@@ @@ @@@@@@ @@@ @@@ @@ @@@@@
@@@@ @@@@@@@ @@ @@@ @@@ @@@ @@ @@@@
@@@@@ @@@@@@@@@@ @@@ @@@ @@@ @@@ @@@ @@@@
@@@@ @@@ @@@@@@ @@ @@@ @@@ @@@ @@@ @@@@
@@@@@@@@ @@@@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@@@@ @@@@ @@@ @@@ @@@@ @@@@ @@@ @@@
@@@@ @@@@@ @@@@ @@@@ @@@@ @@@@ @@@ @@@
@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@
@@@ @@@@ @@@@@@ @@@@ @@@@ @@@@ @@
@@@ @@@@@@@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@ @
@@@@ @@@@@@ @@@@ @@@@@ @@@@@ @@@@@@@
@@@ @@@@ @@@ @@ @@ @@@@
@@ @@@@ @ @ @@
@@@@ @@@
@@@@@@ @@@
@@@@@@@@@@@@
@@@@@@@@@ namespace eval strimj {
proc fromBMP2 bmp {
#-- make a strimj from a binary BMP image file
set fp [open $bmp]
fconfigure $fp -translation binary
set data [read $fp [file size $bmp]]
close $fp
set offset 62
binary scan $data @18ii width height
set nbytes [expr {(($width+31)/32)*4}] ;# 4-byte aligned
set nbits [expr {(($width+7)/8)*8}] ;# byte-aligned
set res ""
for {set y [expr {$height-1}]} {$y>=0} {incr y -1} {
binary scan $data @[expr {$y*$nbytes+$offset}]B$nbits line
append res [string range $line 0 [expr {$width-1}]]\n
}
string map {1 . 0 @} $res
}
proc segment si {
#-- segment a binary text image into a list of character images
set res {}
foreach linesi [lseg $si] {
foreach charsi [lseg [rotate $linesi 270]] {
lappend res [vcrop [rot90 $charsi]]
}
}
set res
}
proc vcrop si {
#-- vertical crop, remove empty lines at top & bottom
set lines [lines $si]
set core [regexp -indices -inline @.+@ [pp2 $lines]]
foreach {from to} [lindex $core 0] break
join [lrange $lines $from $to] \n
}
proc lseg si {
#-- segment a binary text image into a list of line images
set lines [lines $si]
set ranges [regexp -all -indices -inline @+ [pp2 $lines]]
set res {}
foreach pair $ranges {
foreach {from to} $pair break
set height [expr {$to-$from+1}]
if {$height>2 && $height<100} {
lappend res [join [lrange $lines $from $to] \n]
}
}
set res
}
proc pp2 lines {
#-- vertical binary projection profile
set res ""
foreach line $lines {
append res [expr {[string first @ $line]>=0? "@":"."}]
}
set res
}
}
proc testseg {{bmpfile schwabacher2.bmp}} {
join [strimj::segment [strimj::fromBMP2 $bmpfile]] \n\n
}See Arts and crafts of Tcl-Tk programming

