aboutsummaryrefslogtreecommitdiff
path: root/dw/textblock_linebreaking.cc
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2012-12-23 15:00:53 +0100
committerSebastian Geerken <devnull@localhost>2012-12-23 15:00:53 +0100
commit3d3afcaa0bd2cf546c7af00de4b4fd5b2b96c095 (patch)
tree687619a275389b3cc8b6b5d6654940e1b7c4acfe /dw/textblock_linebreaking.cc
parent53fdaaf20da1379ca3ed2ea63d3d698e5a76c65a (diff)
Generalized a previois bug fix (line too tight but no possible breaks).
Diffstat (limited to 'dw/textblock_linebreaking.cc')
-rw-r--r--dw/textblock_linebreaking.cc36
1 files changed, 21 insertions, 15 deletions
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index e0799816..e9200cdf 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -453,7 +453,6 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
this, wordIndex, wrapAll ? "true" : "false");
Word *word;
- //core::Extremes wordExtremes;
if (!wrapAll)
removeTemporaryLines ();
@@ -465,6 +464,10 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
accumulateWordData (wordIndex);
+ //printf (" ");
+ //printWord (word);
+ //printf ("\n");
+
int penaltyIndex = calcPenaltyIndexForNewLine ();
bool newLine;
@@ -486,17 +489,23 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
newLine = true;
searchUntil = wordIndex;
PRINTF (" NEW LINE: forced break\n");
- } else if (wordIndex > firstIndex &&
- word->badnessAndPenalty.lineTooTight () &&
- words->getRef(wordIndex- 1)
- ->badnessAndPenalty.lineCanBeBroken (penaltyIndex)) {
- // TODO Comment the last condition (also below where the minimum is
- // searched for)
- newLine = true;
- searchUntil = wordIndex - 1;
- PRINTF (" NEW LINE: line too tight\n");
- } else
- newLine = false;
+ } else {
+ // Break the line when too tight, but only when there is a
+ // possible break point so far. (TODO: I've forgotten the
+ // original bug which is fixed by this.)
+ bool possibleLineBreak = false;
+ for (int i = firstIndex; !possibleLineBreak && i <= wordIndex - 1; i++)
+ if (words->getRef(i)->badnessAndPenalty
+ .lineCanBeBroken (penaltyIndex))
+ possibleLineBreak = true;
+
+ if (possibleLineBreak && word->badnessAndPenalty.lineTooTight ()) {
+ newLine = true;
+ searchUntil = wordIndex - 1;
+ PRINTF (" NEW LINE: line too tight\n");
+ } else
+ newLine = false;
+ }
if(!newLine && !wrapAll)
// No new line is added. "mustQueueResize" must,
@@ -523,9 +532,6 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
//printWord (w);
//printf ("\n");
- // TODO: is this condition needed:
- // if(w->badnessAndPenalty.lineCanBeBroken ()) ?
-
if (breakPos == -1 ||
w->badnessAndPenalty.compareTo
(penaltyIndex,