]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fixed a bug in computeContentLength when there are empty cells
authorVincent Hennebert <vhennebert@apache.org>
Fri, 25 Jan 2008 15:52:53 +0000 (15:52 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Fri, 25 Jan 2008 15:52:53 +0000 (15:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@615251 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/table/RowPainter.java

index e5b90aa5f61b89ef5d4a1e6c8c00fe4c5a4c9c41..9004e9c1703a7e8f6de8e75e330afc111f0d075e 100644 (file)
@@ -234,20 +234,26 @@ class RowPainter {
     // be used as padding.
     // This should be handled automatically by a proper use of Knuth elements
     private int computeContentLength(PrimaryGridUnit pgu, int startIndex, int endIndex) {
-        int actualStart = startIndex;
-        // Skip from the content length calculation glues and penalties occurring at the
-        // beginning of the page
-        while (actualStart <= endIndex
-                && !((KnuthElement) pgu.getElements().get(actualStart)).isBox()) {
-            actualStart++;
-        }
-        int len = ElementListUtils.calcContentLength(
-                pgu.getElements(), actualStart, endIndex);
-        KnuthElement el = (KnuthElement)pgu.getElements().get(endIndex);
-        if (el.isPenalty()) {
-            len += el.getW();
+        if (startIndex >= endIndex) {
+             // May happen if the cell contributes no content on the current page (empty
+             // cell, in most cases)
+            return 0;
+        } else {
+            int actualStart = startIndex;
+            // Skip from the content length calculation glues and penalties occurring at the
+            // beginning of the page
+            while (actualStart <= endIndex
+                    && !((KnuthElement) pgu.getElements().get(actualStart)).isBox()) {
+                actualStart++;
+            }
+            int len = ElementListUtils.calcContentLength(
+                    pgu.getElements(), actualStart, endIndex);
+            KnuthElement el = (KnuthElement)pgu.getElements().get(endIndex);
+            if (el.isPenalty()) {
+                len += el.getW();
+            }
+            return len;
         }
-        return len;
     }
 
     private void addAreasForCell(PrimaryGridUnit pgu, int startPos, int endPos,