You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2007/07/19 11:57:11 UTC

svn commit: r557541 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java

Author: vhennebert
Date: Thu Jul 19 02:57:10 2007
New Revision: 557541

URL: http://svn.apache.org/viewvc?view=rev&rev=557541
Log:
Use an iterator instead of get(index) to iterate over the list of Knuth elements

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java?view=diff&rev=557541&r1=557540&r2=557541
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java Thu Jul 19 02:57:10 2007
@@ -20,6 +20,7 @@
 package org.apache.fop.layoutmgr.table;
 
 import java.util.List;
+import java.util.ListIterator;
 
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.KnuthBox;
@@ -30,6 +31,8 @@
         private PrimaryGridUnit pgu;
         /** Knuth elements for this active cell. */
         private List elementList;
+        /** Iterator over the Knuth element list. */
+        private ListIterator knuthIter;
         private boolean prevIsBox = false;
         /** Number of the row where the row-span ends, zero-based. */
         private int endRow;
@@ -80,6 +83,7 @@
 //                    log.trace("column " + (column+1) + ": recording " + elementLists.size() + " element(s)");
 //                }
             }
+            knuthIter = elementList.listIterator();
             includedLength = -1;  // Avoid troubles with cells having content of zero length
             this.previousRowsLength = previousRowsLength;
             width = previousRowsLength;
@@ -120,9 +124,8 @@
         private void goToNextLegalBreak() {
             lastPenaltyLength = 0;
             boolean breakFound = false;
-            while (!breakFound && end + 1 < elementList.size()) {
-                end++;
-                KnuthElement el = (KnuthElement)elementList.get(end);
+            while (!breakFound && knuthIter.hasNext()) {
+                KnuthElement el = (KnuthElement) knuthIter.next();
                 if (el.isPenalty()) {
                     prevIsBox = false;
                     if (el.getP() < KnuthElement.INFINITE) {
@@ -143,6 +146,7 @@
                     width += el.getW();
                 }
             }
+            end = knuthIter.nextIndex() - 1;
         }
 
         int getNextStep() {
@@ -150,8 +154,7 @@
                 return width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter;
             } else {
                 start = end + 1;
-                if (end < elementList.size() - 1) {
-
+                if (knuthIter.hasNext()) {
                     goToNextLegalBreak();
                     return width + lastPenaltyLength + borderBefore + borderAfter + paddingBefore + paddingAfter; 
                 } else {
@@ -176,15 +179,18 @@
 
         private void computeRemainingLength() {
             remainingLength = totalLength - width;
-            int index = end + 1;
-            while (index < elementList.size()) {
-                KnuthElement el = (KnuthElement)elementList.get(index);
-                if (el.isBox()) {
-                    break;
-                } else if (el.isGlue()) {
+            // Save the current location in the element list
+            int oldIndex = knuthIter.nextIndex();
+            KnuthElement el;
+            while (knuthIter.hasNext()
+                    && !(el = (KnuthElement) knuthIter.next()).isBox()) {
+                if (el.isGlue()) {
                     remainingLength -= el.getW();
                 }
-                index++;
+            }
+            // Reset the iterator to the current location
+            while (knuthIter.nextIndex() > oldIndex) {
+                knuthIter.previous();
             }
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org