diff options
author | Sebastian Geerken <devnull@localhost> | 2013-04-25 11:06:54 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-04-25 11:06:54 +0200 |
commit | a1203a28631b26fc62bc55c30374a9d298f2827b (patch) | |
tree | f7cfcbd66dc1d94ab2a38510c1179ee77d16c3a0 | |
parent | 84f0997ee34de9eec93065f60b63f412f05ed64d (diff) |
Fixed problem with hyphenation.
-rw-r--r-- | dw/textblock_linebreaking.cc | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 83c1ceb1..7af2d75c 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -591,19 +591,29 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll) } int hyphenatedWord = -1; - Word *word1 = words->getRef(breakPos); + Word *wordBreak = words->getRef(breakPos); PRINTF ("[%p] line (broken at word %d): ", this, breakPos); //word1->badnessAndPenalty.print (); PRINTF ("\n"); - if (word1->badnessAndPenalty.lineTight () && - (word1->flags & Word::CAN_BE_HYPHENATED) && - word1->style->x_lang[0] && - word1->content.type == core::Content::TEXT && - Hyphenator::isHyphenationCandidate (word1->content.text)) - hyphenatedWord = breakPos; + if (wordBreak->badnessAndPenalty.lineTight ()) { + // Sometimes, it is not the last word, which must be + // hyphenated, but some word before. Here, we search + // for the first word which can be hyphenated, *and* + // makes the line too tight. + + for (int i = breakPos; i >= firstIndex; i--) { + Word *word1 = words->getRef (i); + if (word1->badnessAndPenalty.lineTight () && + (word1->flags & Word::CAN_BE_HYPHENATED) && + word1->style->x_lang[0] && + word1->content.type == core::Content::TEXT && + Hyphenator::isHyphenationCandidate (word1->content.text)) + hyphenatedWord = i; + } + } - if (word1->badnessAndPenalty.lineLoose () && + if (wordBreak->badnessAndPenalty.lineLoose () && breakPos + 1 < words->size ()) { Word *word2 = words->getRef(breakPos + 1); if ((word2->flags & Word::CAN_BE_HYPHENATED) && |