diff options
author | Sebastian Geerken <devnull@localhost> | 2014-11-06 23:20:48 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-11-06 23:20:48 +0100 |
commit | 88943c42e9d667f93b4ec12b5eb0c886a29a02a1 (patch) | |
tree | 61db2b4757e39e055de3db15b50f81d14b57b0a5 | |
parent | aa797832f08ae3fcfd3fbd00054e16861f3eb2d5 (diff) |
Fixed TextblockIterator::getAllocation() for words not yet belonging to a line.
-rw-r--r-- | dw/textblock.cc | 3 | ||||
-rw-r--r-- | dw/textblock_iterator.cc | 51 |
2 files changed, 46 insertions, 8 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index bad00624..47ed7bdb 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -3108,7 +3108,8 @@ Textblock *Textblock::getTextblockForLine (Line *line) Textblock *Textblock::getTextblockForLine (int lineNo) { - int firstWord = lineNo == 0 ? 0 :lines->getRef(lineNo - 1)->lastWord + 1; + // Can also be used for a line not yet existing. + int firstWord = lineNo == 0 ? 0 : lines->getRef(lineNo - 1)->lastWord + 1; int lastWord = lineNo < lines->size() ? lines->getRef(lineNo)->lastWord : words->size() - 1; return getTextblockForLine (firstWord, lastWord); diff --git a/dw/textblock_iterator.cc b/dw/textblock_iterator.cc index 6cc8c81b..b6423a29 100644 --- a/dw/textblock_iterator.cc +++ b/dw/textblock_iterator.cc @@ -284,14 +284,52 @@ void Textblock::TextblockIterator::getAllocation (int start, int end, *allocation = *(textblock->outOfFlowMgr->getWidget(index)->getAllocation()); } else { - int lineIndex = textblock->findLineOfWord (index); - Line *line = textblock->lines->getRef (lineIndex); Word *word = textblock->words->getRef (index); + int firstWordOfLine, textOffset, lineYOffsetCanvas, lineBorderAscent; + + int lineIndex = textblock->findLineOfWord (index); - allocation->x = - textblock->allocation.x + line->textOffset; + // It may be that the line does not exist yet. + if (lineIndex != -1) { + // Line exists: simple. + Line *line = textblock->lines->getRef (lineIndex); + firstWordOfLine = line->firstWord; + textOffset = line->textOffset; + lineYOffsetCanvas = textblock->lineYOffsetCanvas (line); + lineBorderAscent = line->borderAscent; + } else { + // Line does not exist. Calculate the values in a similar way as in + // Textblock::addLine(). + Line *prevLine = textblock->lines->size () > 0 ? + textblock->lines->getLastRef () : NULL; + firstWordOfLine = prevLine ? prevLine->lastWord + 1 : 0; + + // The variable textOffset, defined below, is what Line::leftOffset + // will be for the next line; Line::textOffset itself cannot be + // calculated before the line is complete. + bool regardBorder = + textblock->mustBorderBeRegarded (textblock->lines->size ()); + textOffset = + misc::max (regardBorder ? textblock->newLineLeftBorder : 0, + textblock->boxOffsetX () + textblock->leftInnerPadding + + (textblock->lines->size () == 0 ? + textblock->line1OffsetEff : 0)); + + lineYOffsetCanvas = textblock->yOffsetOfLineToBeCreated (); + + lineBorderAscent = 0; + for (int i = firstWordOfLine; i < textblock->words->size (); i++) { + Word *w = textblock->words->getRef (i); + int borderAscent = + w->content.type == core::Content::WIDGET_IN_FLOW ? + w->size.ascent - w->content.widget->getStyle()->margin.top : + w->size.ascent; + lineBorderAscent = misc::max (lineBorderAscent, borderAscent); + } + } - for (int i = line->firstWord; i < index; i++) { + allocation->x = textblock->allocation.x + textOffset; + for (int i = firstWordOfLine; i < index; i++) { Word *w = textblock->words->getRef(i); allocation->x += w->size.width + w->effSpace; } @@ -303,8 +341,7 @@ void Textblock::TextblockIterator::getAllocation (int start, int end, && word->content.text[start] == 0); } - allocation->y = textblock->lineYOffsetCanvas (line) + line->borderAscent - - word->size.ascent; + allocation->y = lineYOffsetCanvas + lineBorderAscent - word->size.ascent; allocation->width = word->size.width; if (word->content.type == core::Content::TEXT) { |