From 0a948282aa0d87afb4d1aea82e1e240b0cee816b Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Tue, 21 Jul 2009 15:31:56 +0000 Subject: [PATCH] Moved the IPD-change-related getNextKnuthElements method to the LayoutManager interface. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ChangingIPDHack@796350 13f79535-47bb-0310-9956-ffa450edef68 --- .../layoutmgr/AbstractBaseLayoutManager.java | 9 +++++++++ .../fop/layoutmgr/BlockLayoutManager.java | 2 +- .../layoutmgr/BlockStackingLayoutManager.java | 2 +- .../fop/layoutmgr/FlowLayoutManager.java | 15 ++++++--------- .../apache/fop/layoutmgr/LayoutManager.java | 18 ++++++++++++++++++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java index 55c6e8227..8c213d7d5 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractBaseLayoutManager.java @@ -19,6 +19,9 @@ package org.apache.fop.layoutmgr; +import java.util.List; +import java.util.Stack; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -264,4 +267,10 @@ public abstract class AbstractBaseLayoutManager return false; } + /** {@inheritDoc} */ + public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack, + Position positionAtIPDChange, LayoutManager restartAtLM) { + throw new UnsupportedOperationException("Not implemented"); + } + } diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index ab9407986..827654699 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -116,7 +116,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager } /** {@inheritDoc} */ - List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack, + public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack, Position restartPosition, LayoutManager restartAtLM) { resetSpaces(); if (lmStack == null) { diff --git a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java index b553c7083..ac781078a 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java @@ -358,7 +358,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager } /** {@inheritDoc} */ - List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack, + public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack, Position restartPosition, LayoutManager restartAtLM) { referenceIPD = context.getRefIPD(); updateContentAreaIPDwithOverconstrainedAdjust(); diff --git a/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java index e451525da..4d077d2b3 100644 --- a/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -104,13 +104,9 @@ public class FlowLayoutManager extends BlockStackingLayoutManager currentChildLM = currentChildLM.getParent(); } setCurrentChildLM(currentChildLM); - if (!(currentChildLM instanceof BlockLayoutManager)) { - throw new UnsupportedOperationException("TODO: layout manager not restartable"); - } else { - if (addChildElements(elements, currentChildLM, context, alignment, lmStack, - positionAtIPDChange, restartAtLM) != null) { - return elements; - } + if (addChildElements(elements, currentChildLM, context, alignment, lmStack, + positionAtIPDChange, restartAtLM) != null) { + return elements; } } @@ -192,7 +188,8 @@ public class FlowLayoutManager extends BlockStackingLayoutManager } private List getNextChildElements(LayoutManager childLM, LayoutContext context, - LayoutContext childLC, int alignment, Stack lmStack, Position restartPosition, LayoutManager restartLM) { + LayoutContext childLC, int alignment, Stack lmStack, Position restartPosition, + LayoutManager restartLM) { childLC.setStackLimitBP(context.getStackLimitBP()); childLC.setRefIPD(context.getRefIPD()); childLC.setWritingMode(getCurrentPage().getSimplePageMaster().getWritingMode()); @@ -201,7 +198,7 @@ public class FlowLayoutManager extends BlockStackingLayoutManager if (lmStack == null) { childrenElements = childLM.getNextKnuthElements(childLC, alignment); } else { - childrenElements = ((BlockLayoutManager) childLM).getNextKnuthElements(childLC, + childrenElements = childLM.getNextKnuthElements(childLC, alignment, lmStack, restartPosition, restartLM); } assert !childrenElements.isEmpty(); diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManager.java b/src/java/org/apache/fop/layoutmgr/LayoutManager.java index 70cd3e02d..454b8b366 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManager.java @@ -20,6 +20,7 @@ package org.apache.fop.layoutmgr; import java.util.List; +import java.util.Stack; import org.apache.fop.area.Area; import org.apache.fop.datatypes.PercentBaseContext; @@ -234,4 +235,21 @@ public interface LayoutManager extends PercentBaseContext { * change */ boolean isRestartable(); + + /** + * Returns an updated list of Knuth elements corresponding to this layout + * manager, after a change of IPD has been detected. + * + * @param context the layout context + * @param alignment the alignment + * @param lmStack the stack of LMs that are active at the IPD change + * @param positionAtIPDChange the position corresponding to the element + * finishing the page before the IPD change + * @param restartAtLM if not null, the layout manager from which to restart. + * That is, the IPD change occurs between two block elements and not inside + * a paragraph + * @return an updated list of elements, taking the new IPD into account + */ + List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack, + Position positionAtIPDChange, LayoutManager restartAtLM); } -- 2.39.5