mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 07:37:37 +03:00
Enhance hyphenation logic to allow fallback breaks for better line breaking in ParsedText
This commit is contained in:
parent
f0ea0b4d5b
commit
07f1786ff2
@ -177,7 +177,9 @@ std::vector<size_t> 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<size_t> 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<uint16_t>& wordWidths) {
|
||||
const int fontId, std::vector<uint16_t>& 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;
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ class ParsedText {
|
||||
std::vector<size_t> computeHyphenatedLineBreaks(const GfxRenderer& renderer, int fontId, int pageWidth,
|
||||
int spaceWidth, std::vector<uint16_t>& wordWidths);
|
||||
bool hyphenateWordAtIndex(size_t wordIndex, int availableWidth, const GfxRenderer& renderer, int fontId,
|
||||
std::vector<uint16_t>& wordWidths);
|
||||
std::vector<uint16_t>& wordWidths, bool allowFallbackBreaks);
|
||||
void extractLine(size_t breakIndex, int pageWidth, int spaceWidth, const std::vector<uint16_t>& wordWidths,
|
||||
const std::vector<size_t>& lineBreakIndices,
|
||||
const std::function<void(std::shared_ptr<TextBlock>)>& processLine);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user