Browse Source

Code cleanup:

- reduce code duplication in getNextKnuthElements()
- removed references to experimental BlockStackingLM.bpUnit
- changed silly private method label
- various fixups


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067665 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Andreas L. Delmelle 13 years ago
parent
commit
72e24a8ee9
1 changed files with 137 additions and 422 deletions
  1. 137
    422
      src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java

+ 137
- 422
src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java View File

import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Stack; import java.util.Stack;


import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.KeepProperty;
import org.apache.fop.traits.MinOptMax; import org.apache.fop.traits.MinOptMax;
import org.apache.fop.traits.SpaceVal; import org.apache.fop.traits.SpaceVal;
import org.apache.fop.util.ListUtil;


/** /**
* LayoutManager for a block-container FO. * LayoutManager for a block-container FO.
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public void initialize() { public void initialize() {
abProps = getBlockContainerFO().getCommonAbsolutePosition(); abProps = getBlockContainerFO().getCommonAbsolutePosition();
foBlockSpaceBefore = new SpaceVal(getBlockContainerFO().getCommonMarginBlock() foBlockSpaceBefore = new SpaceVal(getBlockContainerFO().getCommonMarginBlock()
.getOptimum(this).getLength(); .getOptimum(this).getLength();
} }


bpUnit = 0; //layoutProps.blockProgressionUnit;
if (bpUnit == 0) {
// use optimum space values
adjustedSpaceBefore = getBlockContainerFO().getCommonMarginBlock()
.spaceBefore.getSpace().getOptimum(this).getLength().getValue(this);
adjustedSpaceAfter = getBlockContainerFO().getCommonMarginBlock()
.spaceAfter.getSpace().getOptimum(this).getLength().getValue(this);
} else {
// use minimum space values
adjustedSpaceBefore = getBlockContainerFO().getCommonMarginBlock()
.spaceBefore.getSpace().getMinimum(this).getLength().getValue(this);
adjustedSpaceAfter = getBlockContainerFO().getCommonMarginBlock()
.spaceAfter.getSpace().getMinimum(this).getLength().getValue(this);
}
// use optimum space values
adjustedSpaceBefore = getBlockContainerFO().getCommonMarginBlock()
.spaceBefore.getSpace().getOptimum(this).getLength().getValue(this);
adjustedSpaceAfter = getBlockContainerFO().getCommonMarginBlock()
.spaceAfter.getSpace().getOptimum(this).getLength().getValue(this);
} }


private void resetSpaces() { private void resetSpaces() {
} }


private boolean isAbsoluteOrFixed() { private boolean isAbsoluteOrFixed() {
return (abProps.absolutePosition == EN_ABSOLUTE)
|| (abProps.absolutePosition == EN_FIXED);
return (abProps.absolutePosition == EN_ABSOLUTE
|| abProps.absolutePosition == EN_FIXED);
} }


private boolean isFixed() { private boolean isFixed() {
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public int getContentAreaBPD() { public int getContentAreaBPD() {
if (autoHeight) { if (autoHeight) {
return -1; return -1;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public List getNextKnuthElements(LayoutContext context, int alignment) {
return getNextKnuthElements(context, alignment, null, null, null);
}

/** {@inheritDoc} */
@Override
public List getNextKnuthElements // CSOK: MethodLength public List getNextKnuthElements // CSOK: MethodLength
(LayoutContext context, int alignment) {
(LayoutContext context, int alignment, Stack lmStack,
Position restartPosition, LayoutManager restartAtLM) {
boolean isRestart = (lmStack != null);
resetSpaces(); resetSpaces();
if (isAbsoluteOrFixed()) { if (isAbsoluteOrFixed()) {
return getNextKnuthElementsAbsolute(context, alignment);
return getNextKnuthElementsAbsolute(context);
} }


autoHeight = false; autoHeight = false;


MinOptMax stackLimit = MinOptMax.getInstance(relDims.bpd); MinOptMax stackLimit = MinOptMax.getInstance(relDims.bpd);


List returnedList;
List contentList = new LinkedList();
List returnList = new LinkedList();
List<ListElement> returnedList;
List<ListElement> contentList = new LinkedList<ListElement>();
List<ListElement> returnList = new LinkedList<ListElement>();


if (!breakBeforeServed) { if (!breakBeforeServed) {
breakBeforeServed = true; breakBeforeServed = true;
//Spaces, border and padding to be repeated at each break //Spaces, border and padding to be repeated at each break
addPendingMarks(context); addPendingMarks(context);


LayoutManager curLM; // currently active LM
LayoutManager curLM = null; // currently active LM
LayoutManager prevLM = null; // previously active LM LayoutManager prevLM = null; // previously active LM

LayoutContext childLC = new LayoutContext(0);
if (isRestart) {
if (lmStack.isEmpty()) {
assert restartAtLM != null && restartAtLM.getParent() == this;
curLM = restartAtLM;
curLM.reset();
setCurrentChildLM(curLM);

childLC.copyPendingMarksFrom(context);
childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
childLC.setRefIPD(relDims.ipd);
childLC.setWritingMode(getBlockContainerFO().getWritingMode());
if (curLM == this.childLMs.get(0)) {
childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
//Handled already by the parent (break collapsing, see above)
}

// get elements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment);
} else {
curLM = (LayoutManager) lmStack.pop();
setCurrentChildLM(curLM);

childLC.copyPendingMarksFrom(context);
childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
childLC.setRefIPD(relDims.ipd);
childLC.setWritingMode(getBlockContainerFO().getWritingMode());
if (curLM == this.childLMs.get(0)) {
childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
//Handled already by the parent (break collapsing, see above)
}

// get elements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment, lmStack,
restartPosition, restartAtLM);
}
if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
childLC.clearKeepWithPreviousPending();
}
if (returnedList.size() == 1
&& ElementListUtils.startsWithForcedBreak(returnedList)) {
// a descendant of this block has break-before
contentList.addAll(returnedList);

// "wrap" the Position inside each element
// moving the elements from contentList to returnList
wrapPositionElements(contentList, returnList);

return returnList;
} else {
if (prevLM != null) {
// there is a block handled by prevLM
// before the one handled by curLM
addInBetweenBreak(contentList, context, childLC);
}
contentList.addAll(returnedList);
if (!returnedList.isEmpty()) {
if (ElementListUtils.endsWithForcedBreak(returnedList)) {
// a descendant of this block has break-after
if (curLM.isFinished() && !hasNextChildLM()) {
// there is no other content in this block;
// it's useless to add space after before a page break
setFinished(true);
}

wrapPositionElements(contentList, returnList);

return returnList;
}
}
}
}

// propagate and clear
context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
childLC.clearKeepsPending();
prevLM = curLM;

while ((curLM = getChildLM()) != null) { while ((curLM = getChildLM()) != null) {
LayoutContext childLC = new LayoutContext(0);
curLM.reset();
childLC = new LayoutContext(0);
childLC.copyPendingMarksFrom(context); childLC.copyPendingMarksFrom(context);
// curLM is a ? // curLM is a ?
childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit)); childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
childLC.clearKeepWithPreviousPending(); childLC.clearKeepWithPreviousPending();
} }
if (returnedList.size() == 1 if (returnedList.size() == 1
&& ((ListElement)returnedList.get(0)).isForcedBreak()) {
&& ElementListUtils.startsWithForcedBreak(returnedList)) {
// a descendant of this block has break-before // a descendant of this block has break-before
/*
if (returnList.size() == 0) {
// the first child (or its first child ...) has
// break-before;
// all this block, including space before, will be put in
// the
// following page
bSpaceBeforeServed = false;
}*/
contentList.addAll(returnedList); contentList.addAll(returnedList);


// "wrap" the Position inside each element // "wrap" the Position inside each element
// moving the elements from contentList to returnList // moving the elements from contentList to returnList
returnedList = new LinkedList();
wrapPositionElements(contentList, returnList); wrapPositionElements(contentList, returnList);


return returnList; return returnList;
setFinished(true); setFinished(true);
} }


returnedList = new LinkedList();
wrapPositionElements(contentList, returnList); wrapPositionElements(contentList, returnList);


return returnList; return returnList;
prevLM = curLM; prevLM = curLM;
} }


returnedList = new LinkedList();
wrapPositionElements(contentList, returnList); wrapPositionElements(contentList, returnList);


} else { } else {
returnList.add(refactoredBecauseOfDuplicateCode(contentRectOffsetX,
contentRectOffsetY));
returnList.add(generateNonInlinedBox(contentRectOffsetX, contentRectOffsetY));
} }
addKnuthElementsForBorderPaddingAfter(returnList, true); addKnuthElementsForBorderPaddingAfter(returnList, true);
addKnuthElementsForSpaceAfter(returnList, alignment); addKnuthElementsForSpaceAfter(returnList, alignment);
return returnList; return returnList;
} }


private KnuthBox refactoredBecauseOfDuplicateCode(double contentRectOffsetX,
double contentRectOffsetY) {
private KnuthBox generateNonInlinedBox(double contentRectOffsetX,
double contentRectOffsetY) {


MinOptMax range = MinOptMax.getInstance(relDims.ipd); MinOptMax range = MinOptMax.getInstance(relDims.ipd);
BlockContainerBreaker breaker = new BlockContainerBreaker(this, range); BlockContainerBreaker breaker = new BlockContainerBreaker(this, range);
KnuthBox knuthBox = new KnuthBox(vpContentBPD, notifyPos(bcPosition), false); KnuthBox knuthBox = new KnuthBox(vpContentBPD, notifyPos(bcPosition), false);
//TODO Handle min/opt/max for block-progression-dimension //TODO Handle min/opt/max for block-progression-dimension
/* These two elements will be used to add stretchability to the above box /* These two elements will be used to add stretchability to the above box
returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE,
false, returnPosition, false));
returnList.add(new KnuthGlue(0, 1 * constantLineHeight, 0,
LINE_NUMBER_ADJUSTMENT, returnPosition, false));
*/
returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE,
false, returnPosition, false));
returnList.add(new KnuthGlue(0, 1 * constantLineHeight, 0,
LINE_NUMBER_ADJUSTMENT, returnPosition, false));
*/


if (contentOverflows) { if (contentOverflows) {
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get( BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
public List getNextKnuthElements // CSOK: MethodLength
(LayoutContext context, int alignment, Stack lmStack,
Position restartPosition, LayoutManager restartAtLM) {
resetSpaces();
if (isAbsoluteOrFixed()) {
return getNextKnuthElementsAbsolute(context, alignment);
}

autoHeight = false;
//boolean rotated = (getBlockContainerFO().getReferenceOrientation() % 180 != 0);
int maxbpd = context.getStackLimitBP().getOpt();
int allocBPD;
if (height.getEnum() == EN_AUTO
|| (!height.isAbsolute() && getAncestorBlockAreaBPD() <= 0)) {
//auto height when height="auto" or "if that dimension is not specified explicitly
//(i.e., it depends on content's block-progression-dimension)" (XSL 1.0, 7.14.1)
allocBPD = maxbpd;
autoHeight = true;
if (getBlockContainerFO().getReferenceOrientation() == 0) {
//Cannot easily inline element list when ref-or="180"
inlineElementList = true;
}
} else {
allocBPD = height.getValue(this); //this is the content-height
allocBPD += getBPIndents();
}
vpContentBPD = allocBPD - getBPIndents();

referenceIPD = context.getRefIPD();
if (width.getEnum() == EN_AUTO) {
updateContentAreaIPDwithOverconstrainedAdjust();
} else {
int contentWidth = width.getValue(this);
updateContentAreaIPDwithOverconstrainedAdjust(contentWidth);
}

double contentRectOffsetX = 0;
contentRectOffsetX += getBlockContainerFO()
.getCommonMarginBlock().startIndent.getValue(this);
double contentRectOffsetY = 0;
contentRectOffsetY += getBlockContainerFO()
.getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
contentRectOffsetY += getBlockContainerFO()
.getCommonBorderPaddingBackground().getPaddingBefore(false, this);

updateRelDims(contentRectOffsetX, contentRectOffsetY, autoHeight);

int availableIPD = referenceIPD - getIPIndents();
if (getContentAreaIPD() > availableIPD) {
BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
getBlockContainerFO().getUserAgent().getEventBroadcaster());
eventProducer.objectTooWide(this, getBlockContainerFO().getName(),
getContentAreaIPD(), context.getRefIPD(),
getBlockContainerFO().getLocator());
}

MinOptMax stackLimit = MinOptMax.getInstance(relDims.bpd);

List returnedList;
List contentList = new LinkedList();
List returnList = new LinkedList();

if (!breakBeforeServed) {
breakBeforeServed = true;
if (!context.suppressBreakBefore()) {
if (addKnuthElementsForBreakBefore(returnList, context)) {
return returnList;
}
}
}

if (!firstVisibleMarkServed) {
addKnuthElementsForSpaceBefore(returnList, alignment);
context.updateKeepWithPreviousPending(getKeepWithPrevious());
}

addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
firstVisibleMarkServed = true;

if (autoHeight && inlineElementList) {
//Spaces, border and padding to be repeated at each break
addPendingMarks(context);

BlockLevelLayoutManager curLM; // currently active LM
BlockLevelLayoutManager prevLM = null; // previously active LM

LayoutContext childLC = new LayoutContext(0);
if (lmStack.isEmpty()) {
assert restartAtLM != null && restartAtLM.getParent() == this;
curLM = (BlockLevelLayoutManager) restartAtLM;
curLM.reset();
setCurrentChildLM(curLM);

childLC.copyPendingMarksFrom(context);
childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
childLC.setRefIPD(relDims.ipd);
childLC.setWritingMode(getBlockContainerFO().getWritingMode());
if (curLM == this.childLMs.get(0)) {
childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
//Handled already by the parent (break collapsing, see above)
}

// get elements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment);
} else {
curLM = (BlockLevelLayoutManager) lmStack.pop();
setCurrentChildLM(curLM);

childLC.copyPendingMarksFrom(context);
childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
childLC.setRefIPD(relDims.ipd);
childLC.setWritingMode(getBlockContainerFO().getWritingMode());
if (curLM == this.childLMs.get(0)) {
childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
//Handled already by the parent (break collapsing, see above)
}

// get elements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment, lmStack,
restartPosition, restartAtLM);
}
if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
childLC.clearKeepWithPreviousPending();
}
if (returnedList.size() == 1
&& ((ListElement)returnedList.get(0)).isForcedBreak()) {
// a descendant of this block has break-before
/*
if (returnList.size() == 0) {
// the first child (or its first child ...) has
// break-before;
// all this block, including space before, will be put in
// the
// following page
bSpaceBeforeServed = false;
}*/
contentList.addAll(returnedList);

// "wrap" the Position inside each element
// moving the elements from contentList to returnList
returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);

return returnList;
} else {
if (prevLM != null) {
// there is a block handled by prevLM
// before the one handled by curLM
addInBetweenBreak(contentList, context, childLC);
}
contentList.addAll(returnedList);
if (!returnedList.isEmpty()) {
if (((ListElement) ListUtil.getLast(returnedList))
.isForcedBreak()) {
// a descendant of this block has break-after
if (curLM.isFinished()) {
// there is no other content in this block;
// it's useless to add space after before a page break
setFinished(true);
}

returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);

return returnList;
}
}
}
// propagate and clear
context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
childLC.clearKeepsPending();
prevLM = curLM;

while ((curLM = (BlockLevelLayoutManager) getChildLM()) != null) {
curLM.reset();
childLC = new LayoutContext(0);
childLC.copyPendingMarksFrom(context);
// curLM is a ?
childLC.setStackLimitBP(context.getStackLimitBP().minus(stackLimit));
childLC.setRefIPD(relDims.ipd);
childLC.setWritingMode(getBlockContainerFO().getWritingMode());
if (curLM == this.childLMs.get(0)) {
childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE);
//Handled already by the parent (break collapsing, see above)
}

// get elements from curLM
returnedList = curLM.getNextKnuthElements(childLC, alignment);
if (contentList.isEmpty() && childLC.isKeepWithPreviousPending()) {
//Propagate keep-with-previous up from the first child
context.updateKeepWithPreviousPending(childLC.getKeepWithPreviousPending());
childLC.clearKeepWithPreviousPending();
}
if (returnedList.size() == 1
&& ((ListElement)returnedList.get(0)).isForcedBreak()) {
// a descendant of this block has break-before
/*
if (returnList.size() == 0) {
// the first child (or its first child ...) has
// break-before;
// all this block, including space before, will be put in
// the
// following page
bSpaceBeforeServed = false;
}*/
contentList.addAll(returnedList);

// "wrap" the Position inside each element
// moving the elements from contentList to returnList
returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);

return returnList;
} else {
if (prevLM != null) {
// there is a block handled by prevLM
// before the one handled by curLM
addInBetweenBreak(contentList, context, childLC);
}
contentList.addAll(returnedList);
if (returnedList.isEmpty()) {
//Avoid NoSuchElementException below (happens with empty blocks)
continue;
}
if (((ListElement) ListUtil.getLast(returnedList))
.isForcedBreak()) {
// a descendant of this block has break-after
if (curLM.isFinished()) {
// there is no other content in this block;
// it's useless to add space after before a page break
setFinished(true);
}

returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);

return returnList;
}
}
// propagate and clear
context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
childLC.clearKeepsPending();
prevLM = curLM;
}

returnedList = new LinkedList();
wrapPositionElements(contentList, returnList);

} else {
returnList.add(refactoredBecauseOfDuplicateCode(contentRectOffsetX,
contentRectOffsetY));
}
addKnuthElementsForBorderPaddingAfter(returnList, true);
addKnuthElementsForSpaceAfter(returnList, alignment);

//All child content is processed. Only break-after can occur now, so...
context.clearPendingMarks();
addKnuthElementsForBreakAfter(returnList, context);

context.updateKeepWithNextPending(getKeepWithNext());

setFinished(true);
return returnList;
}

/** {@inheritDoc} */
@Override
public boolean isRestartable() { public boolean isRestartable() {
return true; return true;
} }


private List getNextKnuthElementsAbsolute(LayoutContext context, int alignment) {
private List getNextKnuthElementsAbsolute(LayoutContext context) {
autoHeight = false; autoHeight = false;


boolean bpDirectionChanges = blockProgressionDirectionChanges(); boolean bpDirectionChanges = blockProgressionDirectionChanges();
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
public void addAreas // CSOK: MethodLength
(PositionIterator parentIter, LayoutContext layoutContext) {
@Override
public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
getParentArea(null); getParentArea(null);


// if this will create the first block area in a page // if this will create the first block area in a page


// "unwrap" the NonLeafPositions stored in parentIter // "unwrap" the NonLeafPositions stored in parentIter
// and put them in a new list; // and put them in a new list;
List positionList = new LinkedList();
List<Position> positionList = new LinkedList<Position>();
Position pos; Position pos;
boolean bSpaceBefore = false;
boolean bSpaceAfter = false;
Position firstPos = null; Position firstPos = null;
Position lastPos = null; Position lastPos = null;
while (parentIter.hasNext()) { while (parentIter.hasNext()) {
pos = (Position) parentIter.next();
pos = parentIter.next();
if (pos.getIndex() >= 0) { if (pos.getIndex() >= 0) {
if (firstPos == null) { if (firstPos == null) {
firstPos = pos; firstPos = pos;
//Add child areas inside the reference area //Add child areas inside the reference area
//bcpos.getBreaker().addContainedAreas(); //bcpos.getBreaker().addContainedAreas();
} else if (innerPosition == null) { } else if (innerPosition == null) {
if (pos instanceof NonLeafPosition) {
// pos was created by this BCLM and was inside an element
// representing space before or after
// this means the space was not discarded
if (positionList.isEmpty() && bcpos == null) {
// pos was in the element representing space-before
bSpaceBefore = true;
} else {
// pos was in the element representing space-after
bSpaceAfter = true;
}
} else {
//ignore (probably a Position for a simple penalty between blocks)
}
//ignore (probably a Position for a simple penalty between blocks)
} else if (innerPosition.getLM() == this } else if (innerPosition.getLM() == this
&& !(innerPosition instanceof MappingPosition)) { && !(innerPosition instanceof MappingPosition)) {
// pos was created by this BlockLM and was inside a penalty // pos was created by this BlockLM and was inside a penalty
addMarkersToPage(true, isFirst(firstPos), isLast(lastPos)); addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));


if (bcpos == null) { if (bcpos == null) {
if (bpUnit == 0) {
// the Positions in positionList were inside the elements
// created by the LineLM
childPosIter = new StackingIter(positionList.listIterator());
} else {
// the Positions in positionList were inside the elements
// created by the BCLM in the createUnitElements() method
//if (((Position) positionList.getLast()) instanceof
// LeafPosition) {
// // the last item inside positionList is a LeafPosition
// // (a LineBreakPosition, more precisely); this means that
// // the whole paragraph is on the same page
// childPosIter = new KnuthPossPosIter(storedList, 0,
// storedList.size());
//} else {
// // the last item inside positionList is a Position;
// // this means that the paragraph has been split
// // between consecutive pages
List splitList = new LinkedList();
int splitLength = 0;
int iFirst = ((MappingPosition) positionList.get(0))
.getFirstIndex();
int iLast = ((MappingPosition) ListUtil.getLast(positionList))
.getLastIndex();
// copy from storedList to splitList all the elements from
// iFirst to iLast
ListIterator storedListIterator = storedList.listIterator(iFirst);
while (storedListIterator.nextIndex() <= iLast) {
KnuthElement element = (KnuthElement) storedListIterator
.next();
// some elements in storedList (i.e. penalty items) were created
// by this BlockLM, and must be ignored
if (element.getLayoutManager() != this) {
splitList.add(element);
splitLength += element.getWidth();
lastLM = element.getLayoutManager();
}
}
//log.debug("Adding areas from " + iFirst + " to " + iLast);
//log.debug("splitLength= " + splitLength
// + " (" + neededUnits(splitLength) + " units') "
// + (neededUnits(splitLength) * bpUnit - splitLength)
// + " spacing");
// add space before and / or after the paragraph
// to reach a multiple of bpUnit
if (bSpaceBefore && bSpaceAfter) {
foBlockSpaceBefore = new SpaceVal(getBlockContainerFO()
.getCommonMarginBlock().spaceBefore, this).getSpace();
foBlockSpaceAfter = new SpaceVal(getBlockContainerFO()
.getCommonMarginBlock().spaceAfter, this).getSpace();
adjustedSpaceBefore = (neededUnits(splitLength
+ foBlockSpaceBefore.getMin()
+ foBlockSpaceAfter.getMin())
* bpUnit - splitLength) / 2;
adjustedSpaceAfter = neededUnits(splitLength
+ foBlockSpaceBefore.getMin()
+ foBlockSpaceAfter.getMin())
* bpUnit - splitLength - adjustedSpaceBefore;
} else if (bSpaceBefore) {
adjustedSpaceBefore = neededUnits(splitLength
+ foBlockSpaceBefore.getMin())
* bpUnit - splitLength;
} else {
adjustedSpaceAfter = neededUnits(splitLength
+ foBlockSpaceAfter.getMin())
* bpUnit - splitLength;
}
//log.debug("space before = " + adjustedSpaceBefore
// + " space after = " + adjustedSpaceAfter + " total = " +
// (adjustedSpaceBefore + adjustedSpaceAfter + splitLength));
childPosIter = new KnuthPossPosIter(splitList, 0, splitList
.size());
//}
}
// the Positions in positionList were inside the elements
// created by the LineLM
childPosIter = new StackingIter(positionList.listIterator());


while ((childLM = childPosIter.getNextChildLM()) != null) { while ((childLM = childPosIter.getNextChildLM()) != null) {
// set last area flag // set last area flag
lc.setFlags(LayoutContext.LAST_AREA, lc.setFlags(LayoutContext.LAST_AREA,
(layoutContext.isLastArea() && childLM == lastLM)); (layoutContext.isLastArea() && childLM == lastLM));
/*LF*/lc.setStackLimitBP(layoutContext.getStackLimitBP());
lc.setStackLimitBP(layoutContext.getStackLimitBP());
// Add the line areas to Area // Add the line areas to Area
childLM.addAreas(childPosIter, lc); childLM.addAreas(childPosIter, lc);
} }
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public Area getParentArea(Area childArea) { public Area getParentArea(Area childArea) {
if (referenceArea == null) { if (referenceArea == null) {
boolean switchedProgressionDirection = blockProgressionDirectionChanges(); boolean switchedProgressionDirection = blockProgressionDirectionChanges();
TraitSetter.addPadding(viewportBlockArea, TraitSetter.addPadding(viewportBlockArea,
getBlockContainerFO().getCommonBorderPaddingBackground(), getBlockContainerFO().getCommonBorderPaddingBackground(),
discardPaddingBefore, discardPaddingAfter, false, false, this); discardPaddingBefore, discardPaddingAfter, false, false, this);
// TraitSetter.addBackground(viewportBlockArea,
// getBlockContainerFO().getCommonBorderPaddingBackground(),
// this);
TraitSetter.addMargins(viewportBlockArea, TraitSetter.addMargins(viewportBlockArea,
getBlockContainerFO().getCommonBorderPaddingBackground(), getBlockContainerFO().getCommonBorderPaddingBackground(),
startIndent, endIndent, startIndent, endIndent,


viewportBlockArea.setCTM(absoluteCTM); viewportBlockArea.setCTM(absoluteCTM);
viewportBlockArea.setClip(needClip()); viewportBlockArea.setClip(needClip());
/*
if (getSpaceBefore() != 0) {
viewportBlockArea.addTrait(Trait.SPACE_BEFORE, new Integer(getSpaceBefore()));
}
if (foBlockSpaceAfter.opt != 0) {
viewportBlockArea.addTrait(Trait.SPACE_AFTER, new Integer(foBlockSpaceAfter.opt));
}*/


if (abProps.absolutePosition == EN_ABSOLUTE if (abProps.absolutePosition == EN_ABSOLUTE
|| abProps.absolutePosition == EN_FIXED) { || abProps.absolutePosition == EN_FIXED) {
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public void addChildArea(Area childArea) { public void addChildArea(Area childArea) {
if (referenceArea != null) { if (referenceArea != null) {
referenceArea.addBlock((Block) childArea); referenceArea.addBlock((Block) childArea);
* Force current area to be added to parent area. * Force current area to be added to parent area.
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
protected void flush() { protected void flush() {
viewportBlockArea.addBlock(referenceArea, autoHeight); viewportBlockArea.addBlock(referenceArea, autoHeight);


} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) { public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public void discardSpace(KnuthGlue spaceGlue) { public void discardSpace(KnuthGlue spaceGlue) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public KeepProperty getKeepTogetherProperty() { public KeepProperty getKeepTogetherProperty() {
return getBlockContainerFO().getKeepTogether(); return getBlockContainerFO().getKeepTogether();
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public KeepProperty getKeepWithPreviousProperty() { public KeepProperty getKeepWithPreviousProperty() {
return getBlockContainerFO().getKeepWithPrevious(); return getBlockContainerFO().getKeepWithPrevious();
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public KeepProperty getKeepWithNextProperty() { public KeepProperty getKeepWithNextProperty() {
return getBlockContainerFO().getKeepWithNext(); return getBlockContainerFO().getKeepWithNext();
} }
// --------- Property Resolution related functions --------- // // --------- Property Resolution related functions --------- //


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean getGeneratesReferenceArea() { public boolean getGeneratesReferenceArea() {
return true; return true;
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override
public boolean getGeneratesBlockArea() { public boolean getGeneratesBlockArea() {
return true; return true;
} }

Loading…
Cancel
Save