summaryrefslogtreecommitdiffstats
path: root/library/print.tcl
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-05-22 13:06:19 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-05-22 13:06:19 (GMT)
commiteb776d13e306b28c75b2fa7ae71b75ec690e79eb (patch)
treefae677155f645a5ccbb3b4e0e069c60c9a10a7b4 /library/print.tcl
parent31dee897d0a63e144a8d8076521a899d0e1589e7 (diff)
parent57b99249e67918f2283225a4e3beadb841fdb881 (diff)
downloadtk-eb776d13e306b28c75b2fa7ae71b75ec690e79eb.zip
tk-eb776d13e306b28c75b2fa7ae71b75ec690e79eb.tar.gz
tk-eb776d13e306b28c75b2fa7ae71b75ec690e79eb.tar.bz2
Merge 8.7. end-of-line spacing
Diffstat (limited to 'library/print.tcl')
-rw-r--r--library/print.tcl236
1 files changed, 118 insertions, 118 deletions
diff --git a/library/print.tcl b/library/print.tcl
index 7d9cc39..1a049e2 100644
--- a/library/print.tcl
+++ b/library/print.tcl
@@ -28,12 +28,12 @@ namespace eval ::tk::print {
array set printargs {}
# Multiple utility procedures for printing text based on the
- # C printer primitives.
+ # C printer primitives.
- # _set_dc:
+ # _set_dc:
# Select printer and set device context and other parameters
- # for print job.
- #
+ # for print job.
+ #
proc _set_dc {} {
variable printargs
@@ -45,14 +45,14 @@ namespace eval ::tk::print {
return
}
- #Next, set values. Some are taken from the printer,
+ #Next, set values. Some are taken from the printer,
#some are sane defaults.
-
+
set printargs(hDC) [list $::tk::print::printer_name]
set printargs(pw) $::tk::print::paper_width
set printargs(pl) $::tk::print::paper_height
set printargs(lm) 1000
- set printargs(tm) 1000
+ set printargs(tm) 1000
set printargs(rm) 1000
set printargs(bm) 1000
set printargs(resx) $::tk::print::dpi_x
@@ -65,18 +65,18 @@ namespace eval ::tk::print {
# _print_data
# This function prints multiple-page files, using a line-oriented
# function, taking advantage of knowing the character widths.
- # Arguments:
+ # Arguments:
# data - Text data for printing
# breaklines - If non-zero, keep newlines in the string as
# newlines in the output.
# font - Font for printing
proc _print_data { data {breaklines 1 } {font {}} } {
-
+
variable printargs
_set_dc
-
+
if { [string length $font] == 0 } {
eval ::tk::print::_gdi characters $printargs(hDC) -array printcharwid
} else {
@@ -88,21 +88,21 @@ namespace eval ::tk::print {
set curlen 0
set curhgt [ expr $printargs(tm) * $printargs(resy) / 1000 ]
- ::tk::print::_opendoc
+ ::tk::print::_opendoc
::tk::print::_openpage
-
- while { $curlen < $totallen } {
+
+ while { $curlen < $totallen } {
set linestring [ string range $data $curlen end ]
if { $breaklines } {
set endind [ string first "\n" $linestring ]
if { $endind != -1 } {
- set linestring [ string range $linestring 0 $endind ]
+ set linestring [ string range $linestring 0 $endind ]
# handle blank lines....
- if { $linestring == "" } {
- set linestring " "
+ if { $linestring == "" } {
+ set linestring " "
}
- }
- }
+ }
+ }
set result [_print_page_nextline $linestring \
printcharwid printargs $curhgt $font]
@@ -119,10 +119,10 @@ namespace eval ::tk::print {
::tk::print::_closedoc
}
-
+
# _print_file
# This function prints multiple-page files
- # It will either break lines or just let them run over the
+ # It will either break lines or just let them run over the
# margins (and thus truncate).
# The font argument is JUST the font name, not any additional
# arguments.
@@ -130,12 +130,12 @@ namespace eval ::tk::print {
# filename - File to open for printing
# breaklines - 1 to break lines as done on input, 0 to ignore newlines
# font - Optional arguments to supply to the text command
-
+
proc _print_file { filename {breaklines 1 } { font {}} } {
-
+
variable printargs
array get printargs
-
+
set fn [open $filename r]
set data [ read $fn ]
close $fn
@@ -154,11 +154,11 @@ namespace eval ::tk::print {
# font - if non-empty specifies a font to draw the line in
proc _print_page_nextline { string carray parray y font } {
-
-
+
+
upvar #0 $carray charwidths
upvar #0 $parray printargs
-
+
variable printargs
set endindex 0
@@ -171,7 +171,7 @@ namespace eval ::tk::print {
incr totwidth $charwidths([string index $string $i])
# set width($i) $totwidth
}
-
+
set endindex $i
set startindex $endindex
@@ -179,7 +179,7 @@ namespace eval ::tk::print {
# In this case, the whole data string is not used up, and we wish
# to break on a word. Since we have all the partial widths calculated,
# this should be easy.
-
+
set endindex [ expr [string wordstart $string $endindex] - 1 ]
set startindex [ expr $endindex + 1 ]
@@ -204,10 +204,10 @@ namespace eval ::tk::print {
}
-
- # These procedures read in the canvas widget, and write all of
- # its contents out to the Windows printer.
-
+
+ # These procedures read in the canvas widget, and write all of
+ # its contents out to the Windows printer.
+
variable option
variable vtgPrint
@@ -215,7 +215,7 @@ namespace eval ::tk::print {
variable option
variable vtgPrint
variable printargs
-
+
array get printargs
set option(use_copybits) 1
@@ -224,27 +224,27 @@ namespace eval ::tk::print {
proc _is_win {} {
variable printargs
-
+
array get printargs
-
+
return [ info exist tk_patchLevel ]
}
-
+
# _print_widget
# Main procedure for printing a widget. Currently supports
# canvas widgets. Handles opening and closing of printer.
# Arguments:
- # wid - The widget to be printed.
- # printer - Flag whether to use the default printer.
+ # wid - The widget to be printed.
+ # printer - Flag whether to use the default printer.
# name - App name to pass to printer.
proc _print_widget { wid {printer default} {name "Tk Print Output"} } {
-
+
variable printargs
-
- _set_dc
-
+
+ _set_dc
+
array get printargs
::tk::print::_opendoc
@@ -254,7 +254,7 @@ namespace eval ::tk::print {
# For now, scale so the dimensions of the window are sized to the
# width of the page. Scale evenly.
- # For normal windows, this may be fine--but for a canvas, one wants the
+ # For normal windows, this may be fine--but for a canvas, one wants the
# canvas dimensions, and not the WINDOW dimensions.
if { [winfo class $wid] == "Canvas" } {
set sc [ lindex [ $wid configure -scrollregion ] 4 ]
@@ -283,7 +283,7 @@ namespace eval ::tk::print {
$printargs(resy) / 1000.0 ]
set factor_x [ expr $window_x / $printer_x ]
set factor_y [ expr $window_y / $printer_y ]
-
+
if { $factor_x < $factor_y } {
set lo $window_y
set ph $printer_y
@@ -293,7 +293,7 @@ namespace eval ::tk::print {
}
::tk::print::_gdi map $printargs(hDC) -logical $lo -physical $ph -offset $printargs(resolution)
-
+
# Handling of canvas widgets.
switch [winfo class $wid] {
Canvas {
@@ -310,17 +310,17 @@ namespace eval ::tk::print {
}
-
+
# _print_canvas
# Main procedure for writing canvas widget items to printer.
- # Arguments:
+ # Arguments:
# hdc - The printer handle.
# cw - The canvas widget.
-
+
proc _print_canvas {hdc cw} {
variable vtgPrint
-
+
variable printargs
array get printargs
@@ -338,29 +338,29 @@ namespace eval ::tk::print {
}
}
}
-
- # These procedures support the various canvas item types,
- # reading the information about the item on the real canvas
- # and then writing a similar item to the printer.
-
+
+ # These procedures support the various canvas item types,
+ # reading the information about the item on the real canvas
+ # and then writing a similar item to the printer.
+
# _print_canvas.line
# Description:
# Prints a line item.
- # Arguments:
+ # Arguments:
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.line {hdc cw id} {
variable vtgPrint
-
+
variable printargs
array get printargs
set color [_print_canvas.TransColor [$cw itemcget $id -fill]]
if {[string match $vtgPrint(printer.bg) $color]} {return}
-
+
set coords [$cw coords $id]
set wdth [$cw itemcget $id -width]
set arrow [$cw itemcget $id -arrow]
@@ -368,25 +368,25 @@ namespace eval ::tk::print {
set dash [$cw itemcget $id -dash]
set smooth [$cw itemcget $id -smooth ]
set splinesteps [ $cw itemcget $id -splinesteps ]
-
+
set cmmd "::tk::print::_gdi line $printargs(hDC) $coords -fill $color -arrow $arrow -arrowshape [list $arwshp]"
-
+
if { $wdth > 1 } {
set cmmd "$cmmd -width $wdth"
}
-
+
if { $dash != "" } {
set cmmd "$cmmd -dash [list $dash]"
}
-
+
if { $smooth != "" } {
set cmmd "$cmmd -smooth $smooth"
}
-
+
if { $splinesteps != "" } {
set cmmd "$cmmd -splinesteps $splinesteps"
}
-
+
set result [eval $cmmd]
if { $result != "" } {
puts $result
@@ -394,18 +394,18 @@ namespace eval ::tk::print {
}
-
+
# _print_canvas.arc
# Prints a arc item.
# Args:
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.arc {hdc cw id} {
variable vtgPrint
-
+
variable printargs
array get printargs
@@ -419,7 +419,7 @@ namespace eval ::tk::print {
set start [ $cw itemcget $id -start ]
set extent [ $cw itemcget $id -extent ]
set fill [ $cw itemcget $id -fill ]
-
+
set cmmd "::tk::print::_gdi arc $printargs(hDC) $coords -outline $color -style $style -start $start -extent $extent"
if { $wdth > 1 } {
set cmmd "$cmmd -width $wdth"
@@ -427,22 +427,22 @@ namespace eval ::tk::print {
if { $fill != "" } {
set cmmd "$cmmd -fill $fill"
}
-
+
eval $cmmd
}
-
-
+
+
# _print_canvas.polygon
# Prints a polygon item.
# Arguments:
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.polygon {hdc cw id} {
variable vtgPrint
-
+
variable printargs
array get printargs
@@ -458,33 +458,33 @@ namespace eval ::tk::print {
set wdth [$cw itemcget $id -width]
set smooth [$cw itemcget $id -smooth ]
set splinesteps [ $cw itemcget $id -splinesteps ]
-
+
set cmmd "::tk::print::_gdi polygon $printargs(hDC) $coords -width $wdth \
-fill $fcolor -outline $ocolor"
if { $smooth != "" } {
set cmmd "$cmmd -smooth $smooth"
}
-
+
if { $splinesteps != "" } {
set cmmd "$cmmd -splinesteps $splinesteps"
}
-
+
eval $cmmd
}
-
+
# _print_canvas.oval
# Prints an oval item.
# Arguments:
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.oval { hdc cw id } {
variable vtgPrint
-
+
variable printargs
array get printargs
@@ -501,18 +501,18 @@ namespace eval ::tk::print {
eval $cmmd
}
-
+
# _print_canvas.rectangle
# Prints a rectangle item.
# Arguments:
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.rectangle {hdc cw id} {
variable vtgPrint
-
+
variable printargs
array get printargs
@@ -528,21 +528,21 @@ namespace eval ::tk::print {
eval $cmmd
}
-
+
# _print_canvas.text
# Prints a text item.
# Arguments:
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.text {hdc cw id} {
variable vtgPrint
-
+
variable printargs
array get printargs
-
+
set color [_print_canvas.TransColor [$cw itemcget $id -fill]]
# if {[string match white [string tolower $color]]} {return}
# set color black
@@ -550,21 +550,21 @@ namespace eval ::tk::print {
if {![string length $txt]} {return}
set coords [$cw coords $id]
set anchr [$cw itemcget $id -anchor]
-
+
set bbox [$cw bbox $id]
set wdth [expr [lindex $bbox 2] - [lindex $bbox 0]]
set just [$cw itemcget $id -justify]
-
+
# Get the canvas font info.
set font [ $cw itemcget $id -font ]
-
+
# Find the real font info.
set font [font actual $font]
-
+
# Create a compatible font, suitable for printer name extraction.
set font [ eval font create $font ]
-
+
# Just get the name and family, or some of the ::tk::print::_gdi
# commands will fail.
set font [list [font configure $font -family] -[font configure $font -size] ]
@@ -573,7 +573,7 @@ namespace eval ::tk::print {
-anchor $anchr -font [ list $font ] \
-width $wdth -justify $just"
eval $cmmd
- }
+ }
# _print_canvas.image
@@ -582,33 +582,33 @@ namespace eval ::tk::print {
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.image {hdc cw id} {
variable vtgPrint
variable option
-
+
variable printargs
array get printargs
# First, we have to get the image name.
set imagename [ $cw itemcget $id -image]
-
+
# Now we get the size.
set wid [ image width $imagename]
set hgt [ image height $imagename ]
-
+
# Next, we get the location and anchor
set anchor [ $cw itemcget $id -anchor ]
set coords [ $cw coords $id ]
-
+
# Since the GDI commands don't yet support images and bitmaps,
# and since this represents a rendered bitmap, we CAN use
# copybits IF we create a new temporary toplevel to hold the beast.
# If this is too ugly, change the option!
-
+
if { [ info exist option(use_copybits) ] } {
set firstcase $option(use_copybits)
} else {
@@ -619,7 +619,7 @@ namespace eval ::tk::print {
set tl [toplevel .tmptop[expr int( rand() * 65535 ) ] -height $hgt -width $wid -background $vtgPrint(printer.bg) ]
canvas $tl.canvas -width $wid -height $hgt
$tl.canvas create image 0 0 -image $imagename -anchor nw
- pack $tl.canvas -side left -expand false -fill none
+ pack $tl.canvas -side left -expand false -fill none
tkwait visibility $tl.canvas
update
#set srccoords [list "0 0 [ expr $wid - 1] [expr $hgt - 1 ]" ]
@@ -628,45 +628,45 @@ namespace eval ::tk::print {
set dstcoords [ list "[lindex $coords 0] [lindex $coords 1] $wid $hgt" ]
set cmmd "::tk::print::_gdi copybits $printargs(hDC) -window $tl -client -source $srccoords -destination $dstcoords "
eval $cmmd
- destroy $tl
+ destroy $tl
} else {
set cmmd "::tk::print::_gdi image $printargs(hDC) $coords -anchor $anchor -image $imagename "
eval $cmmd
}
}
-
+
# _print_canvas.bitmap
# Prints a bitmap item.
# Arguments:
# hdc - The printer handle.
# cw - The canvas widget.
# id - The id of the canvas item.
-
+
proc _print_canvas.bitmap {hdc cw id} {
variable option
variable vtgPrint
-
+
variable printargs
array get printargs
# First, we have to get the bitmap name.
set imagename [ $cw itemcget $id -image]
-
+
# Now we get the size.
set wid [ image width $imagename]
set hgt [ image height $imagename ]
-
+
#Next, we get the location and anchor.
set anchor [ $cw itemcget $id -anchor ]
set coords [ $cw coords $id ]
-
+
# Since the GDI commands don't yet support images and bitmaps,
# and since this represents a rendered bitmap, we CAN use
# copybits IF we create a new temporary toplevel to hold the beast.
# If this is too ugly, change the option!
-
+
if { [ info exist option(use_copybits) ] } {
set firstcase $option(use_copybits)
} else {
@@ -676,39 +676,39 @@ namespace eval ::tk::print {
set tl [toplevel .tmptop[expr int( rand() * 65535 ) ] -height $hgt -width $wid -background $vtgPrint(canvas.bg) ]
canvas $tl.canvas -width $wid -height $hgt
$tl.canvas create image 0 0 -image $imagename -anchor nw
- pack $tl.canvas -side left -expand false -fill none
+ pack $tl.canvas -side left -expand false -fill none
tkwait visibility $tl.canvas
update
set srccoords [list "0 0 [ expr $wid - 1] [expr $hgt - 1 ]" ]
set dstcoords [ list "[lindex $coords 0] [lindex $coords 1] [expr $wid - 1] [expr $hgt - 1]" ]
set cmmd "::tk::print::_gdi copybits $printargs(hDC) -window $tl -client -source $srccoords -destination $dstcoords "
eval $cmmd
- destroy $tl
+ destroy $tl
} else {
set cmmd "::tk::print::_gdi bitmap $printargs(hDC) $coords -anchor $anchor -bitmap $imagename"
eval $cmmd
}
}
-
- # These procedures transform attribute setting from the real
- # canvas to the appropriate setting for printing to paper.
-
+
+ # These procedures transform attribute setting from the real
+ # canvas to the appropriate setting for printing to paper.
+
# _print_canvas.TransColor
# Does the actual transformation of colors from the
# canvas widget to paper.
# Arguments:
# color - The color value to be transformed.
-
+
proc _print_canvas.TransColor {color} {
variable vtgPrint
-
+
variable printargs
array get printargs
switch [string toupper $color] {
- $vtgPrint(canvas.bg) {return $vtgPrint(printer.bg)}
+ $vtgPrint(canvas.bg) {return $vtgPrint(printer.bg)}
}
return $color
}
@@ -763,6 +763,6 @@ proc ::tk::print::text {w} {
namespace ensemble configure tk -map \
[dict merge [namespace ensemble configure tk -map] \
{print ::tk::print}]
-
-
+
+