Tk Source Code

View Ticket
Login
Ticket UUID: d08538fd78a8f39bc0a7a5c860fd4b5f771617da
Title: Regression in 9.1: wrapped text counts spaces at end of line, splits words, breaks after leading spaces (X11 with bidi, Windows)
Type: Bug Version: 9.1.0
Submitter: serhiy.storchaka Created on: 2026-10-01 09:45:59
Subsystem: 44. Generic Fonts Assigned To:
Priority: Severity:
Status: Closed Last Modified: 2026-10-06 11:45:56
Resolution: Fixed Closed By:
    Closed on:
Description:

This is a regression in 9.1. The text shaping font backends (X11 built with bidi, which is the default, and Windows) implement Tk_MeasureChars() with TK_WHOLE_WORDS differently from the other backends and from 9.0, so wrapped text in labels, canvas text items, etc. is laid out differently:

  • The spaces at the end of a line are counted in its width.
  • A word which does not fit after a tab is split instead of moved to the next line.
  • Leading spaces are treated as a word boundary, so text starting with spaces breaks after them (bug [1006286] again).
pack [label .l -font TkFixedFont -padx 0 -pady 0 -bd 0 -highlightthickness 0 \
	-text "000            000" -wraplength [font measure TkFixedFont 00000]]
update
puts [expr {[winfo reqwidth .l] / [font measure TkFixedFont 0]}]

This prints 3 with 9.0 and 5 with 9.1.

The failing tests were restricted to macOS (font-24.5, 24.11, 24.12, 30.6, 31.6, canvText-19.1) or excluded on other platforms (canvText-10.1, textDisp-9.7 and textDisp-21.1 on Windows, unixfont-5.6, 5.7 and 5.8 with Xft). 9.0 runs all of them on all platforms.

Proposed fix in branch shaping-whole-words: use the same word-boundary rules as the other backends, and restore the 9.0 constraints of these tests. Tested on X11 (with bidi, without bidi, without Xft) and Windows.

User Comments: serhiy.storchaka added on 2026-10-06 11:44:41:

Merged into main [123cc66f98]. Tested on X11 with bidi and on Windows. Tk 9.0 is not affected: it has neither text shaping on X11 nor Uniscribe on Windows.