]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Update for initial-values of column-number + some pending style-violation corrections
authorAndreas L. Delmelle <adelmelle@apache.org>
Tue, 20 Sep 2005 19:29:31 +0000 (19:29 +0000)
committerAndreas L. Delmelle <adelmelle@apache.org>
Tue, 20 Sep 2005 19:29:31 +0000 (19:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@290540 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/flow/Table.java
src/java/org/apache/fop/fo/flow/TableBody.java
src/java/org/apache/fop/fo/flow/TableCell.java
src/java/org/apache/fop/fo/flow/TableColumn.java
src/java/org/apache/fop/fo/flow/TableFObj.java
src/java/org/apache/fop/fo/flow/TableRow.java
test/fotree/testcases/column-number_cells_body.fo
test/fotree/testcases/column-number_cells_body2.fo [new file with mode: 0644]
test/fotree/testcases/column-number_cells_out-of-order.fo
test/fotree/testcases/column-number_cells_rows.fo
test/fotree/testcases/column-number_columns_special.fo

index 474efc6b7a6b7d44477991d5ba139f6d2268091b..f65a68f580f936791e0cf76025ff6e8e8c0c7a38 100644 (file)
@@ -427,6 +427,7 @@ public class Table extends TableFObj {
      * (used by TableColumn.bind() in case the column-number
      * was explicitly specified)
      * 
+     * @param   newIndex    the new value for column index
      */
     protected void setCurrentColumnIndex(int newIndex) {
         columnIndex = newIndex;
index 460e7b803aafb9f667128a078b3b7dfd5bc5be5c..8d8cd53a23a558619a3958748cb19b01dacecaab 100644 (file)
@@ -50,11 +50,15 @@ public class TableBody extends TableFObj {
     
     private PropertyList savedPropertyList;
 
-    //used for validation
+    /**
+     * used for validation
+     */
     protected boolean tableRowsFound = false;
     protected boolean tableCellsFound = false;
     
-    //used for initial values of column-number property
+    /**
+     * used for initial values of column-number property
+     */
     protected List pendingSpans;
     protected BitSet usedColumnIndices = new BitSet();
     private int columnIndex = 1;
@@ -175,7 +179,7 @@ public class TableBody extends TableFObj {
         int colSpan = cell.getNumberColumnsSpanned();
         //if there were no explicit columns, pendingSpans
         //will not be properly initialized for the first row
-        if (firstRow && ((Table) parent).columns == null) {
+        if (firstRow && getTable().columns == null) {
             if (pendingSpans == null) {
                 pendingSpans = new java.util.ArrayList();
             }
@@ -198,8 +202,8 @@ public class TableBody extends TableFObj {
         //take up more than three columnIndices...
         int startIndex = columnIndex - 1;
         int endIndex = startIndex + colSpan;
-        if (((Table) parent).columns != null) {
-            List cols = ((Table) parent).columns;
+        if (getTable().columns != null) {
+            List cols = getTable().columns;
             int tmpIndex = endIndex;
             for (int i = startIndex; i <= tmpIndex; ++i) {
                 if (i < cols.size() && cols.get(i) == null) {
@@ -298,8 +302,8 @@ public class TableBody extends TableFObj {
      *
      */
     protected void initPendingSpans() {
-        if (((Table) parent).columns != null) {
-            List tableCols = ((Table) parent).columns;
+        if (getTable().columns != null) {
+            List tableCols = getTable().columns;
             pendingSpans = new java.util.ArrayList(tableCols.size());
             for (int i = tableCols.size(); --i >= 0;) {
                 pendingSpans.add(null);
@@ -362,9 +366,9 @@ public class TableBody extends TableFObj {
             //the updated index is not assigned to any
             //column, increment further until the next
             //index occupied by a column...
-            if (((Table) parent).columns != null) {
-                while (columnIndex <= ((Table) parent).columns.size()
-                        && !((Table) parent).isColumnNumberUsed(columnIndex) ) {
+            if (getTable().columns != null) {
+                while (columnIndex <= getTable().columns.size()
+                        && !getTable().isColumnNumberUsed(columnIndex) ) {
                     columnIndex++;
                 }
             }
@@ -396,6 +400,6 @@ public class TableBody extends TableFObj {
      */
     protected boolean isColumnNumberUsed(int colNr) {
         return usedColumnIndices.get(colNr - 1);
-    }
+    }    
 }
 
index 7fb8f8b28ead7529ab8923a6ea23d79f77227100..fa03a0f88a889010ec6c40cc3199297ce5354bcf 100644 (file)
@@ -133,17 +133,29 @@ public class TableCell extends TableFObj {
         
         //check if any of the column-numbers occupied by this cell
         //are already in use in the current row...
-        for( int i = getColumnNumber(); 
-                ++i <= getColumnNumber() + getNumberColumnsSpanned(); ) {
-            if( ((TableFObj) parent).isColumnNumberUsed(i - 1) ) {
-                throw new FOPException("cell overlaps in column " + (i - 1),
-                              locator);
+        int i = -1;
+        int columnIndex = columnNumber.getValue();
+        while (++i < getNumberColumnsSpanned()) {
+            //if table has explicit columns and the column-number isn't
+            //assigned to any column, increment further until the next
+            //column is encountered
+            if (getTable().columns != null) {
+                while (columnIndex <= getTable().columns.size()
+                        && !getTable().isColumnNumberUsed(columnIndex)) {
+                    columnIndex++;
+                }
+            }
+            //if column-number is already in use by another cell
+            //in the current row => error!
+            if (((TableFObj) parent).isColumnNumberUsed(columnIndex)) {
+                throw new FOPException("fo:table-cell overlaps in column "
+                        + i, locator);
             }
         }
         //if column-number was explicitly specified, force the parent's current
         //column index to the specified value, so that the updated index will
         //be the correct initial value for the next cell (see Rec 7.26.8)
-        if( pList.getExplicit(PR_COLUMN_NUMBER) != null ) {
+        if (pList.getExplicit(PR_COLUMN_NUMBER) != null) {
             ((TableFObj) parent).setCurrentColumnIndex(columnNumber.getValue());
         }
     }
@@ -165,7 +177,7 @@ public class TableCell extends TableFObj {
         if (!blockItemFound) {
             missingChildElementError("marker* (%block;)+");
         }
-        if(startsRow() || endsRow()) 
+        if ((startsRow() || endsRow()) 
                 && getParent().getNameId() == FO_TABLE_ROW ) {
             getLogger().warn("starts-row/ends-row for fo:table-cells "
                     + "non-applicable for children of an fo:table-row.");
@@ -192,6 +204,8 @@ public class TableCell extends TableFObj {
 
     /**
      * Set position relative to table (set by body?)
+     * 
+     * @param offset    new offset
      */
     public void setStartOffset(int offset) {
         startOffset = offset;
index 107c1df7f58bb122462303655e435655df779c15..c7b7eab6f1a57c87605ccb3f6e686f39ae84ebf7 100644 (file)
@@ -75,7 +75,7 @@ public class TableColumn extends TableFObj {
         visibility = pList.get(PR_VISIBILITY).getEnum();
         super.bind(pList);
         
-        if( pList.getExplicit(PR_COLUMN_NUMBER) != null ) {
+        if (pList.getExplicit(PR_COLUMN_NUMBER) != null) {
             if (columnNumber.getValue() <= 0) {
                 //TODO: This is actually a non-fatal error. See Rec 7.26.8:
                 //"A positive integer. If a negative or non-integer value 
@@ -83,7 +83,7 @@ public class TableColumn extends TableFObj {
                 // nearest integer value greater than or equal to 1."
                 throw new PropertyException("column-number must be 1 or bigger, "
                         + "but got " + columnNumber);
-            } else if( ((Table) parent).isColumnNumberUsed(columnNumber.getValue()) ) {
+            } else if (getTable().isColumnNumberUsed(columnNumber.getValue())) {
                 throw new PropertyException("specified column-number \""
                         + columnNumber 
                         + "\" has already been assigned to a previous column");
@@ -92,7 +92,7 @@ public class TableColumn extends TableFObj {
                 //to the specified value, so that the updated index
                 //will be the correct initial value for the next column
                 //(see Rec 7.26.8)
-                ((Table) parent).setCurrentColumnIndex(columnNumber.getValue());
+                getTable().setCurrentColumnIndex(columnNumber.getValue());
             }
         }
         if (numberColumnsRepeated.getValue() <= 0) {
index f042e0f96eae3a2749f34ffc770bf9857c0fbd06..8bd88d386fd7bda1c163880908bb00e7fa6968b4 100644 (file)
@@ -45,6 +45,9 @@ public abstract class TableFObj extends FObj {
      */
     protected static class PendingSpan {
         
+        /**
+         * member variable holding the number of rows left
+         */
         protected int rowsLeft;
         
         /**
@@ -129,6 +132,38 @@ public abstract class TableFObj extends FObj {
         return false;
     }
     
+    /**
+     * Checks whether a given column-number is assigned to 
+     * an explicit column in the parent table
+     * (overridden for TableBody, TableRow)
+     * 
+     * @param colNr the column-number to check
+     * @return true if the table has explicit columns, and
+     *              the column-number is in use
+     */
+    protected boolean isColumnNumberUsedInTable(int colNr) {
+        return false;
+    }
+    
+    /**
+     * Convenience method to returns a reference 
+     * to the base Table instance
+     * 
+     * @return  the base table instance
+     * 
+     */
+    protected Table getTable() {
+        if (this.getNameId() == FO_TABLE) {
+            //node is a Table
+            //=> return itself
+            return (Table) this;
+        } else {
+            //any other Table-node
+            //=> recursive call to parent.getTable()
+            return ((TableFObj) parent).getTable();
+        }
+    }
+    
     /**
      * @return the Common Border, Padding, and Background Properties.
      */
index 18baabf2cdad43229ab0fe3ee5162f1c4ff70f13..3081e1632c649a20d358abc3b2156ce49bd7ffd0 100644 (file)
@@ -109,7 +109,7 @@ public class TableRow extends TableFObj {
     protected void startOfNode() throws FOPException {
         pendingSpans = ((TableBody) parent).pendingSpans;
         usedColumnIndices = ((TableBody) parent).usedColumnIndices;
-        while( usedColumnIndices.get(columnIndex - 1) ) {
+        while (usedColumnIndices.get(columnIndex - 1)) {
             columnIndex++;
         }
         
@@ -124,8 +124,8 @@ public class TableRow extends TableFObj {
         if (childNodes == null) {
             missingChildElementError("(table-cell+)");
         }
-        if((TableBody) parent).isFirst(this) 
-                && ((Table) parent.getParent()).columns == null ) {
+        if (((TableBody) parent).isFirst(this) 
+                && getTable().columns == null ) {
             //force parent body's pendingSpans
             //to the one accumulated after processing this row
             ((TableBody) parent).pendingSpans = pendingSpans;
@@ -155,20 +155,20 @@ public class TableRow extends TableFObj {
         TableCell cell = (TableCell) child;
         int rowSpan = cell.getNumberRowsSpanned();
         int colSpan = cell.getNumberColumnsSpanned();
-        if((TableBody) parent).isFirst(this) 
-                && ((Table) parent.getParent()).columns == null ) {
-            if( pendingSpans == null ) {
+        if (((TableBody) parent).isFirst(this) 
+                && getTable().columns == null ) {
+            if (pendingSpans == null) {
                 pendingSpans = new java.util.ArrayList();
             }
             pendingSpans.add(null);
-            if( usedColumnIndices == null ) {
+            if (usedColumnIndices == null) {
                 usedColumnIndices = new BitSet();
             }
         }
         //if the current cell spans more than one row,
         //update pending span list for the next row
-        if( rowSpan > 1 ) {
-            for( int i = colSpan; --i >= 0; ) {
+        if (rowSpan > 1) {
+            for (int i = colSpan; --i >= 0;) {
                 pendingSpans.set(columnIndex - 1 + i, 
                         new PendingSpan(rowSpan));
             }
@@ -180,18 +180,18 @@ public class TableRow extends TableFObj {
         //take up more than three columnIndices...
         int startIndex = columnIndex - 1;
         int endIndex = startIndex + colSpan;
-        if( ((Table) parent.getParent()).columns != null ) {
-            List cols = ((Table) parent.getParent()).columns;
+        if (getTable().columns != null) {
+            List cols = getTable().columns;
             int tmpIndex = endIndex;
-            for( int i = startIndex; i <= tmpIndex; ++i ) {
-                if( i < cols.size() && cols.get(i) == null ) {
+            for (int i = startIndex; i <= tmpIndex; ++i) {
+                if (i < cols.size() && cols.get(i) == null) {
                     endIndex++;
                 }
             }
         }
         usedColumnIndices.set(startIndex, endIndex);
         //update columnIndex for the next cell
-        while( usedColumnIndices.get(columnIndex - 1) ) {
+        while (usedColumnIndices.get(columnIndex - 1)) {
             columnIndex++;
         }
         super.addChildNode(cell);
@@ -301,6 +301,7 @@ public class TableRow extends TableFObj {
      * in case a column-number was explicitly specified
      * (used by TableCell.bind())
      * 
+     * @param newIndex  new value for column index
      */
     protected void setCurrentColumnIndex(int newIndex) {
         columnIndex = newIndex;
@@ -310,6 +311,7 @@ public class TableRow extends TableFObj {
      * Checks whether a given column-number is already in use
      * for the current row (used by TableCell.bind());
      * 
+     * @param colNr the column-number to check
      * @return true if column-number is already occupied
      */
     protected boolean isColumnNumberUsed(int colNr) {
index 97cfb2e1eb3358326da6d6e606e4c81cf5f7446c..4d9de66727bb89d40c9b3b0cd52e444d0ab610bd 100644 (file)
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id: $ -->
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
          xmlns:test="http://xmlgraphics.apache.org/fop/test">
   <fo:layout-master-set>
diff --git a/test/fotree/testcases/column-number_cells_body2.fo b/test/fotree/testcases/column-number_cells_body2.fo
new file mode 100644 (file)
index 0000000..3b5d061
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id: $ -->
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
+         xmlns:test="http://xmlgraphics.apache.org/fop/test">
+  <fo:layout-master-set>
+  <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">
+    <fo:region-body />
+  </fo:simple-page-master>
+  </fo:layout-master-set>
+  <fo:page-sequence master-reference="normal" white-space-collapse="true">
+    <fo:flow flow-name="xsl-region-body">
+      <fo:table table-layout="fixed" border-collapse="separate">
+        <fo:table-column column-width="2in">
+          <test:assert property="column-number" expected="1" />
+        </fo:table-column>
+        <fo:table-column column-width="1in">
+          <test:assert property="column-number" expected="2" />
+        </fo:table-column>
+        <fo:table-column column-width="1in">
+          <test:assert property="column-number" expected="3" />
+        </fo:table-column>
+        <fo:table-column column-width="1in">
+          <test:assert property="column-number" expected="4" />
+        </fo:table-column>
+        <fo:table-body>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="1" />
+            <fo:block>cell1</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="2" />
+            <fo:block>cell2</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="3" />
+            <fo:block>cell3</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="4" />
+            <fo:block>cell4</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="5" />
+            <fo:block>cell5</fo:block>
+          </fo:table-cell>
+          <fo:table-cell starts-row="true">
+            <test:assert property="column-number" expected="1" />
+            <fo:block>cell6</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="2" />
+            <fo:block>cell7</fo:block>
+          </fo:table-cell>
+          <fo:table-cell ends-row="true">
+            <test:assert property="column-number" expected="3" />
+            <fo:block>cell8</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="1" />
+            <fo:block>cell9</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="2" />
+            <fo:block>cell10</fo:block>
+          </fo:table-cell>
+          <fo:table-cell>
+            <test:assert property="column-number" expected="3" />
+            <fo:block>cell11</fo:block>
+          </fo:table-cell>
+          <fo:table-cell ends-row="true">
+            <test:assert property="column-number" expected="4" />
+            <fo:block>cell12</fo:block>
+          </fo:table-cell>
+          <fo:table-cell starts-row="true" ends-row="true">
+            <test:assert property="column-number" expected="1" />
+            <fo:block>cell13</fo:block>
+          </fo:table-cell>
+          <fo:table-cell ends-row="true">
+            <test:assert property="column-number" expected="1" />
+            <fo:block>cell14</fo:block>
+          </fo:table-cell>
+        </fo:table-body>
+      </fo:table>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
index 83f0dec4b17ab5ea4bf7146474d9974c378afca0..841d71f7bacb5183deb3177cda3dd6143a7dbcdc 100644 (file)
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id: $ -->
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
          xmlns:test="http://xmlgraphics.apache.org/fop/test">
   <fo:layout-master-set>
index b7f901cd5bb1913d22465c9f2be4380eeac2c2a0..62b3b620f01ff585bfea35b34e635f9ee0221c77 100644 (file)
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id: $ -->
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
          xmlns:test="http://xmlgraphics.apache.org/fop/test">
   <fo:layout-master-set>
index 5adceca9bb441c0afdda5457819e965b0d82bd84..7787b9d9137aaa899d04cca55f584b106fd2445f 100644 (file)
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id: $ -->
 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
          xmlns:test="http://xmlgraphics.apache.org/fop/test">
   <fo:layout-master-set>