From 9819d1b35e6c0c29763ea68d08a7d79aaec63b61 Mon Sep 17 00:00:00 2001 From: Mirko Pecora Date: Fri, 3 Jul 2026 09:47:59 +0200 Subject: [PATCH] fix(text): improve effective space width calculation in wrapLine function --- src/core/text-rendering/TextLayoutEngine.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/text-rendering/TextLayoutEngine.ts b/src/core/text-rendering/TextLayoutEngine.ts index d64e15a..dd7baa8 100644 --- a/src/core/text-rendering/TextLayoutEngine.ts +++ b/src/core/text-rendering/TextLayoutEngine.ts @@ -454,8 +454,9 @@ export const wrapLine = ( continue; } const space = spaces[spaceIdx++] || ''; - // For width calculation, treat ZWSP as having 0 width but regular space functionality - const effectiveSpaceWidth = space === '\u200B' ? 0 : spaceWidth; + // Measure the real separator \u2014 multi-space runs collapse into one match. + const effectiveSpaceWidth = + space.length > 0 ? measureText(space, fontFamily, letterSpacing) : 0; const totalWidth = currentLineWidth + effectiveSpaceWidth + wordWidth; if (totalWidth < maxWidth) {