]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Remove the AreaInfo objects representing trailing spaces, in order to prevent them...
authorLuca Furini <lfurini@apache.org>
Tue, 20 Sep 2005 11:40:16 +0000 (11:40 +0000)
committerLuca Furini <lfurini@apache.org>
Tue, 20 Sep 2005 11:40:16 +0000 (11:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@290422 13f79535-47bb-0310-9956-ffa450edef68

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

index a24e1babe98fa5958bf063f1bb7598015a968095..09a3466645d5e623eaacaa3bd3e724b709aeb4cd 100644 (file)
@@ -285,6 +285,16 @@ public class ContentLayoutManager extends AbstractBaseLayoutManager
         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) {
     }
 
index 44d8fc8ed6e46ef6d1cb40cc7b0eaa701babfd09..9a32ce9a3ceca888d5aafec0d75c75cb2f2f2fd2 100644 (file)
@@ -122,6 +122,16 @@ public class FootnoteLayoutManager extends AbstractLayoutManager
         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!");
     }
index 71c6adcafdc2b30a30997923a76aec3eea009368..d7c1f84240597b70693657a80495e6f17c0c47c3 100644 (file)
@@ -38,6 +38,14 @@ public interface InlineLevelLayoutManager extends LayoutManager {
      */
     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
      *
index eb8eab71770d1e4143371066c3f685d547adb622..f5fc7315fb5705126b763e117c0dff0898b15a1d 100644 (file)
@@ -247,6 +247,27 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager
         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)
index 56a8e9f1050ba534371ebbd874cf73ba9c132e22..e4e037197d1e4919ae75b1e2d7482e8967a35dba 100644 (file)
@@ -302,6 +302,16 @@ public abstract class LeafNodeLayoutManager extends AbstractLayoutManager
         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) {
     }
 
index 86f13b2cd8d9af4285342a7ffb2a07fe4dfdf1ac..7056f4dbb3e637cd461e9a51e59a673246f0e56d 100644 (file)
@@ -285,35 +285,40 @@ public class LineLayoutManager extends InlineStackingLayoutManager
          * 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 @@ public class LineLayoutManager extends InlineStackingLayoutManager
                           (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 class LineLayoutManager extends InlineStackingLayoutManager
     public boolean getGeneratesLineArea() {
         return true;
     }
-   
 }
 
index 01cc8bba1f4aa47e1380b85e715c168d05a56447..3f4de96a130359fe5b829043106be96fcf5028db 100644 (file)
@@ -557,6 +557,36 @@ public class TextLayoutManager extends LeafNodeLayoutManager {
         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());