aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/textblock_linebreaking.cc36
-rw-r--r--test/table-narrow.html9
2 files changed, 30 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,
diff --git a/test/table-narrow.html b/test/table-narrow.html
new file mode 100644
index 00000000..ad28417d
--- /dev/null
+++ b/test/table-narrow.html
@@ -0,0 +1,9 @@
+<table border=1>
+<tr>
+<td>W d<whatever>aaaaaaaaaaaa*<br>
+<td>WW d<whatever>aaaaaaaaaaaa*<br>
+<td>WWW d<whatever>aaaaaaaaaaaa*<br>
+<td>WWWW d<whatever>aaaaaaaaaaaa*<br>
+<td>WWWWW d<whatever>aaaaaaaaaaaa*<br>
+<td>WWWWWW d<whatever>aaaaaaaaaaaa*<br>
+</table>