Tk Source Code

View Ticket
Login
Ticket UUID: 7579c335f14c9ed4272dbc6bf672c528677b6780
Title: Text widget: wrong bbox widths for non-ASCII characters with bidi text rendering
Type: Bug Version: 9.1b1
Submitter: serhiy.storchaka Created on: 2026-09-24 11:24:10
Subsystem: 18. [text] Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-09-26 13:12:36
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2026-09-25 14:10:22
Description:

With the bidi text rendering in 9.1 (default X11 build), $text bbox returns wrong widths for characters encoded with more than one UTF-8 byte:

pack [text .t -font {Helvetica 14}]
.t insert end "Доброго ранку, світе"
update
# width of each character: bbox vs. font measure

11 of the 20 characters differ; most get the width of the previous character (Д:1/13 о:13/11 г:11/7 …). 9.0 and a 9.1 build with --disable-bidi are correct.

CharBboxProc (generic/tkTextDisp.c) measures the character at byteIndex as the byte range [byteIndex, byteIndex+1], which ends in the middle of a multi-byte character. The Xft font code tolerates this since [437a4bc8fb] ([1185640fff]), but the bidi measuring code does not.

User Comments: serhiy.storchaka added on 2026-09-26 13:12:36:

textDisp-25.2 fails on macOS CI (both Aqua and X11 with --disable-bidi) with result 1.14: the bbox width of the space after the comma differs from font measure of the space.

Proposed fix in branch textdisp-bbox-test-macos: the test checks that the bbox of each character ends where the next one begins, without font measure. It still fails without the fix (for 10 of the characters).


jan.nijtmans added on 2026-09-25 14:10:22:

Fixed [5299492cd8c22dc4|here]

Many thanks!


serhiy.storchaka added on 2026-09-24 11:28:54:

Fix on text-bbox-multibyte: CharBboxProc now measures up to the start of the next character. Test textDisp-25.2.