Usage : (prefix commands with Print:: if you're working from a different namespace) OpenPrinter PrintForm (1 or multiple times) ClosePrintersx and sy are shifts to get the form on the right place on paper, this values are obtained by calibration. These values may not be the same for different printers. fwdt and fhgt are form width and height, the canvas must have the same size.
#
#
proc Print::OpenPrinter {} {
variable WIN
variable FLD
variable CUR
# Preprinted form is shown in the canvas as an image,
# This image must be removed temporarily during the printing
$WIN(FRM) itemconfigure img -state hidden
update
set gspath {C:\\gs\\gs8.51\\bin\\gswin32c.exe}
set opt1 "-q"
if {$FLD(Printer) != "Select from Printer Dialog"} {
set opt2 "-sDEVICE=mswinpr2 -sOutputFile=\"%printer%$FLD(Printer)\""
}\
else {
set opt2 "-sDEVICE=mswinpr2"
}
set opt3 "-dNOPAUSE -dBATCH"
set CUR(gs) [open "|\"$gspath\" $opt1 $opt2 $opt3 -" w]
}
#
#
proc Print::PrintForm {} {
variable WIN
variable FLD
variable CUR
variable Msg ""
# Form definition is stored in a BLT tree
# Values are obtained by procedure GetValues var1 var2 ...
GetValues sx sy fwdt fhgt unit rot
if {$rot} {
set sftx [expr {$sx + $fwdt / 2}]
set sfty [expr {$sy + $fhgt / 2}]
}\
else {
set sftx [expr {-1 * $sy + $fwdt / 2}]
set sfty [expr {$sx + $fhgt / 2}]
}
$WIN(FRM) yview moveto 0
$WIN(FRM) xview moveto 0
$WIN(FRM) postscript -channel $CUR(gs) -pagey $sftx$unit -pagex $sfty$unit -rotate $rot\
-width $fwdt$unit -height $fhgt$unit -pageheight $fhgt$unit -pagewidth $fwdt$unit -x 0 -y 0
}
#
#
proc Print::ClosePrinter {} {
variable WIN
variable CUR
variable Msg "" ;# variable attached to status bar
catch {close $CUR(gs)} Msg
array unset CUR gs
$WIN(FRM) itemconfigure img -state normal
update
}Category Printing - Category Windows
