]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Avoid an IndexOutOfBoundsException when more columns are used than are specified...
authorJeremias Maerki <jeremias@apache.org>
Fri, 23 Mar 2007 09:19:04 +0000 (09:19 +0000)
committerJeremias Maerki <jeremias@apache.org>
Fri, 23 Mar 2007 09:19:04 +0000 (09:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@521640 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java
test/layoutengine/standard-testcases/table-column_missing.xml [new file with mode: 0644]

index b7f29a74485f81c7ee6fe615883365de0b2a96ff..eb91f71752dcd88ceb8e5840ce08c355c086423f 100644 (file)
@@ -221,8 +221,14 @@ public class ColumnSetup {
     public int getXOffset(int col, PercentBaseContext context) {
         int xoffset = 0;
         for (int i = col; --i >= 0;) {
-            if (colWidths.get(i) != null) {
-                xoffset += ((Length) colWidths.get(i)).getValue(context);
+            int effCol;
+            if (i < colWidths.size()) {
+                effCol = i;
+            } else {
+                effCol = colWidths.size() - 1;
+            }
+            if (colWidths.get(effCol) != null) {
+                xoffset += ((Length) colWidths.get(effCol)).getValue(context);
             }
         }
         return xoffset;
diff --git a/test/layoutengine/standard-testcases/table-column_missing.xml b/test/layoutengine/standard-testcases/table-column_missing.xml
new file mode 100644 (file)
index 0000000..01521bf
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+  Licensed to the Apache Software Foundation (ASF) under one or more\r
+  contributor license agreements.  See the NOTICE file distributed with\r
+  this work for additional information regarding copyright ownership.\r
+  The ASF licenses this file to You under the Apache License, Version 2.0\r
+  (the "License"); you may not use this file except in compliance with\r
+  the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+  Unless required by applicable law or agreed to in writing, software\r
+  distributed under the License is distributed on an "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  See the License for the specific language governing permissions and\r
+  limitations under the License.\r
+-->\r
+<!-- $Id$ -->\r
+<testcase>\r
+  <info>\r
+    <p>\r
+      This test checks if FOP can handle the case where more columns are actually used than\r
+      specified.\r
+    </p>\r
+    <p>
+      Note: This test case is technically wrong since in fixed table layout all\r
+      column-widths must be specified. But we don't want to have FOP crash\r
+      with an IndexOutOfBoundsException either.
+    </p>\r
+  </info>\r
+  <fo>\r
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">\r
+      <fo:layout-master-set>\r
+        <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">\r
+          <fo:region-body/>\r
+        </fo:simple-page-master>\r
+      </fo:layout-master-set>\r
+      <fo:page-sequence master-reference="normal">\r
+        <fo:flow flow-name="xsl-region-body">\r
+          <fo:table table-layout="fixed" width="100%" border-collapse="separate">\r
+            <fo:table-column width="2cm"/>\r
+            <fo:table-body>\r
+              <fo:table-row>\r
+                <fo:table-cell>\r
+                  <fo:block>cell 1/1</fo:block>\r
+                </fo:table-cell>\r
+              </fo:table-row>\r
+              <fo:table-row>\r
+                <fo:table-cell>\r
+                  <fo:block>cell 2/1</fo:block>\r
+                </fo:table-cell>\r
+                <fo:table-cell>\r
+                  <fo:block>cell 2/2</fo:block>\r
+                </fo:table-cell>\r
+                <fo:table-cell>\r
+                  <fo:block>cell 2/3</fo:block>\r
+                </fo:table-cell>\r
+              </fo:table-row>\r
+            </fo:table-body>\r
+          </fo:table>\r
+        </fo:flow>\r
+      </fo:page-sequence>\r
+    </fo:root>\r
+  </fo>\r
+  <checks>\r
+    <eval expected="14400" xpath="//flow/block/block[2]/@top-offset"/>\r
+    <eval expected="14400" xpath="//flow/block/block[3]/@top-offset"/>\r
+    <eval expected="14400" xpath="//flow/block/block[4]/@top-offset"/>\r
+\r
+    <eval expected="360000" xpath="//flow/block/block[3]/@left-offset"/>\r
+    <eval expected="720000" xpath="//flow/block/block[4]/@left-offset"/>\r
+    <eval expected="360000" xpath="//flow/block/block[3]/@ipd"/>\r
+    <eval expected="360000" xpath="//flow/block/block[4]/@ipd"/>\r
+  </checks>\r
+</testcase>\r