diff options
author | Glenn Adams <gadams@apache.org> | 2012-05-04 16:52:35 +0000 |
---|---|---|
committer | Glenn Adams <gadams@apache.org> | 2012-05-04 16:52:35 +0000 |
commit | 953e762e1b5dcb2cb31b6ca8a87110018c9151de (patch) | |
tree | fc54d97b0970081728049df5ec2f67787583ca8e /src/java/org | |
parent | 9426ed36abe7189e158116f92f607612ba432a17 (diff) | |
download | xmlgraphics-fop-953e762e1b5dcb2cb31b6ca8a87110018c9151de.tar.gz xmlgraphics-fop-953e762e1b5dcb2cb31b6ca8a87110018c9151de.zip |
Bugzilla #45715: Break before (break-before) not respected on blocks nested in inlines.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1334058 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
8 files changed, 121 insertions, 31 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java index d227b7060..0089f228f 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -41,8 +41,7 @@ import org.apache.fop.fo.flow.RetrieveMarker; /** * The base class for most LayoutManagers. */ -public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager - implements Constants { +public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager implements Constants { /** logging instance */ private static Log log = LogFactory.getLog(AbstractLayoutManager.class); diff --git a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index 8b656a753..adce89ac0 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -44,8 +44,8 @@ import org.apache.fop.traits.SpaceVal; /** * LayoutManager for a block-container FO. */ -public class BlockContainerLayoutManager extends BlockStackingLayoutManager - implements ConditionalElementListener { +public class BlockContainerLayoutManager extends BlockStackingLayoutManager implements + ConditionalElementListener, BreakOpportunity { /** * logging instance @@ -1043,6 +1043,11 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager } return true; } + + public int getBreakBefore() { + return BreakOpportunityHelper.getBreakBefore(this); + } + } diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 9c3639f93..03b2d380c 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -43,8 +43,8 @@ import org.apache.fop.traits.SpaceVal; /** * LayoutManager for a block FO. */ -public class BlockLayoutManager extends BlockStackingLayoutManager - implements ConditionalElementListener { +public class BlockLayoutManager extends BlockStackingLayoutManager implements ConditionalElementListener, + BreakOpportunity { /** logging instance */ private static Log log = LogFactory.getLog(BlockLayoutManager.class); @@ -504,4 +504,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager return true; } + public int getBreakBefore() { + return BreakOpportunityHelper.getBreakBefore(this); + } + } diff --git a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java index 403bd6f68..78ab6711a 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java @@ -38,7 +38,6 @@ import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.layoutmgr.inline.InlineLayoutManager; import org.apache.fop.traits.MinOptMax; -import org.apache.fop.util.BreakUtil; import org.apache.fop.util.ListUtil; /** @@ -1036,7 +1035,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager * @return true if an element has been added due to a break-before. */ protected boolean addKnuthElementsForBreakBefore(List returnList, LayoutContext context) { - int breakBefore = getBreakBefore(); + int breakBefore = BreakOpportunityHelper.getBreakBefore(this); if (breakBefore == EN_PAGE || breakBefore == EN_COLUMN || breakBefore == EN_EVEN_PAGE @@ -1051,27 +1050,6 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager } /** - * Returns the break-before value of the current formatting object. - * @return the break-before value (Constants.EN_*) - */ - private int getBreakBefore() { - int breakBefore = EN_AUTO; - if (fobj instanceof BreakPropertySet) { - breakBefore = ((BreakPropertySet)fobj).getBreakBefore(); - } - if (true /* uncomment to only partially merge: && breakBefore != EN_AUTO*/) { - LayoutManager lm = getChildLM(); - //It is assumed this is only called when the first LM is active. - if (lm instanceof BlockStackingLayoutManager) { - BlockStackingLayoutManager bslm = (BlockStackingLayoutManager)lm; - breakBefore = BreakUtil.compareBreakClasses( - breakBefore, bslm.getBreakBefore()); - } - } - return breakBefore; - } - - /** * Creates Knuth elements for break-after and adds them to the return list. * @param returnList return list to add the additional elements to * @param context the layout context diff --git a/src/java/org/apache/fop/layoutmgr/BreakOpportunity.java b/src/java/org/apache/fop/layoutmgr/BreakOpportunity.java new file mode 100644 index 000000000..668f112c9 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/BreakOpportunity.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.layoutmgr; + +/** + * Defines methods to evaluate break opportunities at a particular location in the tree of + * layout managers. + */ +public interface BreakOpportunity { + + /** + * Returns the highest priority break-before value on this layout manager or its + * relevant descendants. + * + * @return the break-before value (Constants.EN_*) + */ + int getBreakBefore(); + +} diff --git a/src/java/org/apache/fop/layoutmgr/BreakOpportunityHelper.java b/src/java/org/apache/fop/layoutmgr/BreakOpportunityHelper.java new file mode 100644 index 000000000..a3992567f --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/BreakOpportunityHelper.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.layoutmgr; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.properties.BreakPropertySet; +import org.apache.fop.util.BreakUtil; + +/** + * Helper implementations of the {@link BreakOpportunity} methods. + */ +public final class BreakOpportunityHelper { + + private BreakOpportunityHelper() { } + + /** + * Returns the break opportunity before the given layout manager. There is a break + * opportunity if the LM's FO has the break-before property set, or if there is a + * break opportunity before its first child LM. + * + * @return the break-before value (Constants.EN_*) + */ + public static int getBreakBefore(AbstractLayoutManager layoutManager) { + int breakBefore = Constants.EN_AUTO; + if (layoutManager.getFObj() instanceof BreakPropertySet) { + breakBefore = ((BreakPropertySet) layoutManager.getFObj()).getBreakBefore(); + } + LayoutManager childLM = layoutManager.getChildLM(); + // It is assumed this is only called when the first LM is active. + if (childLM instanceof BreakOpportunity) { + BreakOpportunity bo = (BreakOpportunity) childLM; + breakBefore = BreakUtil.compareBreakClasses(breakBefore, bo.getBreakBefore()); + } + return breakBefore; + } + +} diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java index 1eb91e0ab..e87b29b2d 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java @@ -388,6 +388,13 @@ public class InlineLayoutManager extends InlineStackingLayoutManager { } lastSequence = ListUtil.getLast(returnList); lastChildLM = curLM; + // the context used to create this childLC above was applied a LayoutContext.SUPPRESS_BREAK_BEFORE + // in the getNextChildElements() method of the parent BlockLayoutManger; as a consequence all + // line breaks in blocks nested inside the inline associated with this ILM are being supressed; + // here we revert that supression; we do not need to do that for the first element since that + // is handled by the getBreakBefore() method of the wrapping BlockStackingLayoutManager. + // Note: this fix seems to work but is far from being the ideal way to do this + childLC.setFlags(LayoutContext.SUPPRESS_BREAK_BEFORE, false); } if (lastSequence != null) { diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java index 4a203d55e..3e9b85742 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java @@ -28,6 +28,8 @@ import org.apache.fop.area.inline.Space; import org.apache.fop.fo.FObj; import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.layoutmgr.AbstractLayoutManager; +import org.apache.fop.layoutmgr.BreakOpportunity; +import org.apache.fop.layoutmgr.BreakOpportunityHelper; import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.NonLeafPosition; @@ -39,8 +41,8 @@ import org.apache.fop.traits.MinOptMax; * which stack children in the inline direction, such as Inline or * Line. It should not be instantiated directly. */ -public abstract class InlineStackingLayoutManager extends AbstractLayoutManager - implements InlineLevelLayoutManager { +public abstract class InlineStackingLayoutManager extends AbstractLayoutManager implements + InlineLevelLayoutManager, BreakOpportunity { /** * Size of border and padding in BPD (ie, before and after). @@ -385,4 +387,9 @@ public abstract class InlineStackingLayoutManager extends AbstractLayoutManager return returnList; } + + public int getBreakBefore() { + return BreakOpportunityHelper.getBreakBefore(this); + } + } |