]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla #53094: Convert block container overflow exception to event model, improving...
authorGlenn Adams <gadams@apache.org>
Tue, 17 Apr 2012 16:15:44 +0000 (16:15 +0000)
committerGlenn Adams <gadams@apache.org>
Tue, 17 Apr 2012 16:15:44 +0000 (16:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1327157 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java
src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java
src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml
src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
status.xml
test/events/inline-level.fo
test/events/viewport-overflow.fo [new file with mode: 0644]
test/java/org/apache/fop/events/EventProcessingTestCase.java

index aab505d8b105c7b3dd8af3883007efa8a47c0463..8b656a7538fa3aeba9e29eb7d480dc16d0916c24 100644 (file)
@@ -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;
+    }
 }
 
 
index 7d39641810fe27971dd81e84b2ee7e1c934cddb8..d9de09a462440f854dabf13e05dae26621500db6 100644 (file)
@@ -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.
index a89f9ed32814620329297e0c81294011f1346815..d3e243a63f431ab03937b1a7f95812c70637bfa9 100644 (file)
@@ -22,7 +22,8 @@
   <message key="tableFixedAutoWidthNotSupported">table-layout="fixed" and width="auto", but auto-layout not supported =&gt; assuming width="100%".{{locator}}</message>
   <message key="objectTooWide">The extent in inline-progression-direction (width) of a {elementName} is bigger than the available space ({effIPD}mpt &gt; {maxIPD}mpt).{{locator}}</message>
   <message key="overconstrainedAdjustEndIndent">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)</message>
-  <message key="viewportOverflow">Content overflows the viewport of an {elementName} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}}</message>
+  <message key="viewportIPDOverflow">Content overflows the viewport of an {elementName} in inline-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}}</message>
+  <message key="viewportBPDOverflow">Content overflows the viewport of an {elementName} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}}</message>
   <message key="regionOverflow">Content overflows the viewport of the {elementName} on page {page} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}}</message>
   <message key="flowNotMappingToRegionBody">Flow "{flowName}" does not map to the region-body in page-master "{masterName}". FOP presently does not support this.{{locator}}</message>
   <message key="pageSequenceMasterExhausted">Subsequences exhausted in page-sequence-master "{pageSequenceMasterName}", {canRecover,if,using previous subsequence,cannot recover}.{{locator}}</message>
index 56c02795caafaa0dc4a632f46d2b40965b225444..403bd6f689d65ba2deb7d3d66a8e2f47dde2a10b 100644 (file)
@@ -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;
+    }
 }
 
index 3b2f11ea21183545d44fc724af4486bc5127ac74..27958f7e0f7e5b4cb5aa0856c7a408f40560487c 100644 (file)
@@ -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;
+    }
 }
index ee835849d4b50e3064dbf258d800584391192746..57df340941e1967bd8270d08974565a306367f1b 100644 (file)
@@ -62,6 +62,9 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Code" dev="GA" type="update" fixes-bug="53094" due-to="Luis Bernardo">
+        Convert block container overflow exception to event model, improving overflow property behavior.
+      </action>
       <action context="Code" dev="GA" type="update" fixes-bug="51617">
         Add run target for embedded examples. Add increased JVM memory heap flag for example8 in case font cache is rebuilt.
       </action>
index 26a00acff68d9ec67580d286524d4acc0e512ed4..e415891ac0978fac817f140f7ef37afeb7fb7e7c 100644 (file)
@@ -2,16 +2,14 @@
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:layout-master-set>
     <fo:simple-page-master master-name="page"
-      page-height="420pt" page-width="320pt" margin="10pt">
+      page-height="420pt" page-width="100pt" margin="10pt">
       <fo:region-body background-color="#F0F0F0"/>
     </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="page">
     <fo:flow flow-name="xsl-region-body">
       <fo:block>The following line overflows its container:</fo:block>
-      <fo:block-container width="100pt" height="100pt" border="1pt solid black">
-        <fo:block>ThisLineOverflowsItsContainer</fo:block>
-      </fo:block-container>
+      <fo:block border="1pt solid black">ThisLineOverflowsItsContainer</fo:block>
     </fo:flow>
   </fo:page-sequence>
 </fo:root>
diff --git a/test/events/viewport-overflow.fo b/test/events/viewport-overflow.fo
new file mode 100644 (file)
index 0000000..ac9dc76
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+  <fo:layout-master-set>
+    <fo:simple-page-master page-width="10.0cm" page-height="10.0cm" master-name="testpage">
+      <fo:region-body />
+    </fo:simple-page-master>
+  </fo:layout-master-set>
+  <fo:page-sequence master-reference="testpage">
+    <fo:flow flow-name="xsl-region-body">
+      <fo:block-container overflow="error-if-overflow" position="absolute" height="20pt" width="40pt" left="30pt" top="20pt">
+        <fo:block>abcdefghijklmnopqrstuvwxyz</fo:block>
+      </fo:block-container>
+      <fo:block-container overflow="error-if-overflow" position="absolute" height="65pt" width="40pt" left="90pt" top="20pt">
+        <fo:block>abc def ghi jkl mno pqr stu vwx yz</fo:block>
+      </fo:block-container>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
index 8219fa71ef08069feeab6875fe1e57b57d8b73cf..1d38d4ccb200e18803268aae8699bce12f6596c7 100644 (file)
@@ -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");
+    }
 }