diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-12-13 19:48:04 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-12-13 19:48:04 +0000 |
commit | 32521d94ac717c6f07f4d45607d1d049c839c42c (patch) | |
tree | 4c405a9bc0abee3e33031a242d9e0eb7dd2024c8 /src | |
parent | 97233ecb13be21d14b04265c31023b6a759e9d71 (diff) | |
download | xmlgraphics-fop-32521d94ac717c6f07f4d45607d1d049c839c42c.tar.gz xmlgraphics-fop-32521d94ac717c6f07f4d45607d1d049c839c42c.zip |
New method: FONode.decorateWithContextInfo() adds context information to an error or log message by either providing the locator information or by gathering context information from the context FOs.
Improved log and error messages in a number of places by adding additional context information that should make it easier to find the location in the source files.
Added a check to detect inline overflows (LineLayoutManager).
Added a check to detect in-page overflows (PageBreakingAlgorithm).
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@356592 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
9 files changed, 149 insertions, 19 deletions
diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index f321dc663..eeab9f407 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -449,6 +449,57 @@ public abstract class FONode implements Cloneable { } /** + * Decorates a log or warning message with context information on the given node. + * @param text the original message + * @param node the context node + * @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(); + } + + /** + * Returns a String containing as much context information as possible about a node. Call + * this methods only in exceptional conditions because this method may perform quite extensive + * information gathering inside the FO tree. + * @return a String containing + */ + public String getContextInfo() { + StringBuffer sb = new StringBuffer(); + if (getLocalName() != null) { + sb.append(getName()); + sb.append(", "); + } + if (this.locator != null) { + sb.append("location: "); + sb.append(getLocatorString(this.locator)); + } else { + String s = gatherContextInfo(); + if (s != null) { + sb.append("\""); + sb.append(s); + sb.append("\""); + } else { + sb.append("no context info available"); + } + } + if (sb.length() > 80) { + sb.setLength(80); + } + return sb.toString(); + } + + /** + * Gathers context information for the getContextInfo() method. + * @return the collected context information or null, if none is available + */ + protected String gatherContextInfo() { + return null; + } + + /** * Returns the root node of this tree * @return the root node */ diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index f168d9693..7a75f68da 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -617,5 +617,14 @@ public class FOText extends FONode { public String getNormalNamespacePrefix() { return null; } + + /** @see org.apache.fop.fo.FONode#gatherContextInfo() */ + protected String gatherContextInfo() { + if (getLocator() != null) { + return super.gatherContextInfo(); + } else { + return new String(ca).trim(); + } + } }
\ No newline at end of file diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index fb6bf0820..549f03c58 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -316,6 +316,30 @@ public abstract class FObj extends FONode implements Constants { } */ + /** @see org.apache.fop.fo.FONode#gatherContextInfo() */ + protected String gatherContextInfo() { + if (getLocator() != null) { + return super.gatherContextInfo(); + } else { + ListIterator iter = getChildNodes(); + if (iter == null) { + return null; + } + StringBuffer sb = new StringBuffer(); + while (iter.hasNext()) { + FONode node = (FONode)iter.next(); + String s = node.gatherContextInfo(); + if (s != null) { + if (sb.length() > 0) { + sb.append(", "); + } + sb.append(s); + } + } + return (sb.length() > 0 ? sb.toString() : null); + } + } + /** * Convenience method for validity checking. Checks if the * incoming node is a member of the "%block;" parameter entity diff --git a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java index 5a9ede6eb..ced5d620a 100644 --- a/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java +++ b/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.ListIterator; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition; import org.apache.fop.traits.MinOptMax; @@ -697,14 +699,31 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { pageBreaks.addFirst(pageBreak); } + private int getPartCount() { + if (pageBreaks == null) { + return 0; + } else { + return pageBreaks.size(); + } + } + public void updateData1(int total, double demerits) { } public void updateData2(KnuthNode bestActiveNode, KnuthSequence sequence, int total) { - //int difference = (bestActiveNode.line < total) ? bestActiveNode.difference : bestActiveNode.difference + fillerMinWidth; + //int difference = (bestActiveNode.line < total) + // ? bestActiveNode.difference : bestActiveNode.difference + fillerMinWidth; int difference = bestActiveNode.difference; + if (difference + bestActiveNode.availableShrink < 0) { + if (log.isWarnEnabled()) { + log.warn(FONode.decorateWithContextInfo( + "Part/page " + (getPartCount() + 1) + + " overflows the available area in block-progression dimension.", + getFObj())); + } + } int blockAlignment = (bestActiveNode.line < total) ? alignment : alignmentLast; // it is always allowed to adjust space, so the ratio must be set regardless of // the value of the property display-align; the ratio must be <= 1 @@ -771,6 +790,11 @@ class PageBreakingAlgorithm extends BreakingAlgorithm { return (LinkedList) footnotesList.get(index); } + /** @return the associated top-level formatting object. */ + public FObj getFObj() { + return topLevelLM.getFObj(); + } + /** @see org.apache.fop.layoutmgr.BreakingAlgorithm#getLineWidth(int) */ protected int getLineWidth(int line) { int bpd; diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java index 6fe1bf5f1..dbf9290c2 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java @@ -21,6 +21,7 @@ package org.apache.fop.layoutmgr.inline; import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.Numeric; import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FONode; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.properties.CommonHyphenation; import org.apache.fop.hyphenation.Hyphenation; @@ -435,12 +436,23 @@ public class LineLayoutManager extends InlineStackingLayoutManager addedPositions = 0; } - //log.debug("LLM> (" + (lineLayouts.getLineNumber(activePossibility) - addedPositions) + ") difference = " + difference + " ratio = " + ratio); + if (difference + bestActiveNode.availableShrink < 0) { + if (log.isWarnEnabled()) { + log.warn(FONode.decorateWithContextInfo( + "Line " + (addedPositions + 1) + + " of a paragraph overflows the available area.", getFObj())); + } + } + + //log.debug("LLM> (" + (lineLayouts.getLineNumber(activePossibility) - addedPositions) + // + ") difference = " + difference + " ratio = " + ratio); lineLayouts.addBreakPosition(makeLineBreakPosition(par, - (bestActiveNode.line > 1 ? bestActiveNode.previous.position + 1: 0), - bestActiveNode.position, - bestActiveNode.availableShrink - (addedPositions > 0 ? 0 : ((Paragraph)par).lineFiller.opt - ((Paragraph)par).lineFiller.min), bestActiveNode.availableStretch, difference, ratio, indent), - activePossibility); + (bestActiveNode.line > 1 ? bestActiveNode.previous.position + 1 : 0), + bestActiveNode.position, + bestActiveNode.availableShrink - (addedPositions > 0 + ? 0 : ((Paragraph)par).lineFiller.opt - ((Paragraph)par).lineFiller.min), + bestActiveNode.availableStretch, + difference, ratio, indent), activePossibility); addedPositions++; } @@ -453,7 +465,9 @@ public class LineLayoutManager extends InlineStackingLayoutManager private LineBreakPosition makeLineBreakPosition(KnuthSequence par, int firstElementIndex, int lastElementIndex, - int availableShrink, int availableStretch, int difference, + int availableShrink, + int availableStretch, + int difference, double ratio, int indent) { // line height calculation - spaceBefore may differ from spaceAfter diff --git a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java index c49c35760..00784fc5c 100644 --- a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java +++ b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.datatypes.PercentBaseContext; +import org.apache.fop.fo.FONode; import org.apache.fop.fo.flow.Table; import org.apache.fop.fo.flow.TableColumn; @@ -96,10 +97,11 @@ public class ColumnSetup { if (index > maxColIndexReferenced) { maxColIndexReferenced = index; if (!(size == 1 && getColumn(1).isDefaultColumn())) { - log.warn("There are fewer table-columns than are needed. Column " + log.warn(FONode.decorateWithContextInfo( + "There are fewer table-columns than are needed. Column " + index + " was accessed although only " + size + " columns have been defined. " - + "The last defined column will be reused."); + + "The last defined column will be reused.", table)); if (!table.isAutoLayout()) { log.warn("Please note that according XSL-FO 1.0 (7.26.9) says that " + "the 'column-width' property must be specified for every " diff --git a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java index 9b2d8e0f2..511c8559a 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java @@ -30,6 +30,7 @@ import org.apache.fop.area.Block; import org.apache.fop.area.Trait; import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.flow.Table; import org.apache.fop.fo.flow.TableBody; @@ -478,7 +479,7 @@ public class TableContentLayoutManager implements PercentBaseContext { if ((elems.size() > 0) && ((KnuthElement)elems.getLast()).isForcedBreak()) { // a descendant of this block has break-after - log.warn("Descendant of table-cell signals break: " + log.debug("Descendant of table-cell signals break: " + primary.getCellLM().isFinished()); } @@ -556,12 +557,14 @@ public class TableContentLayoutManager implements PercentBaseContext { row.setHeight(rowHeights[rgi]); row.setExplicitHeight(explicitRowHeights[rgi]); if (effRowContentHeight > row.getExplicitHeight().max) { - log.warn("The contents of row " + (row.getIndex() + 1) + log.warn(FONode.decorateWithContextInfo( + "The contents of row " + (row.getIndex() + 1) + " are taller than they should be (there is a" + " block-progression-dimension or height constraint on the indicated row)." + " Due to its contents the row grows" + " to " + effRowContentHeight + " millipoints, but the row shouldn't get" - + " any taller than " + row.getExplicitHeight() + " millipoints."); + + " any taller than " + row.getExplicitHeight() + " millipoints.", + row.getTableRow())); } } if (log.isDebugEnabled()) { diff --git a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java index f290c175a..554ae4069 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java @@ -25,7 +25,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.fop.fo.Constants; -import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.FONode; import org.apache.fop.fo.flow.TableRow; import org.apache.fop.layoutmgr.BreakElement; import org.apache.fop.layoutmgr.ElementListUtils; @@ -418,8 +418,9 @@ public class TableStepper { if (activeRow < rowGroup.length - 1) { TableRow rowFO = getActiveRow().getTableRow(); if (rowFO != null && rowFO.getBreakAfter() != Constants.EN_AUTO) { - log.warn("break-after ignored on table-row because of row spanning " - + "in progress (See XSL 1.0, 7.19.1)"); + log.warn(FONode.decorateWithContextInfo( + "break-after ignored on table-row because of row spanning " + + "in progress (See XSL 1.0, 7.19.1)", rowFO)); } activeRow++; if (log.isDebugEnabled()) { @@ -433,8 +434,9 @@ public class TableStepper { } rowFO = getActiveRow().getTableRow(); if (rowFO != null && rowFO.getBreakBefore() != Constants.EN_AUTO) { - log.warn("break-before ignored on table-row because of row spanning " - + "in progress (See XSL 1.0, 7.19.2)"); + log.warn(FONode.decorateWithContextInfo( + "break-before ignored on table-row because of row spanning " + + "in progress (See XSL 1.0, 7.19.2)", rowFO)); } } } @@ -450,7 +452,7 @@ public class TableStepper { KnuthElement el = (KnuthElement)elementLists[i].get(end[i]); if (el.isPenalty()) { if (el.getP() <= -KnuthElement.INFINITE) { - log.warn("FORCED break encountered!"); + log.debug("FORCED break encountered!"); forcedBreaks[i] = true; break; } else if (el.getP() < KnuthElement.INFINITE) { diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 7552d8e7d..d317ffe50 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -947,7 +947,8 @@ public class RTFHandler extends FOEventHandler { rawData = fopimage.getRessourceBytes(); } if (rawData == null) { - log.warn("Image could not be embedded: " + url); + log.warn(FONode.decorateWithContextInfo( + "Image could not be embedded: " + url, eg)); return; } |