Tk Source Code

View Ticket
Login
2025-11-04
09:30 Closed ticket [4e7a78ea]: tk print text: several issues printing i18n text plus 6 other changes artifact: e4ba315d user: jan.nijtmans
09:20 Ticket [4e7a78ea]: 3 changes artifact: 877f07a2 user: jan.nijtmans
2025-06-02
20:06 Ticket [4e7a78ea]: 3 changes artifact: 3d5dcf52 user: fvogel
2025-05-07
20:14 Ticket [4e7a78ea]: 5 changes artifact: 62f745cf user: fvogel
2025-05-06
21:51 Add attachment utf8demo.txt to ticket [4e7a78ea] artifact: 18f9dcbc user: emiliano
21:51 Add attachment print_text.tcl to ticket [4e7a78ea] artifact: 57f0a030 user: emiliano
21:51 New ticket [4e7a78ea] tk print text: several issues printing i18n text. artifact: a78e0fb4 user: emiliano

Ticket UUID: 4e7a78ea323caf578630fe5e4bdfaebaa51a556
Title: [tk print] text: several issues printing i18n text
Type: Bug Version: trunk
Submitter: emiliano Created on: 2025-05-06 21:51:04
Subsystem: -- New Commands Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2025-11-04 09:30:34
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2025-11-04 09:30:34
Description:

[tk print $text] on windows has limited support (if any) for i18n text.

The code builds an array of character widths but only for the range 0-255 (I presume of the active code page) and then fails when trying to lookup for characters not in this range. Running the attached demo script (paired with the plain text data file "utf8demo.txt") produces

can't read "charwidths(‾)": no such element in array can't read "charwidths(‾)": no such element in array while executing "incr totwidth $charwidths([string index $string $i])" (procedure "_print_page_nextline" line 16) invoked from within "_print_page_nextline $linestring printcharwid printargs $curhgt $font" (procedure "::tk::print::_print_data" line 38) invoked from within "::tk::print::_print_data {UTF-8 encoded sample plain-text file ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾..." ("after" script)

Moreover, the built lookup array resides in the global namespace and not in the ::tk::print namespace, being subject to a potential name clash.

Other issue is that the default font used for text widgets is a proportional font, making it unsuitable for things like printing code. This is also an inconsistency with *nix, and I pressume also MacOS, where the cups printing system uses a monospaced font for Tk text printing (and plaintext files).

The branch tk-print-fixes has a fix for these issues. In the case of the character width lookup array is a workaround: use [array default set] to provide a fallback width.

There's no output attached as they result in a big file and is easy to reproduce.

The attached data file "utf8demo.txt" comes from the cups source code here

User Comments: jan.nijtmans added on 2025-11-04 09:30:34:

Merged to core-9-0-branch (and trunk) now


fvogel added on 2025-05-07 20:14:56:
Thanks, that's definitely a valuable improvement!

I didn't review the code patch, but I have tried your script (it works for me).

Attachments: