]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fix of leading-space problem in HEAD. (A single leading space of the first
authorGlen Mazza <gmazza@apache.org>
Sun, 7 Mar 2004 17:52:43 +0000 (17:52 +0000)
committerGlen Mazza <gmazza@apache.org>
Sun, 7 Mar 2004 17:52:43 +0000 (17:52 +0000)
inline child of the block object was being incorrectly retained.)

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197421 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/FOText.java
src/java/org/apache/fop/fo/flow/Block.java

index 4e0a84de3d50d17afaa3a73be7982e97d39c8bd0..ea25beeef29891415bae6ca1aae400c09599e1e2 100644 (file)
@@ -168,10 +168,6 @@ public class FOText extends FObj {
             } else if (curIndex == length) {
                 curIndex = --length;
             }
-//          Temporary until leading space problem in 1.0 fixed
-//          System.out.println("\n\nremove called: ca = \"" + 
-//              new String(ca) + "\", length/node length: " + length 
-//              + ", " + ca.length);
         }
 
 
index ffb99218178f0543c5c8a037df5f19b82157da7d..63f694b36827cbec7b2ec4dac010718760b02c70 100644 (file)
@@ -246,6 +246,11 @@ public class Block extends FObjMixed {
         if (firstInlineChild != null) {
             boolean bInWS = false;
             boolean bPrevWasLF = false;
+            
+            /* bSeenNonWSYet is an indicator used for trimming all leading 
+               whitespace for the first inline child of the block
+            */
+            boolean bSeenNonWSYet = false;
             RecursiveCharIterator charIter =
               new RecursiveCharIterator(this, firstInlineChild);
             LFchecker lfCheck = new LFchecker(charIter);
@@ -279,7 +284,13 @@ public class Block extends FObjMixed {
                                         && (bPrevWasLF || lfCheck.nextIsLF()))) {
                                 charIter.remove();
                             } else {
+                                // this is to retain a single space between words
                                 bInWS = true;
+                                // remove the space if no word in block 
+                                // encountered yet
+                                if (!bSeenNonWSYet) {
+                                    charIter.remove();
+                                }
                             }
                         }
                         break;
@@ -300,6 +311,11 @@ public class Block extends FObjMixed {
                                 } else {
                                     if (bWScollapse) {
                                         bInWS = true;
+                                        // remove the linefeed if no word in block 
+                                        // encountered yet
+                                        if (!bSeenNonWSYet) {
+                                            charIter.remove();
+                                        }
                                     }
                                     charIter.replaceChar('\u0020');
                                 }
@@ -323,6 +339,7 @@ public class Block extends FObjMixed {
                     case CharUtilities.NONWHITESPACE:
                         /* Any other character */
                         bInWS = bPrevWasLF = false;
+                        bSeenNonWSYet = true;
                         lfCheck.reset();
                         break;
                 }