diff options
author | Sebastian Geerken <devnull@localhost> | 2014-09-01 01:03:02 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-09-01 01:03:02 +0200 |
commit | 710cd1504ba1d34aedd02e8d5f1e90e388e1a7fa (patch) | |
tree | 4ecb4e86d940a1a88c38ccf852d71af1b5d18676 | |
parent | a2cf34555c64fa87bd146071cf46bd381c695761 (diff) |
Some fixes on recent OOFM splitup.
-rw-r--r-- | dw/textblock_iterator.cc | 51 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 149 |
2 files changed, 104 insertions, 96 deletions
diff --git a/dw/textblock_iterator.cc b/dw/textblock_iterator.cc index 74cb3f98..8c47d99e 100644 --- a/dw/textblock_iterator.cc +++ b/dw/textblock_iterator.cc @@ -36,14 +36,16 @@ Textblock::TextblockIterator::TextblockIterator (Textblock *textblock, core::Iterator (textblock, mask, atEnd) { if (atEnd) { - // Note: either all or no OOFM is defined. - if (textblock->outOfFlowMgr[0]) { - oofmIndex = NUM_OOFM - 1; - index = textblock->outOfFlowMgr[NUM_OOFM - 1]->getNumWidgets(); - } else { - oofmIndex = -1; + oofmIndex = NUM_OOFM - 1; + while (oofmIndex >= 0 && + (textblock->outOfFlowMgr[oofmIndex] == NULL || + textblock->outOfFlowMgr[oofmIndex]->getNumWidgets() == 0)) + oofmIndex--; + + if (oofmIndex >= 0) + index = textblock->outOfFlowMgr[oofmIndex]->getNumWidgets(); + else index = textblock->words->size(); - } } else { oofmIndex = -1; index = -1; @@ -60,7 +62,7 @@ Textblock::TextblockIterator::TextblockIterator (Textblock *textblock, this->oofmIndex = oofmIndex; this->index = index; - // TODO To be completely exact, oofm should be considered here. + // TODO To be completely exact, oofmIndex should be considered here. if (index < 0) content.type = core::Content::START; else if (index >= textblock->words->size()) @@ -101,7 +103,8 @@ bool Textblock::TextblockIterator::next () // End of current OOFM list reached. oofmIndex++; while (oofmIndex < NUM_OOFM && - textblock->outOfFlowMgr[oofmIndex]->getNumWidgets() == 0) + (textblock->outOfFlowMgr[oofmIndex] == NULL || + textblock->outOfFlowMgr[oofmIndex]->getNumWidgets() == 0)) oofmIndex++; if (oofmIndex == NUM_OOFM) { @@ -120,25 +123,20 @@ bool Textblock::TextblockIterator::next () content = textblock->words->getRef(index)->content; else { // End of words list reached. - if (textblock->outOfFlowMgr[0] == NULL) { - // No OOFM widgets (no OOFM at all). + oofmIndex = 0; + while (oofmIndex < NUM_OOFM && + (textblock->outOfFlowMgr[oofmIndex] == NULL || + textblock->outOfFlowMgr[oofmIndex]->getNumWidgets() == 0)) + oofmIndex++; + + if (oofmIndex == NUM_OOFM) { content.type = core::Content::END; return false; } else { - oofmIndex = 0; - while (oofmIndex < NUM_OOFM && - textblock->outOfFlowMgr[oofmIndex]->getNumWidgets() == 0) - oofmIndex++; - - if (oofmIndex == NUM_OOFM) { - content.type = core::Content::END; - return false; - } else { - index = 0; - content.type = core::Content::WIDGET_OOF_CONT; - content.widget = - textblock->outOfFlowMgr[oofmIndex]->getWidget (index); - } + index = 0; + content.type = core::Content::WIDGET_OOF_CONT; + content.widget = + textblock->outOfFlowMgr[oofmIndex]->getWidget (index); } } } @@ -166,7 +164,8 @@ bool Textblock::TextblockIterator::prev () } else { oofmIndex--; while (oofmIndex >= 0 && - textblock->outOfFlowMgr[oofmIndex]->getNumWidgets() == 0) + (textblock->outOfFlowMgr[oofmIndex] == NULL || + textblock->outOfFlowMgr[oofmIndex]->getNumWidgets() == 0)) oofmIndex--; if (oofmIndex >= 0) { diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 619c97ce..4cb62631 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -1934,83 +1934,92 @@ void Textblock::calcBorders (int lastOofRef, int height) newLineLeftBorder = newLineRightBorder = 0; newLineLeftFloatHeight = newLineRightFloatHeight = 0; - // Either none or all are defined: - if (containingBlock[0] && containingBlock[0]->outOfFlowMgr[0]) { + bool oofmDefined = false; + for (int i = 0; i < NUM_OOFM && !oofmDefined; i++) + if (containingBlock[i] && containingBlock[i]->outOfFlowMgr[i]) + oofmDefined = true; + + if (oofmDefined) { int firstWordOfLine = lines->size() > 0 ? lines->getLastRef()->lastWord + 1 : 0; int effOofRef = misc::max (lastOofRef, firstWordOfLine - 1); int y = yOffsetOfPossiblyMissingLine (lines->size ()); for (int i = 0; i < NUM_OOFM; i++) { - // Consider the example: - // - // <div> - // Some text A ... - // <p> Some text B ... <img style="float:right" ...> </p> - // Some more text C ... - // </div> - // - // If the image is large enough, it should float around the last - // paragraph, "Some more text C ...": - // - // Some more text A ... - // - // Some more ,---------. - // text B ... | | - // | <img> | - // Some more | | <---- Consider this line! - // text C ... '---------' - // - // Since this float is generated in the <p> element, not in the- - // <div> element, and since they are represented by different - // instances of dw::Textblock, lastOofRefPositionedBeforeThisLine, - // and so lastOofRef, is -1 for the line marked with an arrow; - // this would result in ignoring the float, because -1 is - // equivalent to the very beginning of the <div> element ("Some - // more text A ..."), which is not affected by the float. - // - // On the other hand, the only relevant values of - // Line::lastOofRefPositionedBeforeThisLine are those greater - // than the first word of the new line, so a solution is to use - // the maximum of both. - - bool thisHasLeft, thisHasRight; OutOfFlowMgr *oofm = containingBlock[i]->outOfFlowMgr[i]; - - thisHasLeft = oofm->hasFloatLeft (this, y, height, this, effOofRef); - newLineHasFloatLeft = newLineHasFloatLeft || thisHasLeft; - thisHasRight = oofm->hasFloatRight (this, y, height, this, effOofRef); - newLineHasFloatRight = newLineHasFloatRight || thisHasRight; - - newLineLeftBorder = - misc::max (newLineLeftBorder, - oofm->getLeftBorder (this, y, height, this, effOofRef)); - newLineRightBorder = - misc::max (newLineRightBorder, - oofm->getRightBorder (this, y, height, this, effOofRef)); - - // TODO "max" is not really correct for the heights. (Does - // not matter, since only one, the float manager, returns - // meaningful values.) - if (thisHasLeft) - newLineLeftFloatHeight = - misc::max (newLineLeftFloatHeight, - oofm->getLeftFloatHeight (this, y, height, this, - effOofRef)); - if (thisHasRight) - newLineRightFloatHeight = - misc::max (newLineRightFloatHeight, - oofm->getRightFloatHeight (this, y, height, this, - effOofRef)); - - DBG_OBJ_MSGF ("construct.line", 1, - "%d * %d (%s) / %d * %d (%s), at %d (%d), until %d = " - "max (%d, %d - 1)", - newLineLeftBorder, newLineLeftFloatHeight, - newLineHasFloatLeft ? "true" : "false", - newLineRightBorder, newLineRightFloatHeight, - newLineHasFloatRight ? "true" : "false", - y, height, effOofRef, lastOofRef, firstWordOfLine); + if (oofm) { + // Consider the example: + // + // <div> + // Some text A ... + // <p> Some text B ... <img style="float:right" ...> </p> + // Some more text C ... + // </div> + // + // If the image is large enough, it should float around the last + // paragraph, "Some more text C ...": + // + // Some more text A ... + // + // Some more ,---------. + // text B ... | | + // | <img> | + // Some more | | <---- Consider this line! + // text C ... '---------' + // + // Since this float is generated in the <p> element, not in the- + // <div> element, and since they are represented by different + // instances of dw::Textblock, lastOofRefPositionedBeforeThisLine, + // and so lastOofRef, is -1 for the line marked with an arrow; + // this would result in ignoring the float, because -1 is + // equivalent to the very beginning of the <div> element ("Some + // more text A ..."), which is not affected by the float. + // + // On the other hand, the only relevant values of + // Line::lastOofRefPositionedBeforeThisLine are those greater + // than the first word of the new line, so a solution is to use + // the maximum of both. + + bool thisHasLeft, thisHasRight; + + thisHasLeft = oofm->hasFloatLeft (this, y, height, this, effOofRef); + newLineHasFloatLeft = newLineHasFloatLeft || thisHasLeft; + thisHasRight = oofm->hasFloatRight (this, y, height, this, + effOofRef); + newLineHasFloatRight = newLineHasFloatRight || thisHasRight; + + newLineLeftBorder = + misc::max (newLineLeftBorder, + oofm->getLeftBorder (this, y, height, this, + effOofRef)); + newLineRightBorder = + misc::max (newLineRightBorder, + oofm->getRightBorder (this, y, height, this, + effOofRef)); + + // TODO "max" is not really correct for the heights. (Does + // not matter, since only one, the float manager, returns + // meaningful values.) + if (thisHasLeft) + newLineLeftFloatHeight = + misc::max (newLineLeftFloatHeight, + oofm->getLeftFloatHeight (this, y, height, this, + effOofRef)); + if (thisHasRight) + newLineRightFloatHeight = + misc::max (newLineRightFloatHeight, + oofm->getRightFloatHeight (this, y, height, this, + effOofRef)); + + DBG_OBJ_MSGF ("construct.line", 1, + "OOFM #%d: %d * %d (%s) / %d * %d (%s), at %d (%d), " + "until %d = max (%d, %d - 1)", + i, newLineLeftBorder, newLineLeftFloatHeight, + newLineHasFloatLeft ? "true" : "false", + newLineRightBorder, newLineRightFloatHeight, + newLineHasFloatRight ? "true" : "false", + y, height, effOofRef, lastOofRef, firstWordOfLine); + } } } |