aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2014-04-01 14:07:32 +0200
committerSebastian Geerken <devnull@localhost>2014-04-01 14:07:32 +0200
commit244a03a0baef40605e2c1d3e5805241bf7a142b4 (patch)
treed21dd20e2b01c1d10ec023861051e5a8ecadcd64
parent4184225ff4fb71cc4cef003f18b85f1f949e115a (diff)
Solved problems with OOF references at the end of a textblock.
-rw-r--r--dw/textblock.cc30
-rw-r--r--dw/textblock.hh1
-rw-r--r--dw/textblock_linebreaking.cc33
3 files changed, 49 insertions, 15 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index e0e35237..49030d26 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -294,19 +294,8 @@ Textblock::~Textblock ()
/* make sure not to call a free'd tooltip (very fast overkill) */
hoverTooltip = NULL;
- for (int i = 0; i < words->size(); i++) {
- Word *word = words->getRef (i);
-
- if (word->content.type == core::Content::WIDGET_IN_FLOW)
- delete word->content.widget;
- /** \todo Widget references? What about texts? */
-
- removeWordImgRenderer (i);
- removeSpaceImgRenderer (i);
-
- word->style->unref ();
- word->spaceStyle->unref ();
- }
+ for (int i = 0; i < words->size(); i++)
+ cleanupWord (i);
for (int i = 0; i < anchors->size(); i++) {
Anchor *anchor = anchors->getRef (i);
@@ -1708,6 +1697,21 @@ void Textblock::initWord (int wordNo)
word->spaceImgRenderer = NULL;
}
+void Textblock::cleanupWord (int wordNo)
+{
+ Word *word = words->getRef (wordNo);
+
+ if (word->content.type == core::Content::WIDGET_IN_FLOW)
+ delete word->content.widget;
+ /** \todo Widget references? What about texts? */
+
+ removeWordImgRenderer (wordNo);
+ removeSpaceImgRenderer (wordNo);
+
+ word->style->unref ();
+ word->spaceStyle->unref ();
+}
+
void Textblock::removeWordImgRenderer (int wordNo)
{
Word *word = words->getRef (wordNo);
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 9cc794b8..0b68d36f 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -595,6 +595,7 @@ protected:
core::style::Style *style);
void breakAdded ();
void initWord (int wordNo);
+ void cleanupWord (int wordNo);
void removeWordImgRenderer (int wordNo);
void setWordImgRenderer (int wordNo);
void removeSpaceImgRenderer (int wordNo);
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 44f7c2dc..0cb5e971 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -1803,14 +1803,42 @@ void Textblock::showMissingLines ()
{
DBG_OBJ_MSG ("construct.line", 0, "<b>showMissingLines</b> ()");
DBG_OBJ_MSG_START ();
+
+ // "Temporary word": when the last word is an OOF reference, it is
+ // not processed, and not part of any line. For this reason, we
+ // introduce a "temporary word", which is in flow, after this last
+ // OOF reference, and later removed again.
+ bool tempWord = words->size () > 0 &&
+ words->getLastRef()->content.type == core::Content::WIDGET_OOF_REF;
int firstWordToWrap =
lines->size () > 0 ? lines->getLastRef()->lastWord + 1 : 0;
- DBG_OBJ_MSGF ("construct.line", 1, "firstWordToWrap = %d (of %d)",
- firstWordToWrap, words->size ());
+
+ DBG_OBJ_MSGF ("construct.line", 1,
+ "words->size() = %d, firstWordToWrap = %d, tempWord = %d",
+ words->size (), firstWordToWrap, tempWord ? "true" : "false");
+
+ if (tempWord) {
+ core::Requisition size = { 0, 0, 0 };
+ addText0 ("", 0, Word::WORD_START | Word::WORD_END, getStyle (), &size);
+ }
for (int i = firstWordToWrap; i < words->size (); i++)
wordWrap (i, true);
+ // Remove temporary word again. The only reference should be the line.
+ if (tempWord) {
+ cleanupWord (words->size () - 1);
+ words->setSize (words->size () - 1);
+ if (lines->getLastRef()->lastWord > words->size () - 1)
+ lines->getLastRef()->lastWord = words->size () - 1;
+ }
+
+ // The following old code should not be necessary anymore, after
+ // the introduction of the "virtual word". Instead, test the
+ // condition.
+ assert (lines->size () == 0 ||
+ lines->getLastRef()->lastWord == words->size () - 1);
+ /*
// In some cases, there are some words of type WIDGET_OOF_REF left, which
// are not added to line, since addLine() is only called within
// wrapWordInFlow(), but not within wrapWordOofRef(). The missing line
@@ -1823,6 +1851,7 @@ void Textblock::showMissingLines ()
firstWordNotInLine, words->size ());
if (firstWordNotInLine < words->size ())
addLine (firstWordNotInLine, words->size () - 1, -1, true);
+ */
DBG_OBJ_MSG_END ();
}