summaryrefslogtreecommitdiff
path: root/dw/textblock_iterator.cc
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2014-11-08 14:57:16 +0100
committerSebastian Geerken <devnull@localhost>2014-11-08 14:57:16 +0100
commitaa4f6269918fcfc5ebd11d3b712e88577773ba02 (patch)
tree9e914def2dc344a71c266f4361123abcbde88cba /dw/textblock_iterator.cc
parentfaa8d1b65d9f724445e068d2766356103204728a (diff)
parent550d933b21d548411fe862d6a24ce73e4d5621c5 (diff)
Merge with main repo.
Diffstat (limited to 'dw/textblock_iterator.cc')
-rw-r--r--dw/textblock_iterator.cc56
1 files changed, 47 insertions, 9 deletions
diff --git a/dw/textblock_iterator.cc b/dw/textblock_iterator.cc
index 8da692d6..95e2ce65 100644
--- a/dw/textblock_iterator.cc
+++ b/dw/textblock_iterator.cc
@@ -188,15 +188,54 @@ void Textblock::TextblockIterator::getAllocation (int start, int end,
{
if (inFlow ()) {
Textblock *textblock = (Textblock*)getWidget();
- int index = getInFlowIndex (),
- lineIndex = textblock->findLineOfWord (index);
- Line *line = textblock->lines->getRef (lineIndex);
- Word *word = textblock->words->getRef (index);
- allocation->x =
- textblock->allocation.x + line->textOffset;
+ int index = getInFlowIndex ();
+ Word *word = textblock->words->getRef (index);
+ int firstWordOfLine, textOffset, lineYOffsetCanvas, lineBorderAscent;
+
+ int lineIndex = textblock->findLineOfWord (index);
+
+ // 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;
}
@@ -208,8 +247,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) {