You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/12/15 11:57:51 UTC

svn commit: r357002 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: fo/FONode.java layoutmgr/BreakingAlgorithm.java

Author: jeremias
Date: Thu Dec 15 02:57:45 2005
New Revision: 357002

URL: http://svn.apache.org/viewcvs?rev=357002&view=rev
Log:
Attempt at providing context information about the element causing an endless loop because of an area overflow in b-p-direction. This should make the error message more helpful.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java?rev=357002&r1=357001&r2=357002&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FONode.java Thu Dec 15 02:57:45 2005
@@ -455,9 +455,13 @@
      * @return the decorated text
      */
     public static String decorateWithContextInfo(String text, FONode node) {
-        StringBuffer sb = new StringBuffer(text);
-        sb.append(" (").append(node.getContextInfo()).append(")");
-        return sb.toString();
+        if (node != null) {
+            StringBuffer sb = new StringBuffer(text);
+            sb.append(" (").append(node.getContextInfo()).append(")");
+            return sb.toString();
+        } else {
+            return text;
+        }
     }
     
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java?rev=357002&r1=357001&r2=357002&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java Thu Dec 15 02:57:45 2005
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.fop.fo.FONode;
 import org.apache.fop.traits.MinOptMax;
 
 /**
@@ -427,9 +428,11 @@
                         log.debug("first part doesn't fit into line, recovering: " 
                                 + node.fitRecoveryCounter);
                         if (node.fitRecoveryCounter > getMaxRecoveryAttempts()) {
-                            throw new RuntimeException("Some content could not fit "
+                            FONode contextFO = findContextFO(par, node.position + 1);
+                            throw new RuntimeException(FONode.decorateWithContextInfo(
+                                    "Some content could not fit "
                                     + "into a line/page after " + getMaxRecoveryAttempts() 
-                                    + " attempts. Giving up to avoid an endless loop.");
+                                    + " attempts. Giving up to avoid an endless loop.", contextFO));
                         }
                     } else {
                         lastForced = lastTooLong;
@@ -462,6 +465,33 @@
 
         activeLines = null;
         return line;
+    }
+
+    /**
+     * This method tries to find the context FO for a position in a KnuthSequence.
+     * @param seq the KnuthSequence to inspect
+     * @param position the index of the position in the KnuthSequence
+     * @return the requested context FO note or null, if no context node could be determined
+     */
+    private FONode findContextFO(KnuthSequence seq, int position) {
+        KnuthElement el = seq.getElement(position);
+        while (el.getLayoutManager() == null && position < seq.size() - 1) {
+            position++;
+            el = seq.getElement(position);
+        }
+        Position pos = (el != null ? el.getPosition() : null);
+        LayoutManager lm = (pos != null ? pos.getLM() : null);
+        while (pos instanceof NonLeafPosition) {
+            pos = ((NonLeafPosition)pos).getPosition();
+            if (pos != null && pos.getLM() != null) {
+                lm = pos.getLM();
+            }
+        }
+        if (lm != null) {
+            return lm.getFObj();
+        } else {
+            return null;
+        }
     }
 
     protected void initialize() {



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org