From 8580277131ae88c18e040c8bdfa7910425fbb85a Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Wed, 7 Jan 2026 20:36:06 +0500 Subject: [PATCH] improve explicit hyphen breaking logic --- lib/Epub/Epub/ParsedText.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Epub/Epub/ParsedText.cpp b/lib/Epub/Epub/ParsedText.cpp index ed4b0693..8c9802fe 100644 --- a/lib/Epub/Epub/ParsedText.cpp +++ b/lib/Epub/Epub/ParsedText.cpp @@ -179,11 +179,13 @@ std::vector ParsedText::computeHyphenatedLineBreaks(const GfxRenderer& r // Word would overflow — try to split based on hyphenation points const int availableWidth = pageWidth - lineWidth - spacing; - const bool allowFallbackBreaks = isFirstWord; // Permit soft hyphen tokens only when first word still overflows + const bool allowFallbackBreaks = isFirstWord; // Permit fallback breaks only when first word one the line still overflows if (availableWidth > 0 && hyphenateWordAtIndex(currentIndex, availableWidth, renderer, fontId, wordWidths, allowFallbackBreaks)) { - // widths vector updated for split prefix; re-evaluate same index - continue; + // Prefix now fits; append it to this line and immediately move to the next line + lineWidth += spacing + wordWidths[currentIndex]; + currentIndex += 1; + break; } // Could not split: force at least one word per line to avoid infinite loop