// at the beginning of the line
effectiveListIterator = effectiveList
.listIterator(startElementIndex);
+ KnuthElement firstElement;
while (effectiveListIterator.hasNext()
- && !((KnuthElement) effectiveListIterator.next())
+ && !(firstElement = (KnuthElement) effectiveListIterator.next())
.isBox()) {
+ if (firstElement.isGlue()) {
+ // discard the space representd by the glue element
+ ((BlockLevelLayoutManager) firstElement
+ .getLayoutManager())
+ .discardSpace((KnuthGlue) firstElement);
+ }
startElementIndex++;
}
log.debug(" addAreas from " + startElementIndex
+ " to " + endElementIndex);
childLC = new LayoutContext(0);
+ // set the space adjustment ratio
+ childLC.setSpaceAdjust(pbp.bpdAdjust);
// add space before if display-align is center or bottom
// add space after if display-align is distribute and
// this is not the last page
// Add the block areas to Area
lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
+ // set the space adjustment ratio
+ lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
// set space before for the first LM, in order to implement
// display-align = center or after
lc.setSpaceBefore((childLM == firstLM ? layoutContext.getSpaceBefore() : 0));
/** Iterator over the child layout managers. */
protected ListIterator proxyLMiter;
- /* holds the (one-time use) fo:block space-before
- and -after properties. Large fo:blocks are split
- into multiple Area.Blocks to accomodate the subsequent
- regions (pages) they are placed on. space-before
- is applied at the beginning of the first
- Block and space-after at the end of the last Block
- used in rendering the fo:block.
- */
- private MinOptMax foBlockSpaceBefore = null;
- private MinOptMax foBlockSpaceAfter = null;
-
private int lead = 12000;
private int lineHeight = 14000;
private int follow = 2000;
}
private void initialize() {
- foBlockSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
-/*LF*/ bpUnit = 0; //layoutProps.blockProgressionUnit;
-/*LF*/ if (bpUnit == 0) {
-/*LF*/ // use optimum space values
-/*LF*/ adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getOptimum().getLength().getValue();
-/*LF*/ adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getOptimum().getLength().getValue();
-/*LF*/ } else {
-/*LF*/ // use minimum space values
-/*LF*/ adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getMinimum().getLength().getValue();
-/*LF*/ adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getMinimum().getLength().getValue();
-/*LF*/ }
+ foSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
+ foSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
+ bpUnit = 0; // non-standard extension
+ if (bpUnit == 0) {
+ // use optimum space values
+ adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getOptimum().getLength().getValue();
+ adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getOptimum().getLength().getValue();
+ } else {
+ // use minimum space values
+ adjustedSpaceBefore = getBlockFO().getCommonMarginBlock().spaceBefore.getSpace().getMinimum().getLength().getValue();
+ adjustedSpaceAfter = getBlockFO().getCommonMarginBlock().spaceAfter.getSpace().getMinimum().getLength().getValue();
+ }
}
/**
getParentArea(null);
// if this will create the first block area in a page
- // and display-align is bottom or center, add space before
+ // and display-align is after or center, add space before
if (layoutContext.getSpaceBefore() > 0) {
addBlockSpacing(0.0, new MinOptMax(layoutContext.getSpaceBefore()));
}
// add space before and / or after the paragraph
// to reach a multiple of bpUnit
if (bSpaceBefore && bSpaceAfter) {
- foBlockSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
- foBlockSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
+ foSpaceBefore = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
+ foSpaceAfter = new SpaceVal(getBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
adjustedSpaceBefore = (neededUnits(splitLength
- + foBlockSpaceBefore.min
- + foBlockSpaceAfter.min)
+ + foSpaceBefore.min
+ + foSpaceAfter.min)
* bpUnit - splitLength) / 2;
adjustedSpaceAfter = neededUnits(splitLength
- + foBlockSpaceBefore.min
- + foBlockSpaceAfter.min)
+ + foSpaceBefore.min
+ + foSpaceAfter.min)
* bpUnit - splitLength - adjustedSpaceBefore;
} else if (bSpaceBefore) {
adjustedSpaceBefore = neededUnits(splitLength
- + foBlockSpaceBefore.min)
+ + foSpaceBefore.min)
* bpUnit - splitLength;
} else {
adjustedSpaceAfter = neededUnits(splitLength
- + foBlockSpaceAfter.min)
+ + foSpaceAfter.min)
* bpUnit - splitLength;
}
//System.out.println("spazio prima = " + adjustedSpaceBefore
childPosIter = new KnuthPossPosIter(splitList, 0, splitList
.size());
//}
- }
+ }
// if adjusted space before
- if (bSpaceBefore) {
- addBlockSpacing(0, new MinOptMax(adjustedSpaceBefore));
- }
+ double adjust = layoutContext.getSpaceAdjust();
+ addBlockSpacing(adjust, foSpaceBefore);
+ foSpaceBefore = null;
+ //if (bSpaceBefore) {
+ // addBlockSpacing(0, new MinOptMax(adjustedSpaceBefore));
+ //}
while ((childLM = childPosIter.getNextChildLM()) != null) {
// set last area flag
flush();
// if adjusted space after
- if (bSpaceAfter) {
- addBlockSpacing(0, new MinOptMax(adjustedSpaceAfter));
- }
+ addBlockSpacing(adjust, foSpaceAfter);
+ //if (bSpaceAfter) {
+ // addBlockSpacing(0, new MinOptMax(adjustedSpaceAfter));
+ //}
curBlockArea = null;
}
protected boolean bSpaceBeforeServed = false;
/** Reference IPD available */
protected int referenceIPD = 0;
-
+
+ /* holds the (one-time use) fo:block space-before
+ and -after properties. Large fo:blocks are split
+ into multiple Area.Blocks to accomodate the subsequent
+ regions (pages) they are placed on. space-before
+ is applied at the beginning of the first
+ Block and space-after at the end of the last Block
+ used in rendering the fo:block.
+ */
+ protected MinOptMax foSpaceBefore = null;
+ protected MinOptMax foSpaceAfter = null;
+
private int lastGeneratedPosition = -1;
private int smallestPosNumberChecked = Integer.MAX_VALUE;
}
public void discardSpace(KnuthGlue spaceGlue) {
-/*LF*/ //System.out.println(" BLM.discardSpace> " + spaceGlue.getPosition().getClass().getName());
+ //System.out.println(" BLM.discardSpace> " + spaceGlue.getPosition().getClass().getName());
Position innerPosition = ((NonLeafPosition) spaceGlue.getPosition()).getPosition();
-/*LF*/ if (innerPosition == null || innerPosition.getLM() == this) {
+ if (innerPosition == null || innerPosition.getLM() == this) {
// if this block has block-progression-unit > 0, innerPosition can be
// a MappingPosition
// spaceGlue represents space before or space after of this block
if (spaceGlue.getAdjustmentClass() == SPACE_BEFORE_ADJUSTMENT) {
// space-before must be discarded
adjustedSpaceBefore = 0;
+ foSpaceBefore = new MinOptMax(0);
} else {
// space-after must be discarded
adjustedSpaceAfter = 0;
+ foSpaceAfter = new MinOptMax(0);
//TODO Why are both cases handled in the same way?
}
-/*LF*/ } else {
+ } else {
// this element was not created by this BlockLM
NonLeafPosition savedPos = (NonLeafPosition)spaceGlue.getPosition();
spaceGlue.setPosition(innerPosition);
//int difference = (bestActiveNode.line < total) ? bestActiveNode.difference : bestActiveNode.difference + fillerMinWidth;
int difference = bestActiveNode.difference;
int blockAlignment = (bestActiveNode.line < total) ? alignment : alignmentLast;
- double ratio = (blockAlignment == org.apache.fop.fo.Constants.EN_JUSTIFY
- || bestActiveNode.adjustRatio < 0) ? bestActiveNode.adjustRatio : 0;
-
+ // it is always allowed to adjust space, so the ratio must be set regardless of
+ // the value of the property display-align; the ratio must be <= 1
+ double ratio = bestActiveNode.adjustRatio;
+ if (ratio < 0) {
+ // page break with a negative difference:
+ // spaces always have enough shrink
+ difference = 0;
+ } else if (ratio <= 1 && bestActiveNode.line < total) {
+ // not-last page break with a positive difference smaller than the available stretch:
+ // spaces can stretch to fill the whole difference
+ difference = 0;
+ } else if (ratio > 1) {
+ // not-last page with a positive difference greater than the available stretch
+ // spaces can stretch to fill the difference only partially
+ ratio = 1;
+ difference -= bestActiveNode.availableStretch;
+ } else {
+ // last page with a positive difference:
+ // spaces do not need to stretch
+ ratio = 0;
+ }
// compute the indexes of the first footnote list and the first element in that list
int firstListIndex = ((KnuthPageNode) bestActiveNode.previous).footnoteListIndex;
int firstElementIndex = ((KnuthPageNode) bestActiveNode.previous).footnoteElementIndex;
private Block curBlockArea;
//TODO space-before|after: handle space-resolution rules
- private MinOptMax spaceBefore;
- private MinOptMax spaceAfter;
private static class StackingIter extends PositionIterator {
StackingIter(Iterator parentIter) {
}
private void initialize() {
- spaceBefore = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
- spaceAfter = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
+ foSpaceBefore = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceBefore).getSpace();
+ foSpaceAfter = new SpaceVal(getListBlockFO().getCommonMarginBlock().spaceAfter).getSpace();
}
private int getIPIndents() {
public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) {
getParentArea(null);
-
+
+ // if this will create the first block area in a page
+ // and display-align is after or center, add space before
+ if (layoutContext.getSpaceBefore() > 0) {
+ addBlockSpacing(0.0, new MinOptMax(layoutContext.getSpaceBefore()));
+ }
+
// if adjusted space before
double adjust = layoutContext.getSpaceAdjust();
- addBlockSpacing(adjust, spaceBefore);
- spaceBefore = null;
+ addBlockSpacing(adjust, foSpaceBefore);
+ foSpaceBefore = null;
getPSLM().addIDToPage(getListBlockFO().getId());
StackingIter childPosIter = new StackingIter(positionList.listIterator());
while ((childLM = childPosIter.getNextChildLM()) != null) {
// Add the block areas to Area
+ // set the space adjustment ratio
+ lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
lc.setStackLimit(layoutContext.getStackLimit());
flush();
// if adjusted space after
- addBlockSpacing(adjust, spaceAfter);
+ addBlockSpacing(adjust, foSpaceAfter);
curBlockArea = null;
}
// Add the block areas to Area
lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
+ // set the space adjustment ratio
+ lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
lc.setStackLimit(layoutContext.getStackLimit());
childLM.addAreas(childPosIter, lc);
}
private int listItemHeight;
//TODO space-before|after: handle space-resolution rules
- private MinOptMax spaceBefore;
- private MinOptMax spaceAfter;
private boolean keepWithNextPendingOnLabel;
private boolean keepWithNextPendingOnBody;
}
private void initialize() {
- spaceBefore = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceBefore).getSpace();
- spaceAfter = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceAfter).getSpace();
+ foSpaceBefore = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceBefore).getSpace();
+ foSpaceAfter = new SpaceVal(getListItemFO().getCommonMarginBlock().spaceAfter).getSpace();
}
private int getIPIndents() {
// if adjusted space before
double adjust = layoutContext.getSpaceAdjust();
- addBlockSpacing(adjust, spaceBefore);
- spaceBefore = null;
+ addBlockSpacing(adjust, foSpaceBefore);
+ foSpaceBefore = null;
getPSLM().addIDToPage(getListItemFO().getId());
labelFirstIndex, labelLastIndex + 1);
lc.setFlags(LayoutContext.FIRST_AREA, layoutContext.isFirstArea());
lc.setFlags(LayoutContext.LAST_AREA, layoutContext.isLastArea());
+ // set the space adjustment ratio
+ lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
// TO DO: use the right stack limit for the label
lc.setStackLimit(layoutContext.getStackLimit());
label.addAreas(labelIter, lc);
bodyFirstIndex, bodyLastIndex + 1);
lc.setFlags(LayoutContext.FIRST_AREA, layoutContext.isFirstArea());
lc.setFlags(LayoutContext.LAST_AREA, layoutContext.isLastArea());
+ // set the space adjustment ratio
+ lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
// TO DO: use the right stack limit for the body
lc.setStackLimit(layoutContext.getStackLimit());
body.addAreas(bodyIter, lc);
flush();
// if adjusted space after
- addBlockSpacing(adjust, spaceAfter);
+ addBlockSpacing(adjust, foSpaceAfter);
curBlockArea = null;
}