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 sp...@apache.org on 2007/11/27 20:48:15 UTC

svn commit: r598745 - in /xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/src/java/org/apache/fop/layoutmgr: BlockKnuthSequence.java BreakingAlgorithm.java InlineKnuthSequence.java KnuthSequence.java PageBreakingAlgorithm.java

Author: spepping
Date: Tue Nov 27 11:48:14 2007
New Revision: 598745

URL: http://svn.apache.org/viewvc?rev=598745&view=rev
Log:
In preparation for nested lists I moved the resolveElements methods to
KnuthSequence, so that they will be accessible by the sequence itself,
even away from the page breaking algorithm such as in
ListItemLM.getNextStep.

Modified:
    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/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=598745&r1=598744&r2=598745&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 Tue Nov 27 11:48:14 2007
@@ -19,13 +19,21 @@
 
 package org.apache.fop.layoutmgr;
 
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Stack;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.layoutmgr.list.LineBreakingListElement;
+
 /**
  * Represents a list of block level Knuth elements.
  */
 public class BlockKnuthSequence extends KnuthSequence {
+
+    /** the logger for the class */
+    private static Log log = LogFactory.getLog(BlockKnuthSequence.class);
     
     private boolean isClosed = false;
     
@@ -136,6 +144,100 @@
 
     public SubSequence removeSubSequence() {
         return (SubSequence) subSequences.pop();
+    }
+
+    /**
+     * The iteration stops at the first resolved element (after line breaking).
+     * After space resolution it is guaranteed that seq does not to contain
+     * Paragraph or ListItemListElements until the first resolved element.
+     * @param seq the Knuth Sequence
+     * @param startIndex the start index
+     */
+    public void resolveElements(int startIndex) {
+        resolveElements(startIndex, false);
+    }
+    
+    /**
+     * Resolve all elements in seq
+     * @param seq the Knuth Sequence
+     */
+    public void resolveElements() {
+        resolveElements(0, true);
+    }
+    
+    /**
+     * This method iterates over seq starting at startIndex.
+     * If it finds a ParagraphListElement, the paragraph is broken into lines,
+     * and the ParagraphListElement is replaced by the resulting elements.
+     * If it finds a ListItemListElement, the paragraphs in the next step
+     * of the list item are broken into lines,
+     * the elements of the next step are added to the sequence before the ListItemListElement,
+     * and the ListItemListElement is removed from the sequence if all steps have been returned.  
+     * Then space resolution is done on seq starting at startIndex.
+     * @param seq the Knuth Sequence
+     * @param startIndex the start index
+     * @param doall resolve all elements or not
+     */
+    private void resolveElements(int startIndex, boolean doall) {
+        for (int i = startIndex; i < size(); ++i) {
+            ListElement elt = (ListElement) get(i);
+            if (!doall && !elt.isUnresolvedElement()
+                    && !(elt instanceof LineBreakingListElement)
+                    && !hasSubSequence()) {
+                break;
+            }
+            if (elt instanceof LineBreakingListElement) {
+                LineBreakingListElement lbelt = (LineBreakingListElement) elt;
+                boolean startOfSubsequence =
+                    lbelt.lineBreakingIsStarting() && lbelt.isStartOfSubsequence();
+                LinkedList lineElts = lbelt.doLineBreaking();
+                
+                if (startOfSubsequence) {
+                    KnuthBox box = ElementListUtils.firstKnuthBox(lineElts);
+                    if (box == null) {
+                        log.debug("Could not find a KnuthBox in step");
+                    } else {
+                        addSubSequence(box, lbelt.getWidowRowLimit());
+                    }
+                }
+                
+                boolean endOfSubsequence = false;
+                if (lbelt.lineBreakingIsFinished()) {
+                    remove(i);
+                    endOfSubsequence = lbelt.isEndOfSubsequence();
+                }
+                addAll(i, lineElts);
+                
+                if (endOfSubsequence) {
+                    SubSequence sseq;
+                    // may throw EmptyStackException
+                    sseq = removeSubSequence();
+                    int widowRowLimit = sseq.getWidowRowLimit();
+                    int orphanRowLimit = lbelt.getOrphanRowLimit();
+                    Object nextElt = get(i);
+                    KnuthBox box = ElementListUtils.lastKnuthBox(lineElts);
+                    if (box == null) {
+                        log.debug("Could not find a KnuthBox in step");
+                    } else {
+                        int fromIndex = indexOf(sseq.getFirstBox());
+                        int toIndex = indexOf(box);
+                        List subList = subList(fromIndex, toIndex+1);
+                        SpaceResolver.resolveElementList(subList, 0, true);
+                        if (widowRowLimit != 0) {
+                            ElementListUtils.removeLegalBreaks(subList, widowRowLimit);
+                        }
+                        if (orphanRowLimit != 0) {
+                            ElementListUtils.removeLegalBreaksFromEnd(subList, orphanRowLimit);
+                        }
+                        i = indexOf(nextElt);
+                    }
+                }
+                
+                // consider the new element at i
+                --i;
+            }
+        }
+        SpaceResolver.resolveElementList(this, startIndex, doall);
     }
     
 }

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=598745&r1=598744&r2=598745&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 Tue Nov 27 11:48:14 2007
@@ -441,7 +441,7 @@
             if (alignment != org.apache.fop.fo.Constants.EN_CENTER) {
                 while (par.size() > firstBoxIndex) {
                     // scan for unresolved elements and paragraphs
-                    resolveElements(par, firstBoxIndex);
+                    par.resolveElements(firstBoxIndex);
                     thisElement = (KnuthElement) par.get(firstBoxIndex);
                     if (thisElement.isBox()) {
                         break;
@@ -461,7 +461,7 @@
 
         // main loop
         for (int i = startIndex; i < par.size(); i++) {
-            resolveElements(par, i);
+            par.resolveElements(i);
             // resolveElements may have removed element i
             // without adding any element, so that i == par.size()
             if (i >= par.size() - 1) {
@@ -585,15 +585,6 @@
 
         activeLines = null;
         return line;
-    }
-
-    /**
-     * This method is only implemented in a non-trivial way in PageBreakingAlgorithm
-     * @param seq the Knuth Sequence
-     * @param startIndex the start index
-     */
-    void resolveElements(KnuthSequence seq, int startIndex) {
-        ;
     }
 
     /**

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=598745&r1=598744&r2=598745&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 Tue Nov 27 11:48:14 2007
@@ -151,4 +151,19 @@
         }
     }
 
+    /**
+     * The iteration stops at the first resolved element (after line breaking).
+     * After space resolution it is guaranteed that seq does not to contain
+     * Paragraph or ListItemListElements until the first resolved element.
+     * @param seq the Knuth Sequence
+     * @param startIndex the start index
+     */
+    public void resolveElements(int startIndex) {}
+    
+    /**
+     * Resolve all elements in seq
+     * @param seq the Knuth Sequence
+     */
+    public void resolveElements() {}
+
 }

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=598745&r1=598744&r2=598745&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 Tue Nov 27 11:48:14 2007
@@ -176,4 +176,19 @@
      */
     public abstract boolean isInlineSequence();
 
+    /**
+     * The iteration stops at the first resolved element (after line breaking).
+     * After space resolution it is guaranteed that seq does not to contain
+     * Paragraph or ListItemListElements until the first resolved element.
+     * @param seq the Knuth Sequence
+     * @param startIndex the start index
+     */
+    public abstract void resolveElements(int startIndex);
+    
+    /**
+     * Resolve all elements in seq
+     * @param seq the Knuth Sequence
+     */
+    public abstract void resolveElements();
+
 }

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=598745&r1=598744&r2=598745&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 Tue Nov 27 11:48:14 2007
@@ -255,7 +255,7 @@
              * (Note: this does not respect possible stacking constraints 
              * between footnotes!)
              */
-            resolveElements(noteList);
+            noteList.resolveElements();
             
             int noteLength = 0;
             footnotesList.add(noteList);
@@ -809,100 +809,6 @@
                 ratio, difference));
     }
     
