You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/05/18 17:25:52 UTC
cvs commit: xml-fop/src/java/org/apache/fop/layoutmgr/table Cell.java
jeremias 2005/05/18 08:25:52
Modified: src/java/org/apache/fop/layoutmgr FlowLayoutManager.java
src/java/org/apache/fop/layoutmgr/table Cell.java
Log:
Code cleanup.
Some style fixes.
Revision Changes Path
1.16 +32 -144 xml-fop/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
Index: FlowLayoutManager.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- FlowLayoutManager.java 17 May 2005 14:30:33 -0000 1.15
+++ FlowLayoutManager.java 18 May 2005 15:25:52 -0000 1.16
@@ -23,7 +23,6 @@
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;
@@ -33,39 +32,21 @@
* 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.
@@ -76,77 +57,6 @@
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
@@ -166,8 +76,7 @@
}
}
-
-//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());
@@ -215,16 +124,19 @@
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;
}
@@ -242,6 +154,9 @@
}
}
+ /**
+ * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
+ */
public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
log.debug(" FLM.negotiateBPDAdjustment> " + adj);
@@ -249,7 +164,8 @@
// 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;
@@ -258,6 +174,9 @@
}
}
+ /**
+ * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager
+ */
public void discardSpace(KnuthGlue spaceGlue) {
log.debug(" FLM.discardSpace> ");
@@ -270,18 +189,24 @@
}
}
+ /** @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;
@@ -316,15 +241,16 @@
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));
@@ -335,8 +261,8 @@
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
@@ -345,7 +271,8 @@
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);
}
@@ -358,45 +285,6 @@
*/
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();
}
@@ -426,8 +314,8 @@
} 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;
1.29 +3 -9 xml-fop/src/java/org/apache/fop/layoutmgr/table/Cell.java
Index: Cell.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/table/Cell.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Cell.java 17 May 2005 17:00:25 -0000 1.28
+++ Cell.java 18 May 2005 15:25:52 -0000 1.29
@@ -18,6 +18,9 @@
package org.apache.fop.layoutmgr.table;
+import java.util.LinkedList;
+import java.util.List;
+
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.flow.Table;
import org.apache.fop.fo.flow.TableCell;
@@ -37,10 +40,6 @@
import org.apache.fop.area.Trait;
import org.apache.fop.traits.MinOptMax;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
/**
* LayoutManager for a table-cell FO.
* A cell contains blocks. These blocks fill the cell.
@@ -52,13 +51,10 @@
private Block curBlockArea;
- private List childBreaks = new ArrayList();
-
private int inRowIPDOffset;
private int xoffset;
private int yoffset;
- private int referenceIPD;
private int cellIPD;
private int rowHeight;
private int usedBPD;
@@ -413,7 +409,6 @@
flush();
- childBreaks.clear();
curBlockArea = null;
}
@@ -489,7 +484,6 @@
public void resetPosition(Position resetPos) {
if (resetPos == null) {
reset(null);
- childBreaks.clear();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org