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 lf...@apache.org on 2005/04/07 18:20:44 UTC
cvs commit: xml-fop/src/java/org/apache/fop/layoutmgr/list ListBlockLayoutManager.java ListItemLayoutManager.java Item.java
lfurini 2005/04/07 09:20:44
Modified: src/java/org/apache/fop/layoutmgr/list Tag:
Temp_KnuthStylePageBreaking
ListBlockLayoutManager.java
ListItemLayoutManager.java Item.java
Log:
First working implementation for lists; at the moment, ListItemLM just uses the "body" elements; coming soon: creation of elements combining the label list and the body list.
Revision Changes Path
No revision
No revision
1.12.2.1 +48 -12 xml-fop/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
Index: ListBlockLayoutManager.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -r1.12 -r1.12.2.1
--- ListBlockLayoutManager.java 16 Mar 2005 23:18:43 -0000 1.12
+++ ListBlockLayoutManager.java 7 Apr 2005 16:20:44 -0000 1.12.2.1
@@ -27,6 +27,7 @@
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.BreakPossPosIter;
import org.apache.fop.layoutmgr.Position;
+import org.apache.fop.layoutmgr.NonLeafPosition;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
@@ -34,6 +35,8 @@
import org.apache.fop.traits.SpaceVal;
import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
/**
@@ -54,6 +57,20 @@
private MinOptMax spaceBefore;
private MinOptMax spaceAfter;
+ 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);
+ }
+ }
+
/*
private class SectionPosition extends LeafPosition {
protected List list;
@@ -64,7 +81,7 @@
}*/
/**
- * Create a new table layout manager.
+ * Create a new list block layout manager.
* @param node list-block to create the layout manager for
*/
public ListBlockLayoutManager(ListBlock node) {
@@ -166,6 +183,11 @@
return null;
}
+ public LinkedList getChangedKnuthElements(List oldList, int alignment) {
+ //log.debug("LBLM.getChangedKnuthElements>");
+ return super.getChangedKnuthElements(oldList, alignment);
+ }
+
/**
* The table area is a reference area that contains areas for
* columns, bodies, rows and the contents are in cells.
@@ -186,22 +208,36 @@
// the list block contains areas stacked from each list item
- //int listHeight = 0;
-
- LayoutManager childLM;
- int iStartPos = 0;
+ 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()) {
- LeafPosition lfp = (LeafPosition) parentIter.next();
- // Add the block areas to Area
- PositionIterator breakPosIter = new BreakPossPosIter(
- bodyBreaks, iStartPos, lfp.getLeafPos() + 1);
- iStartPos = lfp.getLeafPos() + 1;
- while ((childLM = (LayoutManager)breakPosIter.getNextChildLM()) != null) {
- childLM.addAreas(breakPosIter, lc);
+ pos = (Position)parentIter.next();
+ if (pos instanceof NonLeafPosition
+ && ((NonLeafPosition) pos).getPosition().getLM() != this) {
+ // pos was created by a child of this ListBlockLM
+ positionList.add(((NonLeafPosition) pos).getPosition());
+ lastLM = ((NonLeafPosition) pos).getPosition().getLM();
+ if (firstLM == null) {
+ firstLM = lastLM;
+ }
}
}
+ 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);
+ lc.setStackLimit(layoutContext.getStackLimit());
+ childLM.addAreas(childPosIter, lc);
+ }
flush();
1.19.2.1 +122 -12 xml-fop/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
Index: ListItemLayoutManager.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java,v
retrieving revision 1.19
retrieving revision 1.19.2.1
diff -u -r1.19 -r1.19.2.1
--- ListItemLayoutManager.java 16 Mar 2005 23:18:43 -0000 1.19
+++ ListItemLayoutManager.java 7 Apr 2005 16:20:44 -0000 1.19.2.1
@@ -29,7 +29,10 @@
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.BreakPossPosIter;
import org.apache.fop.layoutmgr.Position;
+import org.apache.fop.layoutmgr.NonLeafPosition;
import org.apache.fop.layoutmgr.TraitSetter;
+import org.apache.fop.layoutmgr.KnuthElement;
+import org.apache.fop.layoutmgr.KnuthPossPosIter;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
import org.apache.fop.traits.MinOptMax;
@@ -38,6 +41,8 @@
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
+import java.util.LinkedList;
+import java.util.ListIterator;
/**
* LayoutManager for a list-item FO.
@@ -53,6 +58,23 @@
private Block curBlockArea = null;
+ private LinkedList labelList = null;
+ private boolean labelAreasAdded = false;
+
+ 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);
+ }
+ }
+
//private List cellList = null;
private int listItemHeight;
@@ -226,6 +248,69 @@
return breakPoss;
}
+ public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
+ // label
+ labelList = label.getNextKnuthElements(context, alignment);
+
+ // body
+ LinkedList returnedList = body.getNextKnuthElements(context, alignment);
+
+ // "wrap" the Position inside each element
+ LinkedList tempList = returnedList;
+ KnuthElement tempElement;
+ returnedList = new LinkedList();
+ ListIterator listIter = tempList.listIterator();
+ while (listIter.hasNext()) {
+ tempElement = (KnuthElement)listIter.next();
+ tempElement.setPosition(new NonLeafPosition(this, tempElement.getPosition()));
+ returnedList.add(tempElement);
+ }
+
+ setFinished(true);
+ return returnedList;
+ }
+
+ public LinkedList getChangedKnuthElements(List oldList, int alignment) {
+/*LF*/ //log.debug(" LILM.getChanged> label");
+ // label
+ labelList = label.getChangedKnuthElements(labelList, alignment);
+
+/*LF*/ //log.debug(" LILM.getChanged> body");
+ // body
+ // "unwrap" the Positions stored in the elements
+ ListIterator oldListIterator = oldList.listIterator();
+ KnuthElement oldElement = null;
+ while (oldListIterator.hasNext()) {
+ oldElement = (KnuthElement)oldListIterator.next();
+ Position innerPosition = ((NonLeafPosition) oldElement.getPosition()).getPosition();
+/*LF*/ //System.out.println(" BLM> unwrapping: " + (oldElement.isBox() ? "box " : (oldElement.isGlue() ? "glue " : "penalty")) + " creato da " + oldElement.getLayoutManager().getClass().getName());
+/*LF*/ //System.out.println(" BLM> unwrapping: " + oldElement.getPosition().getClass().getName());
+ if (innerPosition != null) {
+ // oldElement was created by a descendant of this BlockLM
+ oldElement.setPosition(innerPosition);
+ } else {
+ // thisElement was created by this BlockLM
+ // modify its position in order to recognize it was not created
+ // by a child
+ oldElement.setPosition(new Position(this));
+ }
+ }
+
+ LinkedList returnedList = body.getChangedKnuthElements(oldList, alignment);
+ // "wrap" the Position inside each element
+ LinkedList tempList = returnedList;
+ KnuthElement tempElement;
+ returnedList = new LinkedList();
+ ListIterator listIter = tempList.listIterator();
+ while (listIter.hasNext()) {
+ tempElement = (KnuthElement)listIter.next();
+ tempElement.setPosition(new NonLeafPosition(this, tempElement.getPosition()));
+ returnedList.add(tempElement);
+ }
+
+ return returnedList;
+ }
+
/**
* Add the areas for the break points.
* This sets the offset of each cell as it is added.
@@ -244,24 +329,49 @@
addID(fobj.getId());
- Item childLM;
+ LayoutManager childLM = null;
LayoutContext lc = new LayoutContext(0);
- while (parentIter.hasNext()) {
- ItemPosition lfp = (ItemPosition) parentIter.next();
- // Add the block areas to Area
+ LayoutManager firstLM = null;
+ LayoutManager lastLM = null;
- for (Iterator iter = lfp.cellBreaks.iterator(); iter.hasNext();) {
- List cellsbr = (List)iter.next();
- PositionIterator breakPosIter;
- breakPosIter = new BreakPossPosIter(cellsbr, 0, cellsbr.size());
-
- while ((childLM = (Item)breakPosIter.getNextChildLM()) != null) {
- childLM.addAreas(breakPosIter, lc);
+ // create a new list;
+ // add the label areas, if this is the first time addAreas() is called
+ LinkedList positionList = new LinkedList();
+ if (!labelAreasAdded) {
+ KnuthPossPosIter labelPosIter = new KnuthPossPosIter(labelList, 0, labelList.size());
+ while (labelPosIter.hasNext()) {
+ positionList.add((Position) labelPosIter.next());
+ }
+ }
+ // "unwrap" the NonLeafPositions stored in parentIter
+ Position pos;
+ while (parentIter.hasNext()) {
+ pos = (Position) parentIter.next();
+ if (pos instanceof NonLeafPosition
+ && ((NonLeafPosition) pos).getPosition().getLM() != this) {
+ // pos was created by a child of this ListBlockLM
+ positionList.add(((NonLeafPosition) pos).getPosition());
+ lastLM = ((NonLeafPosition) pos).getPosition().getLM();
+ if (firstLM == null) {
+ firstLM = lastLM;
}
}
}
- curBlockArea.setBPD(listItemHeight);
+ 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);
+ // reset the area height after adding the label areas
+ if (!labelAreasAdded && childLM == firstLM) {
+ curBlockArea.setBPD(0);
+ labelAreasAdded = true;
+ }
+ /* questo non e' correttissimo, bisogna avere due diversi valori per la label e il body */
+ lc.setStackLimit(layoutContext.getStackLimit());
+ childLM.addAreas(childPosIter, lc);
+ }
flush();
1.12.2.1 +49 -10 xml-fop/src/java/org/apache/fop/layoutmgr/list/Item.java
Index: Item.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/list/Item.java,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -r1.12 -r1.12.2.1
--- Item.java 16 Mar 2005 23:18:43 -0000 1.12
+++ Item.java 7 Apr 2005 16:20:44 -0000 1.12.2.1
@@ -29,12 +29,15 @@
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.BreakPossPosIter;
import org.apache.fop.layoutmgr.Position;
+import org.apache.fop.layoutmgr.NonLeafPosition;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
import org.apache.fop.traits.MinOptMax;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.LinkedList;
/**
* LayoutManager for a table-cell FO.
@@ -50,6 +53,20 @@
private int xoffset;
private int itemIPD;
+ 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);
+ }
+ }
+
/**
* Create a new Cell layout manager.
*/
@@ -152,6 +169,11 @@
xoffset = off;
}
+ public LinkedList getChangedKnuthElements(List oldList, int alignment) {
+ //log.debug(" Item.getChanged>");
+ return super.getChangedKnuthElements(oldList, alignment);
+ }
+
/**
* Add the areas for the break points.
* The list item contains block stacking layout managers
@@ -171,21 +193,38 @@
addID(((ListItemBody) fobj).getId());
}
- LayoutManager childLM;
- int iStartPos = 0;
+ 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()) {
- LeafPosition lfp = (LeafPosition) parentIter.next();
- // Add the block areas to Area
- PositionIterator breakPosIter =
- new BreakPossPosIter(childBreaks, iStartPos,
- lfp.getLeafPos() + 1);
- iStartPos = lfp.getLeafPos() + 1;
- while ((childLM = breakPosIter.getNextChildLM()) != null) {
- childLM.addAreas(breakPosIter, lc);
+ pos = (Position)parentIter.next();
+ if (pos instanceof NonLeafPosition) {
+ // pos was created by a child of this ListBlockLM
+ positionList.add(((NonLeafPosition) pos).getPosition());
+ lastLM = ((NonLeafPosition) pos).getPosition().getLM();
+ if (firstLM == null) {
+ firstLM = lastLM;
+ }
+ } else {
+ // pos was created by this ListBlockLM, 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);
+ lc.setStackLimit(layoutContext.getStackLimit());
+ childLM.addAreas(childPosIter, lc);
+ }
+
/*
if (borderProps != null) {
TraitSetter.addBorders(curBlockArea, borderProps);
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org