-    /**
-     * This method iterates over seq starting at startIndex.
-     * If it finds a ParagraphListElement, the paragraph is broken into lines,
-     * and the ParagraphListElement is replaced by the resulting elements.
-     * If it finds a ListItemListElement, the paragraphs in the next step
-     * of the list item are broken into lines,
-     * the elements of the next step are added to the sequence before the ListItemListElement,
-     * and the ListItemListElement is removed from the sequence if all steps have been returned.  
-     * Then space resolution is done on seq starting at startIndex.
-     * @param seq the Knuth Sequence
-     * @param startIndex the start index
-     * @param doall resolve all elements or not
-     */
-    void resolveElements(BlockKnuthSequence seq, int startIndex, boolean doall) {
-        for (int i = startIndex; i < seq.size(); ++i) {
-            ListElement elt = (ListElement) seq.get(i);
-            if (!doall && !elt.isUnresolvedElement()
-                    && !(elt instanceof LineBreakingListElement)
-                    && !((AbstractBreaker.BlockSequence)seq).hasSubSequence()) {
-                break;
-            }
-            if (elt instanceof LineBreakingListElement) {
-                LineBreakingListElement lbelt = (LineBreakingListElement) elt;
-                boolean startOfSubsequence =
-                    lbelt.lineBreakingIsStarting() && lbelt.isStartOfSubsequence();
-                LinkedList lineElts = lbelt.doLineBreaking();
-                
-                if (startOfSubsequence) {
-                    KnuthBox box = ElementListUtils.firstKnuthBox(lineElts);
-                    if (box == null) {
-                        log.debug("Could not find a KnuthBox in step");
-                    } else {
-                        seq.addSubSequence(box, lbelt.getWidowRowLimit());
-                    }
-                }
-                
-                boolean endOfSubsequence = false;
-                if (lbelt.lineBreakingIsFinished()) {
-                    seq.remove(i);
-                    endOfSubsequence = lbelt.isEndOfSubsequence();
-                }
-                seq.addAll(i, lineElts);
-                
-                if (endOfSubsequence) {
-                    SubSequence sseq;
-                    // may throw EmptyStackException
-                    sseq = seq.removeSubSequence();
-                    int widowRowLimit = sseq.getWidowRowLimit();
-                    int orphanRowLimit = lbelt.getOrphanRowLimit();
-                    Object nextElt = seq.get(i);
-                    KnuthBox box = ElementListUtils.lastKnuthBox(lineElts);
-                    if (box == null) {
-                        log.debug("Could not find a KnuthBox in step");
-                    } else {
-                        int fromIndex = seq.indexOf(sseq.getFirstBox());
-                        int toIndex = seq.indexOf(box);
-                        List subList = seq.subList(fromIndex, toIndex+1);
-                        SpaceResolver.resolveElementList(subList, 0, true);
-                        if (widowRowLimit != 0) {
-                            ElementListUtils.removeLegalBreaks(subList, widowRowLimit);
-                        }
-                        if (orphanRowLimit != 0) {
-                            ElementListUtils.removeLegalBreaksFromEnd(subList, orphanRowLimit);
-                        }
-                        i = seq.indexOf(nextElt);
-                    }
-                }
-                
-                // consider the new element at i
-                --i;
-            }
-        }
-        SpaceResolver.resolveElementList(seq, startIndex, doall);
-    }
-
-    /**
-     * The iteration stops at the first resolved element (after line breaking).
-     * After space resolution it is guaranteed that seq does not to contain
-     * Paragraph or ListItemListElements until the first resolved element.
-     * @param seq the Knuth Sequence
-     * @param startIndex the start index
-     */
-    void resolveElements(KnuthSequence seq, int startIndex) {
-        resolveElements((BlockKnuthSequence) seq, startIndex, false);
-    }
-    
-    /**
-     * Resolve all elements in seq
-     * @param seq the Knuth Sequence
-     */
-    void resolveElements(BlockKnuthSequence seq) {
-        resolveElements(seq, 0, true);
-    }
-
     protected int filterActiveNodes() {
         // leave only the active node with fewest total demerits
         KnuthNode bestActiveNode = null;



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