aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-01-09 13:24:15 +0100
committerSebastian Geerken <devnull@localhost>2013-01-09 13:24:15 +0100
commit92d1e8dbc99e5fa336886082e4eb4a99a8b22c91 (patch)
tree2e5bf391f246e73d7181fed09957b356429e4869 /dw
parentfe7da790d3042ade512fa8bcfd1c2720fc2c6442 (diff)
New attribute Line::offsetCompleteWidget, replaces method lineXOffsetWidget(), and so makes drawing much more efficient.
Diffstat (limited to 'dw')
-rw-r--r--dw/textblock.cc10
-rw-r--r--dw/textblock.hh31
-rw-r--r--dw/textblock_iterator.cc2
-rw-r--r--dw/textblock_linebreaking.cc13
4 files changed, 20 insertions, 36 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 799ccbad..7af85668 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -362,7 +362,7 @@ void Textblock::sizeAllocateImpl (core::Allocation *allocation)
for (lineIndex = 0; lineIndex < lines->size (); lineIndex++) {
line = lines->getRef (lineIndex);
- xCursor = lineXOffsetWidget (line);
+ xCursor = line->offsetCompleteWidget;
for (wordIndex = line->firstWord; wordIndex <= line->lastWord;
wordIndex++) {
@@ -757,11 +757,11 @@ bool Textblock::sendSelectionEvent (core::SelectionState::EventType eventType,
// Choose this break.
wordIndex = line->lastWord;
charPos = core::SelectionState::END_OF_WORD;
- } else if (event->xWidget < lineXOffsetWidget (line)) {
+ } else if (event->xWidget < line->offsetCompleteWidget) {
// Left of the first word in the line.
wordIndex = line->firstWord;
} else {
- int nextWordStartX = lineXOffsetWidget (line);
+ int nextWordStartX = line->offsetCompleteWidget;
for (wordIndex = line->firstWord;
wordIndex <= line->lastWord;
@@ -1235,7 +1235,7 @@ void Textblock::drawSpace(int wordIndex, core::View *view,
*/
void Textblock::drawLine (Line *line, core::View *view, core::Rectangle *area)
{
- int xWidget = lineXOffsetWidget(line);
+ int xWidget = line->offsetCompleteWidget;
int yWidgetBase = lineYOffsetWidget (line) + line->boxAscent;
for (int wordIndex = line->firstWord;
@@ -1393,7 +1393,7 @@ Textblock::Word *Textblock::findWord (int x, int y, bool *inSpace)
if (yWidgetBase + line->boxDescent <= y)
return NULL;
- xCursor = lineXOffsetWidget (line);
+ xCursor = line->offsetCompleteWidget;
for (wordIndex = line->firstWord; wordIndex <= line->lastWord;wordIndex++) {
word = words->getRef (wordIndex);
lastXCursor = xCursor;
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 879ff75e..22f68fe3 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -282,7 +282,7 @@ protected:
/* "top" is always relative to the top of the first line, i.e.
* page->lines[0].top is always 0. */
int top, boxAscent, boxDescent, contentAscent, contentDescent,
- breakSpace, leftOffset;
+ breakSpace, leftOffset, offsetCompleteWidget;
/* This is similar to descent, but includes the bottom margins of the
* widgets within this line. */
@@ -512,35 +512,6 @@ protected:
int diffXToContainingBlock, restWidthToContainingBlock,
diffYToContainingBlock;
- /**
- * \brief Returns the x offset (the indentation plus any offset
- * needed for centering or right justification) for the line,
- * relative to the allocation (i.e. including border etc.).
- */
- inline int lineXOffsetWidget (Line *line)
- {
- // TODO This method is called very often, every time a line is
- // *drawn*. To reduce calls to OutOfFlowMgr::getLeftBorder
- // (which searches through all floats each time), the value
- // should (in the layouting phase) be stored in the line.
-
- assert (diffXToContainingBlock != -1);
- assert (diffYToContainingBlock != -1);
-
- int resultFromOOFM;
- if (containingBlock->outOfFlowMgr && mustBorderBeRegarded (line))
- resultFromOOFM =
- containingBlock->outOfFlowMgr->getLeftBorder
- (line->top + getStyle()->boxOffsetY() + diffYToContainingBlock)
- - diffXToContainingBlock;
- else
- resultFromOOFM = 0;
-
- return innerPadding + line->leftOffset +
- (line == lines->getFirstRef() ? line1OffsetEff : 0) +
- lout::misc::max (getStyle()->boxOffsetX(), resultFromOOFM);
- }
-
inline int lineLeftBorder (int lineNo)
{
assert (diffXToContainingBlock != -1);
diff --git a/dw/textblock_iterator.cc b/dw/textblock_iterator.cc
index 4831bff5..cfb235ac 100644
--- a/dw/textblock_iterator.cc
+++ b/dw/textblock_iterator.cc
@@ -269,7 +269,7 @@ void Textblock::TextblockIterator::getAllocation (int start, int end,
Word *word = textblock->words->getRef (index);
allocation->x =
- textblock->allocation.x + textblock->lineXOffsetWidget (line);
+ textblock->allocation.x + line->offsetCompleteWidget;
for (int i = line->firstWord; i < index; i++) {
Word *w = textblock->words->getRef(i);
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index b8a10207..143cc135 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -371,6 +371,19 @@ Textblock::Line *Textblock::addLine (int firstWord, int lastWord,
// the height should be positive.
line->boxAscent = misc::max (line->boxAscent, 1);
+ // Calculate offsetCompleteWidget, which includes also floats.
+ int resultFromOOFM;
+ if (containingBlock->outOfFlowMgr && mustBorderBeRegarded (line))
+ resultFromOOFM =
+ containingBlock->outOfFlowMgr->getLeftBorder
+ (line->top + getStyle()->boxOffsetY() + diffYToContainingBlock)
+ - diffXToContainingBlock;
+ else
+ resultFromOOFM = 0;
+ line->offsetCompleteWidget =
+ innerPadding + line->leftOffset + (lineIndex == 0 ? line1OffsetEff : 0) +
+ misc::max (getStyle()->boxOffsetX(), resultFromOOFM);
+
PRINTF (" line[%d].top = %d\n", lines->size () - 1, line->top);
PRINTF (" line[%d].boxAscent = %d\n", lines->size () - 1, line->boxAscent);
PRINTF (" line[%d].boxDescent = %d\n",