From 12372aaafcd35ccc28d259bbf4ba4d0379a3b8f3 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Sat, 25 Apr 2026 11:19:04 +0200 Subject: [PATCH] Clamp indent to page dimensions Co-authored-by: Copilot --- lib/Epub/Epub/ParsedText.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Epub/Epub/ParsedText.cpp b/lib/Epub/Epub/ParsedText.cpp index 60528ede..e24094f7 100644 --- a/lib/Epub/Epub/ParsedText.cpp +++ b/lib/Epub/Epub/ParsedText.cpp @@ -295,7 +295,7 @@ std::vector ParsedText::computeLineBreaks(const GfxRenderer& renderer, c // toggle. Only the implicit EmSpace fallback in applyParagraphIndent() is gated on it. const int firstLineIndent = blockStyle.textIndentDefined && (blockStyle.alignment == CssTextAlign::Justify || blockStyle.alignment == CssTextAlign::Left) - ? blockStyle.textIndent + ? std::min(std::max(static_cast(blockStyle.textIndent), -(pageWidth - 1)), pageWidth - 1) : 0; // Ensure any word that would overflow even as the first entry on a line is split using fallback hyphenation. @@ -428,7 +428,7 @@ size_t ParsedText::computeSingleLineBreakNoHyphen(const GfxRenderer& renderer, c const int firstLineIndent = lineStartIndex == 0 && blockStyle.textIndentDefined && (blockStyle.alignment == CssTextAlign::Justify || blockStyle.alignment == CssTextAlign::Left) - ? blockStyle.textIndent + ? std::min(std::max(static_cast(blockStyle.textIndent), -(pageWidth - 1)), pageWidth - 1) : 0; const int effectivePageWidth = pageWidth - firstLineIndent; @@ -496,7 +496,7 @@ std::vector ParsedText::computeHyphenatedLineBreaks(const GfxRenderer& r // toggle. Only the implicit EmSpace fallback in applyParagraphIndent() is gated on it. const int firstLineIndent = blockStyle.textIndentDefined && (blockStyle.alignment == CssTextAlign::Justify || blockStyle.alignment == CssTextAlign::Left) - ? blockStyle.textIndent + ? std::min(std::max(static_cast(blockStyle.textIndent), -(pageWidth - 1)), pageWidth - 1) : 0; // Pre-compute inter-word gaps to avoid repeated codepoint scanning and renderer @@ -789,7 +789,7 @@ ParsedText::LineProcessResult ParsedText::extractLine( const int firstLineIndent = isFirstLine && blockStyle.textIndentDefined && (blockStyle.alignment == CssTextAlign::Justify || blockStyle.alignment == CssTextAlign::Left) - ? blockStyle.textIndent + ? std::min(std::max(static_cast(blockStyle.textIndent), -(pageWidth - 1)), pageWidth - 1) : 0; // Calculate total word width for this line, count actual word gaps,