From: Glenn Adams Date: Tue, 17 Apr 2012 16:15:44 +0000 (+0000) Subject: Bugzilla #53094: Convert block container overflow exception to event model, improving... X-Git-Tag: fop-1_1rc1old~46 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a915c74aa4d3bcad9448d1808e5baba10ba91e24;p=xmlgraphics-fop.git Bugzilla #53094: Convert block container overflow exception to event model, improving overflow property behavior. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1327157 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index aab505d8b..8b656a753 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -86,6 +86,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager private MinOptMax effSpaceBefore; private MinOptMax effSpaceAfter; + private int horizontalOverflow; private double contentRectOffsetX = 0; private double contentRectOffsetY = 0; @@ -401,7 +402,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get( getBlockContainerFO().getUserAgent().getEventBroadcaster()); boolean canRecover = (getBlockContainerFO().getOverflow() != EN_ERROR_IF_OVERFLOW); - eventProducer.viewportOverflow(this, getBlockContainerFO().getName(), + eventProducer.viewportBPDOverflow(this, getBlockContainerFO().getName(), breaker.getOverflowAmount(), needClip(), canRecover, getBlockContainerFO().getLocator()); } @@ -553,10 +554,18 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get( getBlockContainerFO().getUserAgent().getEventBroadcaster()); boolean canRecover = (getBlockContainerFO().getOverflow() != EN_ERROR_IF_OVERFLOW); - eventProducer.viewportOverflow(this, getBlockContainerFO().getName(), + eventProducer.viewportBPDOverflow(this, getBlockContainerFO().getName(), breaker.getOverflowAmount(), needClip(), canRecover, getBlockContainerFO().getLocator()); } + // this handles the IPD (horizontal) overflow + if (this.horizontalOverflow > 0) { + BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider + .get(getBlockContainerFO().getUserAgent().getEventBroadcaster()); + boolean canRecover = (getBlockContainerFO().getOverflow() != EN_ERROR_IF_OVERFLOW); + eventProducer.viewportIPDOverflow(this, getBlockContainerFO().getName(), + this.horizontalOverflow, needClip(), canRecover, getBlockContainerFO().getLocator()); + } } setFinished(true); @@ -1027,6 +1036,13 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager } } + /** {@inheritDoc} */ + public boolean handleOverflow(int milliPoints) { + if (milliPoints > this.horizontalOverflow) { + this.horizontalOverflow = milliPoints; + } + return true; + } } diff --git a/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java b/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java index 7d3964181..d9de09a46 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java @@ -89,19 +89,30 @@ public interface BlockLevelEventProducer extends EventProducer { void overconstrainedAdjustEndIndent(Object source, String elementName, int amount, Locator loc); /** - * Contents overflow a viewport. + * Contents IPD overflow a viewport. * @param source the event source * @param elementName the formatting object * @param amount the amount by which the contents overflow (in mpt) * @param clip true if the content will be clipped * @param canRecover indicates whether FOP can recover from this problem and continue working * @param loc the location of the error or null - * @throws LayoutException the layout error provoked by the method call - * @event.severity FATAL + * @event.severity ERROR */ - void viewportOverflow(Object source, String elementName, - int amount, boolean clip, boolean canRecover, - Locator loc) throws LayoutException; + void viewportIPDOverflow(Object source, String elementName, int amount, boolean clip, + boolean canRecover, Locator loc); + + /** + * Contents BPD overflow a viewport. + * @param source the event source + * @param elementName the formatting object + * @param amount the amount by which the contents overflow (in mpt) + * @param clip true if the content will be clipped + * @param canRecover indicates whether FOP can recover from this problem and continue working + * @param loc the location of the error or null + * @event.severity ERROR + */ + void viewportBPDOverflow(Object source, String elementName, int amount, boolean clip, + boolean canRecover, Locator loc); /** * Contents overflow a region viewport. diff --git a/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml b/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml index a89f9ed32..d3e243a63 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml +++ b/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml @@ -22,7 +22,8 @@ table-layout="fixed" and width="auto", but auto-layout not supported => assuming width="100%".{{locator}} The extent in inline-progression-direction (width) of a {elementName} is bigger than the available space ({effIPD}mpt > {maxIPD}mpt).{{locator}} An {elementName} {{locator}} is wider than the available room in inline-progression-dimension. Adjusting end-indent based on overconstrained geometry rules (XSL 1.1, ch. 5.3.4) - Content overflows the viewport of an {elementName} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}} + Content overflows the viewport of an {elementName} in inline-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}} + Content overflows the viewport of an {elementName} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}} Content overflows the viewport of the {elementName} on page {page} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}} Flow "{flowName}" does not map to the region-body in page-master "{masterName}". FOP presently does not support this.{{locator}} Subsequences exhausted in page-sequence-master "{pageSequenceMasterName}", {canRecover,if,using previous subsequence,cannot recover}.{{locator}} diff --git a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java index 56c02795c..403bd6f68 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java @@ -1249,5 +1249,16 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager // TODO startIndent, endIndent } + /** + * Whether this LM can handle horizontal overflow error messages (only a BlockContainerLayoutManager can). + * @param milliPoints horizontal overflow + * @return true if handled by a BlockContainerLayoutManager + */ + public boolean handleOverflow(int milliPoints) { + if (getParent() instanceof BlockStackingLayoutManager) { + return ((BlockStackingLayoutManager) getParent()).handleOverflow(milliPoints); + } + return false; + } } diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java index 3b2f11ea2..27958f7e0 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java @@ -45,6 +45,7 @@ import org.apache.fop.fonts.FontTriplet; import org.apache.fop.hyphenation.Hyphenation; import org.apache.fop.hyphenation.Hyphenator; import org.apache.fop.layoutmgr.Adjustment; +import org.apache.fop.layoutmgr.BlockLayoutManager; import org.apache.fop.layoutmgr.BlockLevelLayoutManager; import org.apache.fop.layoutmgr.BreakElement; import org.apache.fop.layoutmgr.BreakingAlgorithm; @@ -389,7 +390,10 @@ public class LineLayoutManager extends InlineStackingLayoutManager if (log.isWarnEnabled()) { int lack = difference + bestActiveNode.availableShrink; - if (lack < 0) { + // if this LLM is nested inside a BlockContainerLayoutManager that is constraining + // the available width and thus responsible for the overflow then we do not issue + // warning event here and instead let the BCLM handle that at a later stage + if (lack < 0 && !handleOverflow(-lack)) { InlineLevelEventProducer eventProducer = InlineLevelEventProducer.Provider.get( getFObj().getUserAgent().getEventBroadcaster()); @@ -1635,4 +1639,15 @@ public class LineLayoutManager extends InlineStackingLayoutManager return true; } + /** + * Whether this LM can handle horizontal overflow error messages (only a BlockContainerLayoutManager can). + * @param milliPoints horizontal overflow + * @return true if handled by a BlockContainerLayoutManager + */ + public boolean handleOverflow(int milliPoints) { + if (getParent() instanceof BlockLayoutManager) { + return ((BlockLayoutManager) getParent()).handleOverflow(milliPoints); + } + return false; + } } diff --git a/status.xml b/status.xml index ee835849d..57df34094 100644 --- a/status.xml +++ b/status.xml @@ -62,6 +62,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Convert block container overflow exception to event model, improving overflow property behavior. + Add run target for embedded examples. Add increased JVM memory heap flag for example8 in case font cache is rebuilt. diff --git a/test/events/inline-level.fo b/test/events/inline-level.fo index 26a00acff..e415891ac 100644 --- a/test/events/inline-level.fo +++ b/test/events/inline-level.fo @@ -2,16 +2,14 @@ + page-height="420pt" page-width="100pt" margin="10pt"> The following line overflows its container: - - ThisLineOverflowsItsContainer - + ThisLineOverflowsItsContainer diff --git a/test/events/viewport-overflow.fo b/test/events/viewport-overflow.fo new file mode 100644 index 000000000..ac9dc76bb --- /dev/null +++ b/test/events/viewport-overflow.fo @@ -0,0 +1,18 @@ + + + + + + + + + + + abcdefghijklmnopqrstuvwxyz + + + abc def ghi jkl mno pqr stu vwx yz + + + + diff --git a/test/java/org/apache/fop/events/EventProcessingTestCase.java b/test/java/org/apache/fop/events/EventProcessingTestCase.java index 8219fa71e..1d38d4ccb 100644 --- a/test/java/org/apache/fop/events/EventProcessingTestCase.java +++ b/test/java/org/apache/fop/events/EventProcessingTestCase.java @@ -124,4 +124,16 @@ public class EventProcessingTestCase { doTest("inline-level.fo", InlineLevelEventProducer.class.getName() + ".lineOverflows"); } + + @Test + public void testViewportIPDOverflow() throws FOPException, TransformerException, IOException, + SAXException { + doTest("viewport-overflow.fo", BlockLevelEventProducer.class.getName() + ".viewportIPDOverflow"); + } + + @Test + public void testViewportBPDOverflow() throws FOPException, TransformerException, IOException, + SAXException { + doTest("viewport-overflow.fo", BlockLevelEventProducer.class.getName() + ".viewportBPDOverflow"); + } }