diff --git a/lib/Epub/Epub/ParsedText.cpp b/lib/Epub/Epub/ParsedText.cpp index 7dac22ad..305ba1a2 100644 --- a/lib/Epub/Epub/ParsedText.cpp +++ b/lib/Epub/Epub/ParsedText.cpp @@ -177,7 +177,9 @@ std::vector ParsedText::computeHyphenatedLineBreaks(const GfxRenderer& r } const int availableWidth = pageWidth - lineWidth - spacing; - if (availableWidth > 0 && hyphenateWordAtIndex(currentIndex, availableWidth, renderer, fontId, wordWidths)) { + const bool allowFallbackBreaks = isFirstWord; // Only permit fallback splits when even the first word overflows + if (availableWidth > 0 && + hyphenateWordAtIndex(currentIndex, availableWidth, renderer, fontId, wordWidths, allowFallbackBreaks)) { // Widths updated for the split word; retry with current index continue; } @@ -199,7 +201,8 @@ std::vector ParsedText::computeHyphenatedLineBreaks(const GfxRenderer& r // Splits words[wordIndex] into prefix+hyphen and remainder when a legal breakpoint fits the available width. bool ParsedText::hyphenateWordAtIndex(const size_t wordIndex, const int availableWidth, const GfxRenderer& renderer, - const int fontId, std::vector& wordWidths) { + const int fontId, std::vector& wordWidths, + const bool allowFallbackBreaks) { if (availableWidth <= 0 || wordIndex >= words.size()) { return false; } @@ -209,7 +212,7 @@ bool ParsedText::hyphenateWordAtIndex(const size_t wordIndex, const int availabl std::advance(wordIt, wordIndex); std::advance(styleIt, wordIndex); - const auto breakOffsets = Hyphenator::breakOffsets(*wordIt, true); + const auto breakOffsets = Hyphenator::breakOffsets(*wordIt, allowFallbackBreaks); if (breakOffsets.empty()) { return false; } diff --git a/lib/Epub/Epub/ParsedText.h b/lib/Epub/Epub/ParsedText.h index e7f53f9c..1089054e 100644 --- a/lib/Epub/Epub/ParsedText.h +++ b/lib/Epub/Epub/ParsedText.h @@ -24,7 +24,7 @@ class ParsedText { std::vector computeHyphenatedLineBreaks(const GfxRenderer& renderer, int fontId, int pageWidth, int spaceWidth, std::vector& wordWidths); bool hyphenateWordAtIndex(size_t wordIndex, int availableWidth, const GfxRenderer& renderer, int fontId, - std::vector& wordWidths); + std::vector& wordWidths, bool allowFallbackBreaks); void extractLine(size_t breakIndex, int pageWidth, int spaceWidth, const std::vector& wordWidths, const std::vector& lineBreakIndices, const std::function)>& processLine);