Skip to content

Commit

Permalink
Merge pull request #296 from andreacampi/issue-290-rebased
Browse files Browse the repository at this point in the history
[#290] When looking for the next block for keepwithnext we need to exclude fallback content for figures that have already been placed.
  • Loading branch information
Andrea Campi committed Aug 25, 2012
2 parents 435eaaf + 4780398 commit cbe091d
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/layout/page.js
Expand Up @@ -382,6 +382,7 @@ goog.scope(function() {
block = content.blocks[br.index],
nextSibling,
nextNonChild,
nextNotUsed,
parent, closeTags = [],
effectiveBlockHeight,
finishColumn = false,
Expand Down Expand Up @@ -434,6 +435,7 @@ goog.scope(function() {
block = content.blocks[br.index];
nextSibling = block.nextSibling;
nextNonChild = nextSibling || block.getNextNonChildBlock();
nextNotUsed = nextSibling && Page.nextNotUsedBlock(content, br, nextSibling, blockCount);

// First, we must check if this block is a figure's fallback content.
// If so, then we must see if the figure has been used
Expand Down Expand Up @@ -506,7 +508,7 @@ goog.scope(function() {
// Note that keepwithnext is ignored if there is no next sibling, or if the
// block was already broken (has overhang) -- or if this is the isFirstBlock
// in a non-short column
if (!finishColumn && block.keepwithnext && nextSibling &&
if (!finishColumn && block.keepwithnext && nextNotUsed &&
!(br.overhang || (isFirstBlock && !shortColumn))) {
// Keepwithnext means that we must attempt to keep this block in the same
// column/page as it's next sibling. However, the current block can still
Expand All @@ -524,7 +526,7 @@ goog.scope(function() {
// out if we need to end the column early
finishColumn = (remainingHeight >= effectiveBlockHeight) &&
(remainingHeight <
(effectiveBlockHeight + marginBottom + nextSibling.firstLine));
(effectiveBlockHeight + marginBottom + nextNotUsed.firstLine));

if (finishColumn) {
debug.info('Leaving column due to keepwithnext');
Expand Down Expand Up @@ -883,6 +885,24 @@ goog.scope(function() {
}
};

/**
* @param {!treesaver.layout.Content} content
* @param {!treesaver.layout.BreakRecord} br
* @param {!treesaver.layout.Block} nextBlock
* @param {number} blockCount
*/
Page.nextNotUsedBlock = function(content, br, nextBlock, blockCount) {
var index,
block;
for (index = nextBlock.index; index < blockCount; index++) {
block = content.blocks[index];
if (!block.isFallback || !br.figureUsed(block.figure.figureIndex)) {
return block;
}
}
return null;
};

/**
* Compute overhang
* @param {!treesaver.layout.BreakRecord} br The lastBlock inserted into the column
Expand Down

0 comments on commit cbe091d

Please sign in to comment.