spepping 2004/08/26 13:58:31 Modified: src/java/org/apache/fop/area AreaTreeHandler.java src/java/org/apache/fop/fo FObjMixed.java src/java/org/apache/fop/layoutmgr LayoutManager.java AbstractLayoutManager.java BasicLinkLayoutManager.java BlockLayoutManager.java ContentLayoutManager.java InlineStackingLayoutManager.java LMiter.java LeaderLayoutManager.java LineLayoutManager.java Log: Moved some functionality from LMiter to the LayoutManagers. The LMs now hold the list of child LMs and the method preLoadNext. This makes it possible to create a new LMiter object for a LM, or even a list iterator over the list of child LMs if the latter is known to be complete. Revision Changes Path 1.5 +7 -9 xml-fop/src/java/org/apache/fop/area/AreaTreeHandler.java Index: AreaTreeHandler.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/AreaTreeHandler.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AreaTreeHandler.java 20 Aug 2004 09:38:21 -0000 1.4 +++ AreaTreeHandler.java 26 Aug 2004 20:58:30 -0000 1.5 @@ -432,20 +432,18 @@ * @return the Title area */ private org.apache.fop.area.Title getTitleArea(org.apache.fop.fo.pagination.Title foTitle) { - // use special layout manager to add the inline areas - // to the Title. - InlineStackingLayoutManager lm; - lm = new InlineStackingLayoutManager(foTitle); - lm.setLMiter(new LMiter(lm, foTitle.getChildNodes())); - lm.initialize(); - // get breaks then add areas to title org.apache.fop.area.Title title = new org.apache.fop.area.Title(); ContentLayoutManager clm = new ContentLayoutManager(title); clm.setUserAgent(foTitle.getUserAgent()); - lm.setParent(clm); + + // use special layout manager to add the inline areas + // to the Title. + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager(foTitle); + clm.addChildLM(lm); clm.fillArea(lm); 1.35 +0 -1 xml-fop/src/java/org/apache/fop/fo/FObjMixed.java Index: FObjMixed.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObjMixed.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- FObjMixed.java 22 Aug 2004 01:56:33 -0000 1.34 +++ FObjMixed.java 26 Aug 2004 20:58:30 -0000 1.35 @@ -75,7 +75,6 @@ if (getChildNodes() != null) { InlineStackingLayoutManager lm; lm = new InlineStackingLayoutManager(this); - lm.setLMiter(new LMiter(lm, getChildNodes())); list.add(lm); } } 1.10 +27 -0 xml-fop/src/java/org/apache/fop/layoutmgr/LayoutManager.java Index: LayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/LayoutManager.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- LayoutManager.java 13 Jul 2004 00:16:22 -0000 1.9 +++ LayoutManager.java 26 Aug 2004 20:58:30 -0000 1.10 @@ -18,6 +18,7 @@ package org.apache.fop.layoutmgr; +import java.util.List; import java.util.Map; import org.apache.fop.fo.flow.Marker; @@ -217,5 +218,31 @@ * @return the layout manaager of the retrieved marker if any */ Marker retrieveMarker(String name, int pos, int boundary); + + /** + * Load next child LMs, up to child LM index pos + * @param pos index up to which child LMs are requested + * @return if requested index does exist + */ + boolean preLoadNext(int pos); + + /** + * @return the list of child LMs + */ + List getChildLMs(); + + /** + * Add the LM in the argument to the list of child LMs; + * set this LM as the parent; + * initialize the LM. + * @param lm the LM to be added + */ + void addChildLM(LayoutManager lm); + + /** + * Add the LMs in the argument to the list of child LMs; + * @param newLMs the list of LMs to be added + */ + void addChildLMs(List newLMs); } 1.20 +76 -6 xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java Index: AbstractLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- AbstractLayoutManager.java 11 Aug 2004 22:56:48 -0000 1.19 +++ AbstractLayoutManager.java 26 Aug 2004 20:58:30 -0000 1.20 @@ -31,6 +31,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.List; +import java.util.ArrayList; import java.util.ListIterator; import java.util.Map; @@ -40,20 +42,24 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants { protected FOUserAgent userAgent; protected LayoutManager parentLM = null; + protected List childLMs = new ArrayList(10); protected FObj fobj; protected String foID = null; + protected ListIterator fobjIter = null; protected Map markers = null; /** True if this LayoutManager has handled all of its content. */ private boolean bFinished = false; - protected LayoutManager curChildLM = null; - protected ListIterator childLMiter; protected boolean bInited = false; + /** child LM and child LM iterator during getNextBreakPoss phase */ + protected LayoutManager curChildLM = null; + protected ListIterator childLMiter = null; + /** * logging instance */ - protected static Log log = LogFactory.getLog(AbstractLayoutManager.class); + protected static Log log = LogFactory.getLog(LayoutManager.class); /** * Abstract layout manager. @@ -82,7 +88,8 @@ this.fobj = fo; foID = fobj.getID(); markers = fobj.getMarkers(); - childLMiter = new LMiter(this, fobj.getChildNodes()); + fobjIter = fobj.getChildNodes(); + childLMiter = new LMiter(this); } /** @@ -169,8 +176,6 @@ } while (childLMiter.hasNext()) { curChildLM = (LayoutManager) childLMiter.next(); - curChildLM.setParent(this); - curChildLM.initialize(); return curChildLM; } return null; @@ -361,6 +366,71 @@ */ public Marker retrieveMarker(String name, int pos, int boundary) { return parentLM.retrieveMarker(name, pos, boundary); + } + + /** + * Convenience method: preload a number of child LMs + * @param size the requested number of child LMs + * @return the list with the preloaded child LMs + */ + protected List preLoadList(int size) { + if (fobjIter == null) { + return null; + } + AreaTreeHandler areaTreeHandler = getAreaTreeHandler(); + List newLMs = new ArrayList(size); + while (fobjIter.hasNext() && newLMs.size() < size ) { + Object theobj = fobjIter.next(); + if (theobj instanceof FObj) { + FObj fobj = (FObj) theobj; + areaTreeHandler.addLayoutManager(fobj, newLMs); + } + } + return newLMs; + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#preLoadNext + */ + public boolean preLoadNext(int pos) { + List newLMs = preLoadList(pos + 1 - childLMs.size()); + addChildLMs(newLMs); + return pos < childLMs.size(); + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#getChildLMs + */ + public List getChildLMs() { + return childLMs; + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#addChildLM + */ + public void addChildLM(LayoutManager lm) { + if (lm == null) { + return; + } + lm.setParent(this); + lm.initialize(); + childLMs.add(lm); + log.trace(this.getClass().getName() + + ": Adding child LM " + lm.getClass().getName()); + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#addChildLMs + */ + public void addChildLMs(List newLMs) { + if (newLMs == null || newLMs.size() == 0) { + return; + } + ListIterator iter = newLMs.listIterator(); + while (iter.hasNext()) { + LayoutManager lm = (LayoutManager) iter.next(); + addChildLM(lm); + } } } 1.2 +1 -2 xml-fop/src/java/org/apache/fop/layoutmgr/BasicLinkLayoutManager.java Index: BasicLinkLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BasicLinkLayoutManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BasicLinkLayoutManager.java 7 Aug 2004 13:01:17 -0000 1.1 +++ BasicLinkLayoutManager.java 26 Aug 2004 20:58:30 -0000 1.2 @@ -39,7 +39,6 @@ */ public BasicLinkLayoutManager(BasicLink node) { super(node); - setLMiter(new LMiter(this, node.getChildNodes())); link = node.getLink(); isExternalLink = node.isExternalLink(); } 1.25 +61 -43 xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java Index: BlockLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- BlockLayoutManager.java 18 Aug 2004 03:26:37 -0000 1.24 +++ BlockLayoutManager.java 26 Aug 2004 20:58:30 -0000 1.25 @@ -43,6 +43,8 @@ private Block curBlockArea; + protected ListIterator proxyLMiter; + private LayoutProps layoutProps; private CommonBorderAndPadding borderProps; private CommonBackground backgroundProps; @@ -71,7 +73,7 @@ public BlockLayoutManager(org.apache.fop.fo.flow.Block inBlock) { super.setFObj(inBlock); - childLMiter = new BlockLMiter(this, childLMiter); + proxyLMiter = new ProxyLMiter(); userAgent = inBlock.getUserAgent(); setBlockTextInfo(inBlock.getPropertyManager().getTextLayoutProps( inBlock.getFOInputHandler().getFontInfo())); @@ -99,59 +101,75 @@ } /** - * Iterator for Block layout. - * This iterator combines consecutive inline areas and - * creates a line layout manager. - * The use of this iterator means that it can be reset properly. + * Proxy iterator for Block LM. + * This iterator creates and holds the complete list + * of child LMs. + * It uses fobjIter as its base iterator. + * Block LM's preLoadNext uses this iterator + * as its base iterator. */ - protected class BlockLMiter extends LMiter { + protected class ProxyLMiter extends LMiter { - private ListIterator proxy; + public ProxyLMiter() { + super(BlockLayoutManager.this); + listLMs = new ArrayList(10); + } - public BlockLMiter(LayoutManager lp, ListIterator pr) { - super(lp, null); - proxy = pr; + public boolean hasNext() { + return (curPos < listLMs.size()) ? true : preLoadNext(curPos); } - protected boolean preLoadNext() { - while (proxy.hasNext()) { - LayoutManager lm = (LayoutManager) proxy.next(); - lm.setParent(BlockLayoutManager.this); - if (lm.generatesInlineAreas()) { - LineLayoutManager lineLM = createLineManager(lm); - listLMs.add(lineLM); - } else { - listLMs.add(lm); - } - if (curPos < listLMs.size()) { - return true; - } + protected boolean preLoadNext(int pos) { + List newLMs = preLoadList(pos + 1 - listLMs.size()); + if (newLMs != null) { + listLMs.addAll(newLMs); } - return false; + return pos < listLMs.size(); } + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#preLoadNext + */ + public boolean preLoadNext(int pos) { - protected LineLayoutManager createLineManager( - LayoutManager firstlm) { - LayoutManager lm; - List inlines = new ArrayList(); - inlines.add(firstlm); - while (proxy.hasNext()) { - lm = (LayoutManager) proxy.next(); - lm.setParent(BlockLayoutManager.this); - if (lm.generatesInlineAreas()) { - inlines.add(lm); - } else { - proxy.previous(); - break; - } + while (proxyLMiter.hasNext()) { + LayoutManager lm = (LayoutManager) proxyLMiter.next(); + if (lm.generatesInlineAreas()) { + LineLayoutManager lineLM = createLineManager(lm); + addChildLM(lineLM); + } else { + addChildLM(lm); } - LineLayoutManager child; - child = new LineLayoutManager(fobj, lineHeight, - lead, follow); - child.setLMiter(inlines.listIterator()); - return child; + if (pos < childLMs.size()) { + return true; + } + } + return false; + } + /** + * Create a new LineLM, and collect all consecutive + * inline generating LMs as its child LMs. + * @param firstlm First LM in new LineLM + * @return the newly created LineLM + */ + private LineLayoutManager createLineManager(LayoutManager firstlm) { + LineLayoutManager llm; + llm = new LineLayoutManager(fobj, lineHeight, lead, follow); + List inlines = new ArrayList(); + inlines.add(firstlm); + while (proxyLMiter.hasNext()) { + LayoutManager lm = (LayoutManager) proxyLMiter.next(); + if (lm.generatesInlineAreas()) { + inlines.add(lm); + } else { + proxyLMiter.previous(); + break; + } } + llm.addChildLMs(inlines); + return llm; } public BreakPoss getNextBreakPoss(LayoutContext context) { 1.12 +53 -0 xml-fop/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java Index: ContentLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ContentLayoutManager.java 13 Jul 2004 00:16:22 -0000 1.11 +++ ContentLayoutManager.java 26 Aug 2004 20:58:30 -0000 1.12 @@ -27,10 +27,14 @@ import org.apache.fop.area.PageViewport; import java.util.List; +import java.util.ListIterator; import java.util.Map; import java.util.ArrayList; import org.apache.fop.traits.MinOptMax; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * Content Layout Manager. * For use with objects that contain inline areas such as @@ -41,6 +45,12 @@ private Area holder; private int stackSize; private LayoutManager parentLM; + private List childLMs = new ArrayList(1); + + /** + * logging instance + */ + protected static Log log = LogFactory.getLog(LayoutManager.class); /** * Constructs a new ContentLayoutManager @@ -241,5 +251,48 @@ public Marker retrieveMarker(String name, int pos, int boundary) { return parentLM.retrieveMarker(name, pos, boundary); } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#preLoadNext + */ + public boolean preLoadNext(int pos) { + return false; + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#getChildLMs + */ + public List getChildLMs() { + return childLMs; + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#addChildLM + */ + public void addChildLM(LayoutManager lm) { + if (lm == null) { + return; + } + lm.setParent(this); + lm.initialize(); + childLMs.add(lm); + log.trace(this.getClass().getName() + + ": Adding child LM " + lm.getClass().getName()); + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager#addChildLMs + */ + public void addChildLMs(List newLMs) { + if (newLMs == null || newLMs.size() == 0) { + return; + } + ListIterator iter = newLMs.listIterator(); + while (iter.hasNext()) { + LayoutManager lm = (LayoutManager) iter.next(); + addChildLM(lm); + } + } + } 1.10 +0 -11 xml-fop/src/java/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java Index: InlineStackingLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- InlineStackingLayoutManager.java 26 May 2004 04:22:39 -0000 1.9 +++ InlineStackingLayoutManager.java 26 Aug 2004 20:58:30 -0000 1.10 @@ -95,17 +95,6 @@ } /** - * Set the FO object for this layout manager - * - * @param fo the fo for this layout manager - */ - public void setFObj(FObj fo) { - this.fobj = fo; - foID = fobj.getID(); - childLMiter = null; - } - - /** * @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties() */ protected void initProperties() { 1.10 +3 -23 xml-fop/src/java/org/apache/fop/layoutmgr/LMiter.java Index: LMiter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/LMiter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- LMiter.java 16 Aug 2004 11:59:52 -0000 1.9 +++ LMiter.java 26 Aug 2004 20:58:30 -0000 1.10 @@ -29,38 +29,18 @@ public class LMiter implements ListIterator { - private ListIterator baseIter; - private FObj curFO; protected List listLMs; protected int curPos = 0; /** The LayoutManager to which this LMiter is attached **/ private LayoutManager lp; - public LMiter(LayoutManager lp, ListIterator bIter) { + public LMiter(LayoutManager lp) { this.lp = lp; - baseIter = bIter; - listLMs = new ArrayList(10); + listLMs = lp.getChildLMs(); } public boolean hasNext() { - return (curPos < listLMs.size()) ? true : preLoadNext(); - } - - protected boolean preLoadNext() { - AreaTreeHandler areaTreeHandler = lp.getAreaTreeHandler(); - // skip over child FObj's that don't add lms - while (baseIter != null && baseIter.hasNext()) { - Object theobj = baseIter.next(); - if (theobj instanceof FObj) { - FObj fobj = (FObj) theobj; - //listLMs.add(fobj.getLayoutManager()); - areaTreeHandler.addLayoutManager(fobj, listLMs); - if (curPos < listLMs.size()) { - return true; - } - } - } - return false; + return (curPos < listLMs.size()) ? true : lp.preLoadNext(curPos); } public boolean hasPrevious() { 1.2 +10 -8 xml-fop/src/java/org/apache/fop/layoutmgr/LeaderLayoutManager.java Index: LeaderLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/LeaderLayoutManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LeaderLayoutManager.java 16 Aug 2004 04:11:42 -0000 1.1 +++ LeaderLayoutManager.java 26 Aug 2004 20:58:30 -0000 1.2 @@ -108,18 +108,20 @@ ldrNode.getLogger().error("Leader use-content with no content"); return null; } - InlineStackingLayoutManager lm; - lm = new InlineStackingLayoutManager(ldrNode); - lm.setLMiter(new LMiter(lm, ldrNode.getChildNodes())); - lm.initialize(); + // child FOs are assigned to the InlineStackingLM + fobjIter = null; + // get breaks then add areas to FilledArea FilledArea fa = new FilledArea(); - + ContentLayoutManager clm = new ContentLayoutManager(fa); - clm.setParent(this); clm.setUserAgent(ldrNode.getUserAgent()); - lm.setParent(clm); + addChildLM(clm); + + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager(ldrNode); + clm.addChildLM(lm); clm.fillArea(lm); int width = clm.getStackingSize(); 1.24 +3 -0 xml-fop/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java Index: LineLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/LineLayoutManager.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- LineLayoutManager.java 29 May 2004 09:07:59 -0000 1.23 +++ LineLayoutManager.java 26 Aug 2004 20:58:30 -0000 1.24 @@ -115,6 +115,9 @@ */ public LineLayoutManager(FObj node, int lh, int l, int f) { super(node); + // the child FObj are owned by the parent BlockLM + // this LM has all its childLMs preloaded + fobjIter = null; lineHeight = lh; lead = l; follow = f;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]