xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spepp...@apache.org
Subject svn commit: r613245 - /xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/
Date Fri, 18 Jan 2008 19:52:08 GMT
Author: spepping
Date: Fri Jan 18 11:52:06 2008
New Revision: 613245

URL: http://svn.apache.org/viewvc?rev=613245&view=rev
Log:
When in BreakingAlgorithm.considerLegalBreaks a legal linebreak is
considered, there is a forward search until the next box. ListElements
must be resolved before that search can move forward. Fixed by calling
resolveElements at that place too.

Modified:
    xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
    xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java
    xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
    xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java
    xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
    xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java?rev=613245&r1=613244&r2=613245&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
(original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
Fri Jan 18 11:52:06 2008
@@ -483,7 +483,7 @@
             if (p == 0) {
                 lastBreakClass = effectiveList.getStartOn();
             } else {
-                ListElement lastBreakElement = effectiveList.getElement(endElementIndex);
+                ListElement lastBreakElement = effectiveList.getListElement(endElementIndex);
                 if (lastBreakElement.isPenalty()) {
                     KnuthPenalty pen = (KnuthPenalty)lastBreakElement;
                     lastBreakClass = pen.getBreakClass();

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java?rev=613245&r1=613244&r2=613245&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java
(original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BlockKnuthSequence.java
Fri Jan 18 11:52:06 2008
@@ -157,6 +157,18 @@
         resolveElements(startIndex, false);
     }
     
+    /* (non-Javadoc)
+     * @see org.apache.fop.layoutmgr.KnuthSequence#resolveAndGetElement(int)
+     */
+    public KnuthElement resolveAndGetKnuthElement(int index) {
+        resolveElements(index);
+        if (index < size()) {
+            return getKnuthElement(index);
+        } else {
+            return null;
+        }
+    }
+
     /**
      * Resolve all elements in seq
      * @param seq the Knuth Sequence
@@ -179,7 +191,8 @@
      * @param doall resolve all elements or not
      */
     private void resolveElements(int startIndex, boolean doall) {
-        for (int i = startIndex; i < size(); ++i) {
+        int i;
+        for (i = startIndex; i < size(); ++i) {
             ListElement elt = (ListElement) get(i);
             if (!doall && !elt.isUnresolvedElement()
                     && !(elt instanceof LineBreakingListElement)
@@ -238,6 +251,11 @@
             }
         }
         SpaceResolver.resolveElementList(this, startIndex, doall);
+        // resolveElements may have removed element startIndex
+        // without adding any element, so that startIndex == par.size()
+        if (startIndex >= size() - 1) {
+            endBlockSequence();
+        }
     }
     
 }

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java?rev=613245&r1=613244&r2=613245&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
(original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
Fri Jan 18 11:52:06 2008
@@ -19,8 +19,6 @@
 
 package org.apache.fop.layoutmgr;
 
-import java.util.List;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.FONode;
@@ -441,9 +439,9 @@
             if (alignment != org.apache.fop.fo.Constants.EN_CENTER) {
                 while (par.size() > firstBoxIndex) {
                     // scan for unresolved elements and paragraphs
-                    par.resolveElements(firstBoxIndex);
-                    thisElement = (KnuthElement) par.get(firstBoxIndex);
-                    if (thisElement.isBox()) {
+                    // par.resolveElements(firstBoxIndex);
+                    thisElement = par.resolveAndGetKnuthElement(firstBoxIndex);
+                    if (thisElement == null || thisElement.isBox()) {
                         break;
                     }
                     firstBoxIndex++;
@@ -461,17 +459,8 @@
 
         // main loop
         for (int i = startIndex; i < par.size(); i++) {
-            par.resolveElements(i);
-            // resolveElements may have removed element i
-            // without adding any element, so that i == par.size()
-            if (i >= par.size() - 1) {
-                par.endBlockSequence();
-                if (i == par.size()) {
-                    break;
-                }
-            }
-            thisElement = (KnuthElement) par.get(i);
-            if (thisElement.isBox()) {
+            thisElement = par.resolveAndGetKnuthElement(i);
+            if (thisElement == null || thisElement.isBox()) {
                 // a KnuthBox object is not a legal line break
                 totalWidth += thisElement.getW();
                 previousIsBox = true;
@@ -594,10 +583,10 @@
      * @return the requested context FO note or null, if no context node could be determined
      */
     private FONode findContextFO(KnuthSequence seq, int position) {
-        ListElement el = seq.getElement(position);
+        ListElement el = seq.getListElement(position);
         while (el.getLayoutManager() == null && position < seq.size() - 1) {
             position++;
-            el = seq.getElement(position);
+            el = seq.getListElement(position);
         }
         Position pos = (el != null ? el.getPosition() : null);
         LayoutManager lm = (pos != null ? pos.getLM() : null);
@@ -682,7 +671,7 @@
         // these elements twice
         int restartingIndex = restartingNode.position;
         while (restartingIndex + 1 < par.size()
-               && !(getElement(restartingIndex + 1).isBox())) {
+               && !(par.getKnuthElement(restartingIndex + 1).isBox())) {
             restartingIndex++;
         }
         return restartingIndex;
@@ -762,8 +751,8 @@
                     // was just before the next box element, thus ignoring glues and
                     // penalties between the "real" break and the following box
                     for (int i = elementIdx; i < par.size(); i++) {
-                        KnuthElement tempElement = getElement(i);
-                        if (tempElement.isBox()) {
+                        KnuthElement tempElement = par.resolveAndGetKnuthElement(i);
+                        if (tempElement == null || tempElement.isBox()) {
                             break;
                         } else if (tempElement.isGlue()) {
                             newWidth += tempElement.getW();
@@ -828,7 +817,7 @@
         // was just before the next box element, thus ignoring glues and
         // penalties between the "real" break and the following box
         for (int i = elementIdx; i < par.size(); i++) {
-            KnuthElement tempElement = getElement(i);
+            KnuthElement tempElement = par.getKnuthElement(i);
             if (tempElement.isBox()) {
                 break;
             } else if (tempElement.isGlue()) {
@@ -960,8 +949,8 @@
         }
     
         if (element.isPenalty() && ((KnuthPenalty) element).isFlagged()
-            && getElement(activeNode.position).isPenalty()
-            && ((KnuthPenalty) getElement(activeNode.position)).isFlagged()) {
+            && par.getKnuthElement(activeNode.position).isPenalty()
+            && ((KnuthPenalty) par.getKnuthElement(activeNode.position)).isFlagged())
{
             // add demerit for consecutive breaks at flagged penalties
             demerits += repeatedFlaggedDemerit;
             // there are at least two consecutive lines ending with a flagged penalty;
@@ -971,7 +960,7 @@
             for (KnuthNode prevNode = activeNode.previous;
                  prevNode != null && flaggedPenaltiesCount <= maxFlaggedPenaltiesCount;
                  prevNode = prevNode.previous) {
-                KnuthElement prevElement = getElement(prevNode.position);
+                KnuthElement prevElement = par.getKnuthElement(prevNode.position);
                 if (prevElement.isPenalty()
                     && ((KnuthPenalty) prevElement).isFlagged()) {
                     // the previous line ends with a flagged penalty too
@@ -999,15 +988,6 @@
     }
 
     protected void finish() {
-    }
-
-    /**
-     * Return the element at index idx in the paragraph.
-     * @param idx index of the element.
-     * @return the element at index idx in the paragraph.
-     */
-    protected KnuthElement getElement(int idx) {
-        return (KnuthElement) par.get(idx);
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java?rev=613245&r1=613244&r2=613245&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java
(original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/InlineKnuthSequence.java
Fri Jan 18 11:52:06 2008
@@ -74,7 +74,7 @@
         // does the first element of the first paragraph add to an existing word?
         ListElement lastOldElement, firstNewElement;
         lastOldElement = getLast();
-        firstNewElement = sequence.getElement(0);
+        firstNewElement = sequence.getListElement(0);
         if (firstNewElement.isBox() && !((KnuthElement) firstNewElement).isAuxiliary()
                 && lastOldElement.isBox() && ((KnuthElement) lastOldElement).getW()
!= 0) {
             addALetterSpace();
@@ -107,9 +107,9 @@
         KnuthBox prevBox = (KnuthBox) getLast();
         if (prevBox.isAuxiliary()
             && (size() < 4
-                || !getElement(size() - 2).isGlue()
-                || !getElement(size() - 3).isPenalty()
-                || !getElement(size() - 4).isBox()
+                || !getListElement(size() - 2).isGlue()
+                || !getListElement(size() - 3).isPenalty()
+                || !getListElement(size() - 4).isBox()
                )
            ) {
             // Not the sequence we are expecting
@@ -160,6 +160,13 @@
      */
     public void resolveElements(int startIndex) {}
     
+    /* (non-Javadoc)
+     * @see org.apache.fop.layoutmgr.KnuthSequence#resolveAndGetElement(int)
+     */
+    public KnuthElement resolveAndGetKnuthElement(int index) {
+        return getKnuthElement(index);
+    }
+
     /**
      * Resolve all elements in seq
      * @param seq the Knuth Sequence

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java?rev=613245&r1=613244&r2=613245&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
(original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
Fri Jan 18 11:52:06 2008
@@ -166,11 +166,19 @@
      * @param index The index of the element to be returned
      * @return the element at index index.
      */
-    public ListElement getElement(int index) {
+    public ListElement getListElement(int index) {
         return (ListElement) get(index);
     }
 
     /**
+     * @param index The index of the element to be returned
+     * @return the element at index index.
+     */
+    public KnuthElement getKnuthElement(int index) {
+        return (KnuthElement) get(index);
+    }
+
+    /**
      * Is this an inline or a block sequence?
      * @return true if this is an inline sequence
      */
@@ -185,6 +193,13 @@
      */
     public abstract void resolveElements(int startIndex);
     
+    /**
+     * Resolve elements and get element index
+     * @param index the index to get
+     * @return the Knuth Element at index
+     */
+    public abstract KnuthElement resolveAndGetKnuthElement(int index);
+
     /**
      * Resolve all elements in seq
      * @param seq the Knuth Sequence

Modified: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=613245&r1=613244&r2=613245&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
(original)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
Fri Jan 18 11:52:06 2008
@@ -30,8 +30,6 @@
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition;
-import org.apache.fop.layoutmgr.BlockKnuthSequence.SubSequence;
-import org.apache.fop.layoutmgr.list.LineBreakingListElement;
 import org.apache.fop.traits.MinOptMax;
 
 class PageBreakingAlgorithm extends BreakingAlgorithm {
@@ -281,7 +279,7 @@
             // remove from footnotesList the note lists that will be met
             // after the restarting point
             for (int j = currentIndex; j >= restartingNode.position; j--) {
-                KnuthElement resettedElement = getElement(j);
+                KnuthElement resettedElement = par.getKnuthElement(j);
                 if (resettedElement instanceof KnuthBlockBox
                     && ((KnuthBlockBox) resettedElement).hasAnchors()) {
                     resetFootnotes(((KnuthBlockBox) resettedElement).getFootnoteElementLists());
@@ -409,7 +407,7 @@
             int index;
             // ignore suppressed elements
             for (index = prevBreakIndex + 1;
-                    !par.getElement(index).isBox();
+                    !par.getListElement(index).isBox();
                     index++) {
                 //nop
             }
@@ -417,9 +415,9 @@
             for (;
                  index < breakIndex;
                  index++) {
-                if (par.getElement(index).isGlue() && par.getElement(index - 1).isBox()
-                    || par.getElement(index).isPenalty() 
-                       && ((KnuthElement) par.getElement(index)).getP() < KnuthElement.INFINITE)
{
+                if (par.getListElement(index).isGlue() && par.getListElement(index
- 1).isBox()
+                    || par.getListElement(index).isPenalty() 
+                       && ((KnuthElement) par.getListElement(index)).getP() <
KnuthElement.INFINITE) {
                     // break found
                     break;
                 }
@@ -628,8 +626,8 @@
         }
 
         if (element.isPenalty() && ((KnuthPenalty) element).isFlagged()
-            && getElement(activeNode.position).isPenalty()
-            && ((KnuthPenalty) getElement(activeNode.position)).isFlagged()) {
+            && par.getKnuthElement(activeNode.position).isPenalty()
+            && ((KnuthPenalty) par.getKnuthElement(activeNode.position)).isFlagged())
{
             // add demerit for consecutive breaks at flagged penalties
             demerits += repeatedFlaggedDemerit;
         }



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


Mime
View raw message