From 398b53eed8b7bc1f59fc14c0dab14c67e82b7f4a Mon Sep 17 00:00:00 2001 From: MurakamiShinyu Date: Mon, 5 Feb 2024 16:08:22 +0900 Subject: [PATCH] fix: text-spacing-trim:space-first not working properly in some case - fix #1261 --- .../core/src/vivliostyle/text-polyfill.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/core/src/vivliostyle/text-polyfill.ts b/packages/core/src/vivliostyle/text-polyfill.ts index b5e7a7fd7..ba13d2412 100644 --- a/packages/core/src/vivliostyle/text-polyfill.ts +++ b/packages/core/src/vivliostyle/text-polyfill.ts @@ -446,16 +446,21 @@ class TextSpacingPolyfill { function checkIfFirstInBlock(): boolean { const p = checkPoints[0]; - let viewNode = p.viewNode; - let parent = p.parent; - while (parent && parent.inline) { - parent = parent.parent; + for (let pp = p; ; pp = pp.parent) { + if (!pp || !pp.inline) { + if (pp?.fragmentIndex !== 1) { + // This block is not the first fragment + return false; + } + break; + } } - if (parent?.fragmentIndex !== 1) { - return false; + if (!p.inline) { + // This is at the start of the block + return true; } for ( - let prev = viewNode.previousSibling; + let prev = p.viewNode.previousSibling; prev; prev = prev.previousSibling ) {