Tk Source Code

View Ticket
Login
Ticket UUID: d2eac285d9c33ffcc8a9d59cae6e405632acdaf3
Title: tk print command fails with canvas widget
Type: Bug Version: 9.0.1
Submitter: anonymous Created on: 2025-04-23 08:18:39
Subsystem: 99. Other Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2025-04-26 11:46:11
Resolution: Fixed Closed By: fvogel
    Closed on: 2025-04-26 11:46:11
Description:
platform : MS Windows 7 and 10 (64 bits)
distribution : Magicsplat Tcl/Tk 2.0.3 (Tcl 9.0.1)

1) Try to print a text displays in a canvas widget :

package require Tk
canvas .c -width 220 -height 220
.c create text 5 5 -text "try to print a canvas widget" -anchor nw
pack .c
pack [button .b -text print -command {tk print .c}]

The click on the button "print" posts a dialog as expected but the click on the button "print" of this dialog causes a crach with the message :

expected integer but got "5.0"
    while executing
"_gdi text $hdc {*}$coords  -fill $color -text $txt -font $font  -anchor $anchr -width $wdth -justify $just"
    (procedure "_print_canvas.text" line 28)
    invoked from within
"_print_canvas.[$cw type $id] $printargs(hDC) $cw $id"
    (procedure "_print_canvas" line 13)
    invoked from within
"_print_canvas $printargs(hDC) $wid"
    (procedure "::tk::print::_print_widget" line 59)
    invoked from within
"::tk::print::_print_widget .c 0 {Tk Print Output}"
    invoked from within
"tk print .c"


2) Try to print an image displays in a canvas widget :

package require Tk
image create photo logo -data {iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAgAAAAIACH+pydAAAHMUlEQVRYw62XTYwlVRmGn/NTP/enbzd0MxOamWboGf4kIhA1TgxjXDAIIXFhYoxg4kKcrRtXLtxrZM9WdENcGRYuXCCRaExkQQIhBgfSzgwydE9333vrVtX5dXHq3ts0AxmCNzldleo69b7n+97v/c4RfL6fBEpgBJwAht3zKXAdGAMNEG71g+IW3+sD2w8+fufFO+9dPZ/39ZnTD66d8z7q4CPVf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udogxrwzJeNd2HWt3yE53Gv8nw6nx3/z43m/G3n33HRgMz7n8fx/BZOJfNhih6cAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTItMDgtMjRUMDk6MjY6NDcrMDI6MDBkhmwbAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDEyLTA4LTI0VDA5OjI2OjQ3KzAyOjAwFdvUpwAAAABJRU5ErkJggg==}
canvas .c -width 220 -height 220
.c create image 5 5 -image logo -anchor nw
pack .c
pack [button .b -text print -command {tk print .c}]

On Win 7 : there is no crach but the processed sheet by the printer has nothing printed on it
On win 10 : the same leads to a crach with the message :

can't read "printargs(pw)": no such element in array
    while executing
"expr {
		( $printargs(pw) - $printargs(lm) - $printargs(rm) ) *
		$printargs(resx)  / 1000.0
	    }"
    (procedure "::tk::print::_print_widget" line 35)
    invoked from within
"::tk::print::_print_widget .c 0 {Tk Print Output}"
    invoked from within
"tk print .c"
    invoked from within
".b invoke"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 [list $w invoke]"
    (procedure "tk::ButtonUp" line 24)
    invoked from within
"tk::ButtonUp .b"
    (command bound to event)

Thanks,
Jean-Baptiste
User Comments: fvogel added on 2025-04-26 11:46:11:

Thanks, now committed in [408f20ff4c].


emiliano added on 2025-04-25 18:54:30:
There's one problem left with canvas:

(bin) 1 % pack [canvas .c]
(bin) 2 % .c create line 20 20 50 50 50 100 200 200
1
(bin) 3 % tk print .c
cannot use non-numeric string "10c" as left operand of "/"
(bin) 4 % set errorInfo
cannot use non-numeric string "10c" as left operand of "/"
    while executing
"expr {$window_x / $printer_x}"
    (procedure "::tk::print::_print_widget" line 43)
    invoked from within
"::tk::print::_print_widget .c 0 {Tk Print Output}"
    invoked from within
"tk print .c"

Attached patch fixes the issue

jan.nijtmans added on 2025-04-24 13:07:10:

Issue 1 fixed [b2411a5ec4326096|here]

> I suggest merging of [fada46f6] to fix issue 1 and follow up to [bb5c3d0ecc] for issue 2

Agreed. So, closing this one.


fvogel added on 2025-04-23 21:44:53:

Note to the OP: next time please open two tickets for two issues. Thanks!

The first problem is repeatable. I confirm Jan's fix [fada46f6] works for me.

The second problem seems to happen once only. At least I could only get it once only. After the first time, when the problem does no longer happen the correct functioning survives kill and restart of tclsh, and even survives the switch of / switch on of the printer. Interesting. This second problem is the same as [bb5c3d0ecc].

I suggest merging of [fada46f6] to fix issue 1 and follow up to [bb5c3d0ecc] for issue 2.


anonymous added on 2025-04-23 10:13:39:
(not sure to use the correct way to append a new post here)
Thanks for looking into this
Unfornulately, my use of Tcl/Tk is only at script level (no C skill here ...)
I've no C compiler, so I can't test your patch, sorry
Jean-Baptiste

jan.nijtmans added on 2025-04-23 09:46:36:

Does [fada46f6992135b6|this] help? (at least for the first problem)


Attachments: