import org.apache.fop.area.Area;
import org.apache.fop.area.BlockParent;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
* Its parent LM is the PageSequenceLayoutManager.
* This LM is responsible for getting columns of the appropriate size
* and filling them with block-level areas generated by its children.
+ * @todo Reintroduce emergency counter (generate error to avoid endless loop)
*/
public class FlowLayoutManager extends BlockStackingLayoutManager
implements BlockLevelLayoutManager {
private Flow fobj;
- /** List of break possibilities */
- protected List blockBreaks = new java.util.ArrayList();
-
/** Array of areas currently being filled stored by area class */
private BlockParent[] currentAreas = new BlockParent[Area.CLASS_MAX];
- private int iStartPos = 0;
-
/**
* Used to count the number of subsequent times to layout child areas on
* multiple pages.
*/
private int numSubsequentOverflows = 0;
- private static class StackingIter extends PositionIterator {
- StackingIter(Iterator parentIter) {
- super(parentIter);
- }
-
- protected LayoutManager getLM(Object nextObj) {
- return ((Position) nextObj).getLM();
- }
-
- protected Position getPos(Object nextObj) {
- return ((Position) nextObj);
- }
- }
-
/**
* This is the top level layout manager.
* It is created by the PageSequence FO.
fobj = node;
}
- /*
- public BreakPoss getNextBreakPoss(LayoutContext context) {
-
- // currently active LM
- LayoutManager curLM;
- MinOptMax stackSize = new MinOptMax();
-
- fobj.setLayoutDimension(PercentBase.BLOCK_IPD, context.getRefIPD());
- fobj.setLayoutDimension(PercentBase.BLOCK_BPD, context.getStackLimit().opt);
-
- while ((curLM = getChildLM()) != null) {
- if (curLM.generatesInlineAreas()) {
- log.error("inline area not allowed under flow - ignoring");
- curLM.setFinished(true);
- continue;
- }
-
- // Make break positions and return page break
- // Set up a LayoutContext
- MinOptMax bpd = context.getStackLimit();
- BreakPoss bp;
-
- LayoutContext childLC = new LayoutContext(0);
- boolean breakPage = false;
- childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
- childLC.setRefIPD(context.getRefIPD());
-
- if (!curLM.isFinished()) {
- if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
- stackSize.add(bp.getStackingSize());
- blockBreaks.add(bp);
- // set stackLimit for remaining space
- childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
-
- if (bp.isForcedBreak() || bp.nextBreakOverflows()) {
- if (log.isDebugEnabled()) {
- log.debug("BreakPoss signals " + (bp.isForcedBreak()
- ? "forced break" : "next break overflows"));
- }
- breakPage = true;
- }
- }
- }
-
- // check the stack bpd and if greater than available
- // height then go to the last best break and return
- // break position
- if (stackSize.opt > context.getStackLimit().opt) {
- breakPage = true;
- }
- if (breakPage) {
- numSubsequentOverflows++;
- if (numSubsequentOverflows > 50) {
- log.error("Content overflows available area. Giving up after 50 attempts.");
- setFinished(true);
- return null;
- }
- return new BreakPoss(
- new LeafPosition(this, blockBreaks.size() - 1));
- }
- numSubsequentOverflows = 0; //Reset emergency counter
- }
- setFinished(true);
- if (blockBreaks.size() > 0) {
- return new BreakPoss(
- new LeafPosition(this, blockBreaks.size() - 1));
- }
- return null;
- }*/
-
-
/**
* "wrap" the Position inside each element moving the elements from
* SourceList to targetList
}
}
-
-//TODO Reintroduce emergency counter (generate error to avoid endless loop)
+ /** @see org.apache.fop.layoutmgr.LayoutManager */
public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
// set layout dimensions
fobj.setLayoutDimension(PercentBase.BLOCK_IPD, context.getRefIPD());
if (prevLM.mustKeepWithNext()
|| curLM.mustKeepWithPrevious()) {
// add an infinite penalty to forbid a break between blocks
- returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, new Position(this), false));
+ returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false,
+ new Position(this), false));
} else if (!((KnuthElement) returnList.getLast()).isGlue()) {
// add a null penalty to allow a break between blocks
- returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
+ returnList.add(new KnuthPenalty(0, 0, false,
+ new Position(this), false));
}
}
if (returnedList.size() > 0) { // controllare!
returnList.addAll(returnedList);
if (((KnuthElement)returnedList.getLast()).isPenalty()
- && ((KnuthPenalty)returnedList.getLast()).getP() == -KnuthElement.INFINITE) {
+ && ((KnuthPenalty)returnedList.getLast()).getP()
+ == -KnuthElement.INFINITE) {
// a descendant of this flow has break-after
return returnList;
}
}
}
+ /**
+ * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
+ */
public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
log.debug(" FLM.negotiateBPDAdjustment> " + adj);
// this element was not created by this FlowLM
NonLeafPosition savedPos = (NonLeafPosition)lastElement.getPosition();
lastElement.setPosition(savedPos.getPosition());
- int returnValue = ((BlockLevelLayoutManager) lastElement.getLayoutManager()).negotiateBPDAdjustment(adj, lastElement);
+ int returnValue = ((BlockLevelLayoutManager)lastElement.getLayoutManager())
+ .negotiateBPDAdjustment(adj, lastElement);
lastElement.setPosition(savedPos);
log.debug(" FLM.negotiateBPDAdjustment> result " + returnValue);
return returnValue;
}
}
+ /**
+ * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
+ */
public void discardSpace(KnuthGlue spaceGlue) {
log.debug(" FLM.discardSpace> ");
}
}
+ /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepTogether() */
public boolean mustKeepTogether() {
return false;
}
+ /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithPrevious() */
public boolean mustKeepWithPrevious() {
return false;
}
+ /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithNext() */
public boolean mustKeepWithNext() {
return false;
}
+ /**
+ * @see org.apache.fop.layoutmgr.LayoutManager#getChangedKnuthElements(java.util.List, int)
+ */
public LinkedList getChangedKnuthElements(List oldList, /*int flaggedPenalty,*/ int alignment) {
ListIterator oldListIterator = oldList.listIterator();
KnuthElement returnedElement;
prevElement.getLayoutManager();
BlockLevelLayoutManager currLM = (BlockLevelLayoutManager)
currElement.getLayoutManager();
- returnedList.addAll(prevLM.getChangedKnuthElements(oldList.subList(fromIndex, oldListIterator.previousIndex()),
- /*flaggedPenalty,*/ alignment));
+ returnedList.addAll(prevLM.getChangedKnuthElements(
+ oldList.subList(fromIndex, oldListIterator.previousIndex()), alignment));
fromIndex = oldListIterator.previousIndex();
// there is another block after this one
if (prevLM.mustKeepWithNext()
|| currLM.mustKeepWithPrevious()) {
// add an infinite penalty to forbid a break between blocks
- returnedList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, new Position(this), false));
+ returnedList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false,
+ new Position(this), false));
} else if (!((KnuthElement) returnedList.getLast()).isGlue()) {
// add a null penalty to allow a break between blocks
returnedList.add(new KnuthPenalty(0, 0, false, new Position(this), false));
if (currElement != null) {
BlockLevelLayoutManager currLM = (BlockLevelLayoutManager)
currElement.getLayoutManager();
- returnedList.addAll(currLM.getChangedKnuthElements(oldList.subList(fromIndex, oldList.size()),
- /*flaggedPenalty,*/ alignment));
+ returnedList.addAll(currLM.getChangedKnuthElements(
+ oldList.subList(fromIndex, oldList.size()), alignment));
}
// "wrap" the Position stored in each element of returnedList
while (listIter.hasNext()) {
returnedElement = (KnuthElement)listIter.next();
if (returnedElement.getLayoutManager() != this) {
- returnedElement.setPosition(new NonLeafPosition(this, returnedElement.getPosition()));
+ returnedElement.setPosition(
+ new NonLeafPosition(this, returnedElement.getPosition()));
}
returnList.add(returnedElement);
}
*/
public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
AreaAdditionUtil.addAreas(parentIter, layoutContext);
- /*
- LayoutManager childLM = null;
- LayoutContext lc = new LayoutContext(0);
- LayoutManager firstLM = null;
- LayoutManager lastLM = null;
-
- // "unwrap" the NonLeafPositions stored in parentIter
- // and put them in a new list;
- LinkedList positionList = new LinkedList();
- Position pos;
- while (parentIter.hasNext()) {
- pos = (Position)parentIter.next();
- if (pos instanceof NonLeafPosition) {
- // pos was created by a child of this FlowLM
- positionList.add(((NonLeafPosition) pos).getPosition());
- lastLM = ((NonLeafPosition) pos).getPosition().getLM();
- if (firstLM == null) {
- firstLM = lastLM;
- }
- } else {
- // pos was created by this FlowLM, so it must be ignored
- }
- }
-
- StackingIter childPosIter = new StackingIter(positionList.listIterator());
- while ((childLM = childPosIter.getNextChildLM()) != null) {
- // Add the block areas to Area
- lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
- lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM);
- // set space before for the first LM, in order to implement
- // display-align = center or after
- lc.setSpaceBefore((childLM == firstLM ? layoutContext.getSpaceBefore() : 0));
- // set space after for each LM, in order to implement
- // display-align = distribute
- lc.setSpaceAfter(layoutContext.getSpaceAfter());
- lc.setStackLimit(layoutContext.getStackLimit());
- childLM.addAreas(childPosIter, lc);
- }*/
-
flush();
}
} else if (aclass == Area.CLASS_FOOTNOTE) {
parentArea = getCurrentPV().getBodyRegion().getFootnote();
} else {
- throw new IllegalStateException("(internal error) Invalid " +
- "area class (" + aclass + ") requested.");
+ throw new IllegalStateException("(internal error) Invalid "
+ + "area class (" + aclass + ") requested.");
}
this.currentAreas[aclass] = parentArea;