mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 15:47:39 +03:00
fix(parser): handle oversized words in line break algorithm
When a word exceeds the page width, the DP algorithm would leave dp[i] = MAX_COST, causing a cascade failure where all preceding words also got MAX_COST. This resulted in each word being placed on its own line. Fix: When dp[i] remains MAX_COST after the inner loop, force the oversized word onto its own line (ans[i] = i) and inherit the cost from the next word (dp[i] = dp[i+1]) to allow preceding words to find valid configurations.
This commit is contained in:
parent
abe3e6c6db
commit
d3848779f9
@ -106,6 +106,18 @@ std::vector<size_t> ParsedText::computeLineBreaks(const int pageWidth, const int
|
|||||||
ans[i] = j; // j is the index of the last word in this optimal line
|
ans[i] = j; // j is the index of the last word in this optimal line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle oversized word: if no valid configuration found, force single-word line
|
||||||
|
// This prevents cascade failure where one oversized word breaks all preceding words
|
||||||
|
if (dp[i] == MAX_COST) {
|
||||||
|
ans[i] = i; // Just this word on its own line
|
||||||
|
// Inherit cost from next word to allow subsequent words to find valid configurations
|
||||||
|
if (i + 1 < static_cast<int>(totalWordCount)) {
|
||||||
|
dp[i] = dp[i + 1];
|
||||||
|
} else {
|
||||||
|
dp[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stores the index of the word that starts the next line (last_word_index + 1)
|
// Stores the index of the word that starts the next line (last_word_index + 1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user