]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Further fine-tuning of white-space-handling during refinement
authorAndreas L. Delmelle <adelmelle@apache.org>
Wed, 1 Feb 2006 21:13:42 +0000 (21:13 +0000)
committerAndreas L. Delmelle <adelmelle@apache.org>
Wed, 1 Feb 2006 21:13:42 +0000 (21:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@374174 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
test/layoutengine/standard-testcases/inline_border_padding.xml

index 8af878dc93216d3f780f0285b68a8096a1a3c050..4abef6528716aed9a4e65a122bf593cbafd5f83c 100644 (file)
@@ -34,6 +34,8 @@ public class XMLWhiteSpaceHandler {
     private boolean inWhiteSpace = false;
     // True if the last char was a linefeed
     private boolean afterLinefeed = true;
+    // Counter, increased every time a non-white-space is encountered
+    private int nonWhiteSpaceCount;
     
     private Block currentBlock;
     private FObj currentFO;
@@ -89,28 +91,46 @@ public class XMLWhiteSpaceHandler {
                     || (textNodeIndex > 0
                             && ((FONode) fo.childNodes.get(textNodeIndex - 1))
                                 .getNameId() == Constants.FO_BLOCK));
-            endOfBlock = (nextChild == null);
         }
+        endOfBlock = (nextChild == null && currentFO == currentBlock);
         nextChildIsBlock = (nextChild != null 
                         && nextChild.getNameId() == Constants.FO_BLOCK);
         handleWhiteSpace();
-        if (inWhiteSpace) {
-            if (!endOfBlock && currentFO != currentBlock) {
-                /* means there is at least one trailing space in the
-                   inline FO that is about to end */
-                addPendingInline(fo);
-            } else if (pendingInlines != null) {
-                if (endOfBlock || nextChildIsBlock) {
-                    /* handle white-space for all trailing inlines*/
+        if (currentFO == currentBlock 
+                && pendingInlines != null 
+                && !pendingInlines.isEmpty()) {
+            /* current FO is a block, and has pending inlines */
+            if (endOfBlock || nextChildIsBlock) {
+                if (nonWhiteSpaceCount == 0) {
+                    /* handle white-space for all pending inlines*/
+                    PendingInline p;
                     for (int i = pendingInlines.size(); --i >= 0;) {
-                        PendingInline p = (PendingInline) pendingInlines.get(i);
-                        currentFO = p.fo;
+                        p = (PendingInline) pendingInlines.get(i);
                         charIter = (RecursiveCharIterator) p.firstTrailingWhiteSpace;
                         handleWhiteSpace();
+                        pendingInlines.remove(p);
                     }
+                } else {
+                    /* there is non-white-space text between the pending
+                     * inline(s) and the end of the block;
+                     * clear list of pending inlines */
+                    pendingInlines.clear();
                 }
+            }
+        }
+        if (currentFO != currentBlock && nextChild == null) {
+            /* current FO is not a block, and is about to end */
+            if (nonWhiteSpaceCount > 0 && pendingInlines != null) {
+                /* there is non-white-space text between the pending 
+                 * inline(s) and the end of the non-block node; 
+                 * clear list of pending inlines */
                 pendingInlines.clear();
             }
+            if (inWhiteSpace) {
+                /* means there is at least one trailing space in the
+                   inline FO that is about to end */
+                addPendingInline(fo);
+            }
         }
     }
     
@@ -131,8 +151,13 @@ public class XMLWhiteSpaceHandler {
     private void handleWhiteSpace() {
         
         EOLchecker lfCheck = new EOLchecker(charIter);
-
+        
+        nonWhiteSpaceCount = 0;
+        
         while (charIter.hasNext()) {
+            if (!inWhiteSpace) {
+                firstWhiteSpaceInSeq = charIter.mark();
+            }
             char currentChar = charIter.nextChar();
             int currentCharClass = CharUtilities.classOf(currentChar);
             if (currentCharClass == CharUtilities.LINEFEED
@@ -178,9 +203,6 @@ public class XMLWhiteSpaceHandler {
                         if (bIgnore) {
                             charIter.remove();
                         } else {
-                            if (!inWhiteSpace) {
-                                firstWhiteSpaceInSeq = charIter.mark();
-                            }
                             // this is to retain a single space between words
                             inWhiteSpace = true;
                             if (currentChar != '\u0020') {
@@ -220,6 +242,7 @@ public class XMLWhiteSpaceHandler {
                     // Any other character
                     inWhiteSpace = false;
                     afterLinefeed = false;
+                    nonWhiteSpaceCount++;
                     lfCheck.reset();
                     break;
             }
index 601b5ca62d31986ddbe49fc0fca89c62368f7503..3822cbc3acd3f42cc2760938a90f8afc58f8e3e5 100644 (file)
@@ -254,8 +254,6 @@ public class LineLayoutManager extends InlineStackingLayoutManager
         }
 
         public KnuthSequence endSequence() {
-            // remove elements representig spaces at the end of the paragraph
-            removeElementsForTrailingSpaces();
             if (this.size() > ignoreAtStart) {
                 if (textAlignment == EN_CENTER
                     && textAlignmentLast != EN_JUSTIFY) {
@@ -289,57 +287,6 @@ public class LineLayoutManager extends InlineStackingLayoutManager
             }
         }
 
-        /**
-         * remove elements representing spaces at the end of the paragraph;
-         * the text could have one or more trailing spaces, each of them
-         * being either a normal space or a non-breaking space;
-         * according to the alignment, the sub-sequence of elements
-         * representing each space has a different "pattern"
-         */
-        private void removeElementsForTrailingSpaces() {
-            LinkedList removedElements;
-            InlineLevelLayoutManager inlineLM;
-            int alignment = 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 (alignment == EN_CENTER
-                    || this.size() > 6
-                       && ((KnuthElement) this.get(this.size() - 6)).isGlue()
-                       && ((KnuthElement) this.get(this.size() - 5)).isPenalty()
-                       && ((KnuthElement) this.get(this.size() - 4)).isGlue()
-                       && ((KnuthElement) this.get(this.size() - 3)).isBox()
-                       && ((KnuthElement) this.get(this.size() - 2)).isPenalty()) {
-                    // centered text (or text with inline borders and padding): the pattern is
-                    //     <glue> <penaly> <glue> <box> <penaly> <glue>
-                    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 (alignment == EN_START || alignment == EN_END) {
-                    // left- or right-aligned text: the pattern is
-                    //     <glue> <penalty> <glue>
-                    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>
-                    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()) {
-                    removedElements.addFirst((KnuthPenalty) this.remove(this.size() - 1));
-                }
-                inlineLM.removeWordSpace(removedElements);
-            }
-        }
-        
         /**
          * @return true if the sequence contains a box
          */
index 609a0962559210e7be32420e22ba1e18bc170856..5797da93adec7861faa2c24b0be53d9db0b07ac5 100644 (file)
     <eval expected="(solid,#ff0000,1000)" xpath="//flow/block[5]/lineArea[4]/inlineparent/@border-end"/>
     <eval expected="2000" xpath="//flow/block[5]/lineArea[4]/inlineparent/@padding-end"/>
     
-    <eval expected="118830" xpath="//flow/block[6]/lineArea/inlineparent/@ipd"/>
-    <eval expected="126830" xpath="//flow/block[6]/lineArea/inlineparent/@ipda"/>
+    <eval expected="113270" xpath="//flow/block[6]/lineArea/inlineparent/@ipd"/>
+    <eval expected="121270" xpath="//flow/block[6]/lineArea/inlineparent/@ipda"/>
     <eval expected="0" xpath="//flow/block[6]/lineArea/inlineparent/@offset"/>
     <eval expected="(solid,#ff0000,2000)" xpath="//flow/block[6]/lineArea/inlineparent/@border-after"/>
     <eval expected="(solid,#ff0000,2000)" xpath="//flow/block[6]/lineArea/inlineparent/@border-before"/>
     <eval expected="(solid,#ff0000,2000)" xpath="//flow/block[6]/lineArea/inlineparent/@border-start"/>
     <eval expected="2000" xpath="//flow/block[6]/lineArea/inlineparent/@padding-end"/>
     <eval expected="2000" xpath="//flow/block[6]/lineArea/inlineparent/@padding-start"/>
-    <eval expected="78930" xpath="//flow/block[6]/lineArea/inlineparent/inlineparent/@ipd"/>
-    <eval expected="84930" xpath="//flow/block[6]/lineArea/inlineparent/inlineparent/@ipda"/>
+    <eval expected="76150" xpath="//flow/block[6]/lineArea/inlineparent/inlineparent/@ipd"/>
+    <eval expected="82150" xpath="//flow/block[6]/lineArea/inlineparent/inlineparent/@ipda"/>
     <eval expected="0" xpath="//flow/block[6]/lineArea/inlineparent/inlineparent/@offset"/>
     <eval expected="(solid,#008000,1000)" xpath="//flow/block[6]/lineArea/inlineparent/inlineparent/@border-after"/>
     <eval expected="(solid,#008000,1000)" xpath="//flow/block[6]/lineArea/inlineparent/inlineparent/@border-before"/>