diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-12-15 10:57:45 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-12-15 10:57:45 +0000 |
commit | 3377a2e7a34fdd28fec46ac57ca9476b9e0922be (patch) | |
tree | dffb3fa01f7d35c80f433974a9de9dcf52fec4bd /src | |
parent | a952810ccb6730a7e533809eb9fdd29e34fadc9d (diff) | |
download | xmlgraphics-fop-3377a2e7a34fdd28fec46ac57ca9476b9e0922be.tar.gz xmlgraphics-fop-3377a2e7a34fdd28fec46ac57ca9476b9e0922be.zip |
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.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@357002 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/fop/fo/FONode.java | 10 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java | 34 |
2 files changed, 39 insertions, 5 deletions
diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index eeab9f407..84d04b2c0 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -455,9 +455,13 @@ public abstract class FONode implements Cloneable { * @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; + } } /** diff --git a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java index 92d5c08d3..c290f5b13 100644 --- a/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java +++ b/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java @@ -21,6 +21,7 @@ package org.apache.fop.layoutmgr; 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 @@ public abstract class BreakingAlgorithm { 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; @@ -464,6 +467,33 @@ public abstract class BreakingAlgorithm { 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() { this.totalWidth = 0; this.totalStretch = 0; |