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 lf...@apache.org on 2005/09/20 13:40:38 UTC

svn commit: r290422 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/

Author: lfurini
Date: Tue Sep 20 04:40:16 2005
New Revision: 290422

URL: http://svn.apache.org/viewcvs?rev=290422&view=rev
Log:
Remove the AreaInfo objects representing trailing spaces, in order to prevent them reappearing again when getChangedKnuthElements() is called.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java?rev=290422&r1=290421&r2=290422&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java Tue Sep 20 04:40:16 2005
@@ -285,6 +285,16 @@
         return oldList;
     }
 
+    /**
+     * Remove the word space represented by the given elements
+     *
+     * @param oldList the elements representing the word space
+     */
+    public void removeWordSpace(List oldList) {
+        // do nothing
+        log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)");
+    }
+
     public void getWordChars(StringBuffer sbChars, Position pos) {
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java?rev=290422&r1=290421&r2=290422&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java Tue Sep 20 04:40:16 2005
@@ -122,6 +122,16 @@
         return oldList;
     }
 
+    /**
+     * Remove the word space represented by the given elements
+     *
+     * @param oldList the elements representing the word space
+     */
+    public void removeWordSpace(List oldList) {
+        // do nothing
+        log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)");
+    }
+
     public void getWordChars(StringBuffer sbChars, Position pos) {
         log.warn("null implementation of getWordChars() called!");
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java?rev=290422&r1=290421&r2=290422&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineLevelLayoutManager.java Tue Sep 20 04:40:16 2005
@@ -39,6 +39,14 @@
     List addALetterSpaceTo(List oldList);
 
     /**
+     * Tell the LM to modify its data, removing the word space 
+     * represented by the given elements
+     *
+     * @param oldList the elements representing the word space
+     */
+    void removeWordSpace(List oldList);
+
+    /**
      * Get the word chars corresponding to the given position
      *
      * @param sbChars the StringBuffer used to append word chars

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java?rev=290422&r1=290421&r2=290422&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java Tue Sep 20 04:40:16 2005
@@ -247,6 +247,27 @@
         return oldList;
     }
 
+    /**
+     * remove the AreaInfo object represented by the given elements,
+     * so that it won't generate any element when getChangedKnuthElements
+     * will be called
+     *
+     * @param oldList the elements representing the word space
+     */
+    public void removeWordSpace(List oldList) {
+        ListIterator oldListIterator = oldList.listIterator();
+        KnuthElement element = null;
+        // "unwrap" the Position stored in each element of oldList
+        while (oldListIterator.hasNext()) {
+            element = (KnuthElement) oldListIterator.next();
+            element.setPosition(((NonLeafPosition)element.getPosition()).getPosition());
+        }
+
+        ((InlineLevelLayoutManager)
+                   element.getLayoutManager()).removeWordSpace(oldList);
+
+    }
+
     public void getWordChars(StringBuffer sbChars, Position pos) {
         Position newPos = ((NonLeafPosition) pos).getPosition();
         ((InlineLevelLayoutManager)

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java?rev=290422&r1=290421&r2=290422&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java Tue Sep 20 04:40:16 2005
@@ -302,6 +302,16 @@
         return oldList;
     }
 
+    /**
+     * Remove the word space represented by the given elements
+     *
+     * @param oldList the elements representing the word space
+     */
+    public void removeWordSpace(List oldList) {
+        // do nothing
+        log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)");
+    }
+
     public void getWordChars(StringBuffer sbChars, Position pos) {
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=290422&r1=290421&r2=290422&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Tue Sep 20 04:40:16 2005
@@ -285,35 +285,40 @@
          * representing each space has a different "pattern"
          */
         private void removeElementsForTrailingSpaces() {
-            KnuthElement removedElement;
+            LinkedList removedElements;
+            InlineLevelLayoutManager inlineLM;
             int effectiveAlignment = getEffectiveAlignment(textAlignment, textAlignmentLast);
             while (this.size() > ignoreAtStart
                    && ((KnuthElement) this.get(this.size() - 1)).isGlue()) {
+                removedElements = new LinkedList();
+                inlineLM = (InlineLevelLayoutManager)
+                    ((KnuthElement) this.get(this.size() - 1)).getLayoutManager();
                 if (effectiveAlignment == EN_CENTER) {
                     // centered text: the pattern is
                     //     <glue> <penaly> <glue> <box> <penaly> <glue>
-                    removedElement = (KnuthGlue) this.remove(this.size() - 1);
-                    removedElement = (KnuthPenalty) this.remove(this.size() - 1);
-                    removedElement = (KnuthBox) this.remove(this.size() - 1);
-                    removedElement = (KnuthGlue) this.remove(this.size() - 1);
-                    removedElement = (KnuthPenalty) this.remove(this.size() - 1);
-                    removedElement = (KnuthGlue) this.remove(this.size() - 1);
+                    removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
+                    removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
+                    removedElements.addFirst((KnuthBox) this.remove(this.size() - 1));
+                    removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
+                    removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
+                    removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
                 } else if (effectiveAlignment == EN_START || effectiveAlignment == EN_END) {
                     // left- or right-aligned text: the pattern is
                     //     <glue> <penalty> <glue>
-                    removedElement = (KnuthGlue) this.remove(this.size() - 1);
-                    removedElement = (KnuthPenalty) this.remove(this.size() - 1);
-                    removedElement = (KnuthGlue) this.remove(this.size() - 1);
+                    removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
+                    removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
+                    removedElements.addFirst((KnuthGlue) this.remove(this.size() - 1));
                 } else {
                     // justified text: the pattern is
                     //     <glue>
-                    removedElement = (KnuthGlue) this.remove(this.size() - 1);
+                    removedElements.add((KnuthGlue) this.remove(this.size() - 1));
                 }
                 // if the space was a non-breaking one, there is also a penalty
                 if (this.size() > ignoreAtStart
                     && ((KnuthElement) this.get(this.size() - 1)).isPenalty()) {
-                    removedElement = (KnuthPenalty) this.remove(this.size() - 1);
+                    removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
                 }
+                inlineLM.removeWordSpace(removedElements);
             }
         }
 
@@ -405,7 +410,9 @@
                           (textAlign == Constants.EN_END) ? difference : 0;
             indent += (bestActiveNode.line == 1 && bFirst) ? 
                           textIndent : 0;
-            double ratio = (textAlign == Constants.EN_JUSTIFY) ? bestActiveNode.adjustRatio : 0;
+            double ratio = (textAlign == Constants.EN_JUSTIFY
+                || difference < 0 && -difference <= bestActiveNode.availableShrink) ?
+                bestActiveNode.adjustRatio : 0;
 
             // add nodes at the beginning of the list, as they are found
             // backwards, from the last one to the first one
@@ -1807,6 +1814,5 @@
     public boolean getGeneratesLineArea() {
         return true;
     }
-   
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java?rev=290422&r1=290421&r2=290422&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java Tue Sep 20 04:40:16 2005
@@ -557,6 +557,36 @@
         return oldList;
     }
 
+    /**
+     * remove the AreaInfo object represented by the given elements,
+     * so that it won't generate any element when getChangedKnuthElements
+     * will be called
+     *
+     * @param oldList the elements representing the word space
+     */
+    public void removeWordSpace(List oldList) {
+        // find the element storing the Position whose value
+        // points to the AreaInfo object
+        ListIterator oldListIterator = oldList.listIterator();
+        if (((KnuthElement) ((LinkedList) oldList).getFirst()).isPenalty()) {
+            // non breaking space: oldList starts with a penalty
+            oldListIterator.next();
+        }
+        if (oldList.size() > 2) {
+            // alignment is either center, start or end:
+            // the first two elements does not store the needed Position
+            oldListIterator.next();
+            oldListIterator.next();
+        }
+        int leafValue = ((LeafPosition) ((KnuthElement) oldListIterator.next()).getPosition()).getLeafPos();
+        // only the last word space can be a trailing space!
+        if (leafValue == vecAreaInfo.size() - 1) {
+            vecAreaInfo.remove(leafValue);
+        } else {
+            log.error("trying to remove a non-trailing word space");
+        }
+    }
+
     public void hyphenate(Position pos, HyphContext hc) {
         AreaInfo ai
             = (AreaInfo) vecAreaInfo.get(((LeafPosition) pos).getLeafPos());



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