* @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;
+ }
}
/**
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fo.FONode;
import org.apache.fop.traits.MinOptMax;
/**
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;
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;