From ac2616a2749d3b51a1c5a2d73e143a36d48222f7 Mon Sep 17 00:00:00 2001 From: Sebastian Geerken Date: Thu, 18 Apr 2013 14:56:51 +0200 Subject: Fixed limited floats search, and integrated it into textblock widget. (Still not fully working.) --- dw/outofflowmgr.cc | 69 ++++++++++++++++++++++++++++++-------------- dw/outofflowmgr.hh | 4 +-- dw/textblock.cc | 1 + dw/textblock.hh | 1 + dw/textblock_linebreaking.cc | 19 ++++++++---- lout/container.cc | 2 +- 6 files changed, 65 insertions(+), 31 deletions(-) diff --git a/dw/outofflowmgr.cc b/dw/outofflowmgr.cc index d775501c..390f3e2c 100644 --- a/dw/outofflowmgr.cc +++ b/dw/outofflowmgr.cc @@ -131,11 +131,11 @@ int OutOfFlowMgr::Float::CompareSideSpanningIndex::compare(Object *o1, return ((Float*)o1)->sideSpanningIndex - ((Float*)o2)->sideSpanningIndex; } - -int OutOfFlowMgr::SortedFloatsVector::find (Textblock *textblock, int y, - Textblock *lastGB, int lastExtIndex) +int OutOfFlowMgr::SortedFloatsVector::findFloatIndex (Textblock *lastGB, + int lastExtIndex) { - int last; + // TODO Is the case "lastGB == NULL" (search until the end) needed? + assert (lastGB); if (lastGB) { TypedPointer key (lastGB); @@ -153,30 +153,48 @@ int OutOfFlowMgr::SortedFloatsVector::find (Textblock *textblock, int y, } if (lastFloat) - last = lastFloat->index; + // Float found with the same generator. + return lastFloat->index; else { - if (tbInfo->index > 0) { - TBInfo *prev = oofm->tbInfos->get (tbInfo->index - 1); - SortedFloatsVector *prevList = - side == LEFT ? prev->leftFloatsGB : prev->rightFloatsGB; - // Each GB list contains at least one elemenent, - // otherwise it would not have been created; so the - // following is save. - Float *lastFloat = prevList->get (prevList->size() - 1); - last = lastFloat->index; - } else - last = -1; + // No float until "lastExtIndex"; search backwards in the + // list of text blocks. + int last = -1; // If nothing is found. + + // If not allocated, the only list to search is the GB + // list, which has been searched already. + if (oofm->wasAllocated (lastGB)) { + for (int index = tbInfo->index - 1; last == -1 && index >= 0; + index--) { + TBInfo *prev = oofm->tbInfos->get (index); + SortedFloatsVector *prevList = + side == LEFT ? prev->leftFloatsGB : prev->rightFloatsGB; + // Even if each GB list contains at least one elemenent + // (otherwise it would not have been created), this one + // element may be in the wrong (i. e. opposite) + // list. So, this list may be empty. save. + if (prevList->size() > 0) { + Float *lastFloat = prevList->get (prevList->size() - 1); + last = lastFloat->index; + } + } + } + + return last; } } else - last = size () - 1; + // "lastGB" not yet registered. TODO Correct? + return size () - 1; } else - last = size() - 1; + return size() - 1; +} +int OutOfFlowMgr::SortedFloatsVector::find (Textblock *textblock, int y, + int start, int end) +{ Float key (oofm, NULL, NULL, 0); key.generatingBlock = textblock; key.yReal = y; - - return bsearch (&key, false, 0, last); + return bsearch (&key, false, start, end); } int OutOfFlowMgr::SortedFloatsVector::findFirst (Textblock *textblock, @@ -184,10 +202,17 @@ int OutOfFlowMgr::SortedFloatsVector::findFirst (Textblock *textblock, Textblock *lastGB, int lastExtIndex) { - int i = find (textblock, y, lastGB, lastExtIndex); + int last = findFloatIndex (lastGB, lastExtIndex); + int i = find (textblock, y, 0, last); + + //printf ("[%p] FIND (%p, %d, %p, %d) => last = %d, result = %d\n", + // oofm->containingBlock, textblock, y,lastGB, lastExtIndex, last, i); + + if (i < 0 || i > last) + return -1; if (i > 0 && get(i - 1)->covers (textblock, y, h)) return i - 1; - else if (i < size() && get(i)->covers (textblock, y, h)) + else if (i <= last && get(i)->covers (textblock, y, h)) return i; else return -1; diff --git a/dw/outofflowmgr.hh b/dw/outofflowmgr.hh index 18ac801d..718eed48 100644 --- a/dw/outofflowmgr.hh +++ b/dw/outofflowmgr.hh @@ -88,8 +88,8 @@ private: lout::container::typed::Vector (1, false) { this->oofm = oofm; this->side = side; } - int find (Textblock *textblock, int y, Textblock *lastGB, - int lastExtIndex); + int findFloatIndex (Textblock *lastGB, int lastExtIndex); + int find (Textblock *textblock, int y, int start, int end); int findFirst (Textblock *textblock, int y, int h, Textblock *lastGB, int lastExtIndex); int findLastBeforeSideSpanningIndex (int sideSpanningIndex); diff --git a/dw/textblock.cc b/dw/textblock.cc index 19210fce..03eeb33f 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -130,6 +130,7 @@ Textblock::Textblock (bool limitTextWidth) mustQueueResize = false; redrawY = 0; lastWordDrawn = -1; + lastPositionedOofWidget = -1; /* * The initial sizes of lines and words should not be diff --git a/dw/textblock.hh b/dw/textblock.hh index 4eb5a264..e188031a 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -445,6 +445,7 @@ protected: are the line numbers, not the value stored in parentRef. */ + int lastPositionedOofWidget; lout::misc::SimpleVector *lines; lout::misc::SimpleVector *paragraphs; diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 4a5922b4..1256f348 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -401,7 +401,8 @@ Textblock::Line *Textblock::addLine (int firstWord, int lastWord, int y = line->top + getStyle()->boxOffsetY(); int h = line->boxAscent + line->boxDescent; leftBorder = - containingBlock->outOfFlowMgr->getLeftBorder (this, y, h, NULL, 0); + containingBlock->outOfFlowMgr->getLeftBorder (this, y, h, this, + lastPositionedOofWidget); } else leftBorder = 0; @@ -536,8 +537,10 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll) // disputable. (More on this later.) thereWillBeMoreSpace = - containingBlock->outOfFlowMgr->hasFloatLeft (this, y, h, NULL, 0) || - containingBlock->outOfFlowMgr->hasFloatRight (this, y, h, NULL, 0); + containingBlock->outOfFlowMgr->hasFloatLeft (this, y, h, this, + lastPositionedOofWidget) || + containingBlock->outOfFlowMgr->hasFloatRight (this, y, h, this, + lastPositionedOofWidget); PRINTF (" thereWillBeMoreSpace = %s (y = %d, h = %d)\n", thereWillBeMoreSpace ? "true" : "false", y, h); @@ -701,7 +704,8 @@ void Textblock::wrapWidgetOofRef (int wordIndex) containingBlock->outOfFlowMgr->tellPosition (words->getRef(wordIndex)->content.widget, top + getStyle()->boxOffsetY()); - + lastPositionedOofWidget = wordIndex; + // TODO: compare old/new values of calcAvailWidth(...) (?) int firstIndex = lines->size() == 0 ? 0 : lines->getLastRef()->lastWord + 1; @@ -1143,9 +1147,11 @@ int Textblock::calcAvailWidth (int lineIndex) int y = topOfPossiblyMissingLine (lineIndex); int h = heightOfPossiblyMissingLine (lineIndex); leftBorder = - containingBlock->outOfFlowMgr->getLeftBorder (this, y, h, NULL, 0); + containingBlock->outOfFlowMgr->getLeftBorder (this, y, h, this, + lastPositionedOofWidget); rightBorder = - containingBlock->outOfFlowMgr->getRightBorder (this, y, h, NULL, 0); + containingBlock->outOfFlowMgr->getRightBorder (this, y, h, this, + lastPositionedOofWidget); } else leftBorder = rightBorder = 0; @@ -1256,6 +1262,7 @@ void Textblock::rewrap () * the line list up from this position is rebuild. */ lines->setSize (wrapRefLines); nonTemporaryLines = misc::min (nonTemporaryLines, wrapRefLines); + lastPositionedOofWidget = -1; int firstWord; if (lines->size () > 0) diff --git a/lout/container.cc b/lout/container.cc index 5f3be123..7197ba74 100644 --- a/lout/container.cc +++ b/lout/container.cc @@ -204,7 +204,7 @@ void Vector::sort(Comparator *comparator) * insertion; see insertSortet()). */ int Vector::bsearch(Object *key, bool mustExist, int start, int end, - Comparator *comparator) + Comparator *comparator) { // The case !mustExist is not handled by bsearch(3), so here is a // new implementation. -- cgit v1.2.3