Tk Source Code

Artifact [d2366d0f]
Login

Artifact d2366d0f3d8b27238a70a59e4196cfa8640cd06c0e3ac60a94dcf6e47c1c3dda:

Attachment "tk-windows-uniscribe-measure.patch" to ticket [f3d96411] added by Arnault01 2026-10-30 01:42:55. (unpublished)Also attachment "tk-windows-uniscribe-measure.patch" to ticket [59d6d5f6] added by Arnault01 2026-10-28 03:07:42. (unpublished)
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -8840,6 +8840,19 @@
 	fit = MeasureChars(tkfont, chars, charsLen, 0, bend,
 			   ciPtr->baseChunkPtr->x + xDisplacement, maxX, flags, nextXPtr);
 
+	/*
+	 * The Windows backend (Uniscribe) can return a non-monotonic
+	 * position when the measured range ends with a control character
+	 * such as '\n': the returned right edge may be to the left of the
+	 * span start, producing chunks with negative width (e.g. the
+	 * newline chunk), which corrupts DLine length and justification.
+	 * Clamp to the span start so such characters get zero width.
+	 */
+
+	if (*nextXPtr < startX) {
+	    *nextXPtr = startX;
+	}
+
 	if (fit < bstart) {
 	    return 0;
 	} else {