diff options
author | Keiron Liddle <keiron@apache.org> | 2002-08-21 09:17:42 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-08-21 09:17:42 +0000 |
commit | 764bcf89165659d00a6a9e026457c1cb15d62186 (patch) | |
tree | dbdb87fdcade6d7938bc55cd4a07bfb48814a3d3 | |
parent | 87043b9e254777402d1df0f308f8766777583ba4 (diff) | |
download | xmlgraphics-fop-764bcf89165659d00a6a9e026457c1cb15d62186.tar.gz xmlgraphics-fop-764bcf89165659d00a6a9e026457c1cb15d62186.zip |
properly resets blocks
use a block lm iter so that it can create line layout manager from inline lm's
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195110 13f79535-47bb-0310-9956-ffa450edef68
5 files changed, 95 insertions, 67 deletions
diff --git a/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java b/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java index 45499d909..b00b708f8 100644 --- a/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java @@ -90,7 +90,7 @@ public abstract class AbstractBPLayoutManager extends AbstractLayoutManager impl BPLayoutManager lm = (pos != null) ? pos.getLM() : null; if (m_curChildLM != lm) { // ASSERT m_curChildLM == (BPLayoutManager)m_childLMiter.previous() - if (m_curChildLM != + if (m_childLMiter.hasPrevious() && m_curChildLM != (BPLayoutManager) m_childLMiter.previous()) { //log.error("LMiter problem!"); } diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index 88af158db..588335171 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -32,8 +32,62 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { ArrayList childBreaks = new ArrayList(); + /** + * 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. + */ + protected class BlockLMiter extends LMiter { + + private ListIterator proxy; + + public BlockLMiter(ListIterator pr) { + super(null); + proxy = pr; + } + + protected boolean preLoadNext() { + while (proxy.hasNext()) { + LayoutManager lm = (LayoutManager) proxy.next(); + if(lm.generatesInlineAreas()) { + LineBPLayoutManager lineLM = createLineManager(lm); + m_listLMs.add(lineLM); + } else { + m_listLMs.add(lm); + } + if (m_curPos < m_listLMs.size()) { + return true; + } + } + return false; + } + + protected LineBPLayoutManager createLineManager( + LayoutManager firstlm) { + LayoutManager lm; + ArrayList inlines = new ArrayList(); + inlines.add(firstlm); + while (proxy.hasNext()) { + lm = (LayoutManager) proxy.next(); + if (lm.generatesInlineAreas()) { + inlines.add(lm); + } else { + proxy.previous(); + break; + } + } + LineBPLayoutManager child; + child = new LineBPLayoutManager(fobj, inlines, lineHeight, + lead, follow); + return child; + + } + } + public BlockLayoutManager(FObj fobj) { super(fobj); + m_childLMiter = new BlockLMiter(m_childLMiter); } public void setBlockTextInfo(TextInfo ti) { @@ -54,47 +108,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { return curBlockArea.getIPD(); } - protected BPLayoutManager getChildLM() { - if (m_curChildLM != null && !m_curChildLM.isFinished()) { - return m_curChildLM; - } - while (m_childLMiter.hasNext()) { - LayoutManager lm = (LayoutManager) m_childLMiter.next(); - if (lm.generatesInlineAreas()) { - ArrayList inlines = new ArrayList(); - inlines.add(lm); - //lms.remove(count); - while (m_childLMiter.hasNext()) { - lm = (LayoutManager) m_childLMiter.next(); - if (lm.generatesInlineAreas()) { - inlines.add(lm); - //lms.remove(count + 1); - } else { - m_childLMiter.previous(); - break; - } - } - m_curChildLM = new LineBPLayoutManager(fobj, inlines, - lineHeight, lead, follow); - m_curChildLM.setParentLM(this); - m_curChildLM.init(); - return m_curChildLM; - //lms.set(count, lm); - } else if (lm instanceof BPLayoutManager) { - m_curChildLM = (BPLayoutManager) lm; - m_curChildLM.setParentLM(this); - m_curChildLM.init(); - return m_curChildLM; - } else { - m_childLMiter.remove(); - //log.warn( - // "child LM not a BPLayoutManager: " + - // lm.getClass().getName()); - } - } - return null; - } - public BreakPoss getNextBreakPoss(LayoutContext context, Position prevLineBP) { @@ -111,41 +124,45 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { int ipd = context.getRefIPD(); BreakPoss bp; - LayoutContext childLC = - new LayoutContext(0); - if(curLM.generatesInlineAreas()) { + LayoutContext childLC = new LayoutContext(0); + // if line layout manager then set stack limit to ipd + // line LM actually generates a LineArea which is a block + if (curLM.generatesInlineAreas()) { // set stackLimit for lines childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents - m_iTextIndent*/)); } else { - childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize)); + childLC.setStackLimit( + MinOptMax.subtract(context.getStackLimit(), + stackSize)); childLC.setRefIPD(ipd); } while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) { - stackSize.add(bp.getStackingSize()); - if(stackSize.min > context.getStackLimit().max) { - // reset to last break - if(lastPos != null) { - reset(lastPos.getPosition()); - } else { - curLM.resetPosition(null); - } - break; + stackSize.add(bp.getStackingSize()); + if (stackSize.min > context.getStackLimit().max) { + // reset to last break + if (lastPos != null) { + reset(lastPos.getPosition()); + } else { + curLM.resetPosition(null); } - lastPos = bp; - childBreaks.add(bp); + break; + } + lastPos = bp; + childBreaks.add(bp); - if(curLM.generatesInlineAreas()) { + if (curLM.generatesInlineAreas()) { // Reset stackLimit for non-first lines childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents*/)); - } else { - childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize)); - } + } else { + childLC.setStackLimit( MinOptMax.subtract( + context.getStackLimit(), stackSize)); + } } } BreakPoss breakPoss = new BreakPoss( - new LeafPosition(this, childBreaks.size() - 1)); + new LeafPosition(this, childBreaks.size() - 1)); breakPoss.setStackingSize(stackSize); return breakPoss; } @@ -153,7 +170,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { return null; } - public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { + public void addAreas(PositionIterator parentIter, + LayoutContext layoutContext) { getParentArea(null); BPLayoutManager childLM ; @@ -226,5 +244,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { return false; } + public void resetPosition(Position resetPos) { + if (resetPos == null) { + reset(null); + } + } } diff --git a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java index 97d031e27..114283b58 100644 --- a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -128,5 +128,10 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { return parentArea; } + public void resetPosition(Position resetPos) { + if (resetPos == null) { + reset(null); + } + } } diff --git a/src/org/apache/fop/layoutmgr/LMiter.java b/src/org/apache/fop/layoutmgr/LMiter.java index eea620c95..9870c5e60 100644 --- a/src/org/apache/fop/layoutmgr/LMiter.java +++ b/src/org/apache/fop/layoutmgr/LMiter.java @@ -18,8 +18,8 @@ public class LMiter implements ListIterator { private ListIterator m_baseIter; private FObj m_curFO; - private ArrayList m_listLMs; - private int m_curPos = 0; + protected ArrayList m_listLMs; + protected int m_curPos = 0; public LMiter(ListIterator baseIter) { m_baseIter = baseIter; @@ -30,7 +30,7 @@ public class LMiter implements ListIterator { return (m_curPos < m_listLMs.size()) ? true : preLoadNext(); } - private boolean preLoadNext() { + protected boolean preLoadNext() { // skip over child FObj's that don't add lms while (m_baseIter.hasNext()) { FObj fobj = (FObj) m_baseIter.next(); diff --git a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java index b0e4a60dc..f24b94c05 100644 --- a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java @@ -95,7 +95,6 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { m_hyphProps = propMgr.getHyphenationProps(); } - /** * Call child layout managers to generate content as long as they * generate inline areas. If a block-level generating LM is found, @@ -457,6 +456,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { public void resetPosition(Position resetPos) { if (resetPos == null) { + iStartPos = 0; reset(null); m_vecInlineBreaks.clear(); m_prevBP = null; |