From 239a590e9819edadc30d82695ba9e1c8af9627a9 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sun, 7 Mar 2004 17:52:43 +0000 Subject: [PATCH] Fix of leading-space problem in HEAD. (A single leading space of the first 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 | 4 ---- src/java/org/apache/fop/fo/flow/Block.java | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index 4e0a84de3..ea25beeef 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -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); } diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java index ffb992181..63f694b36 100644 --- a/src/java/org/apache/fop/fo/flow/Block.java +++ b/src/java/org/apache/fop/fo/flow/Block.java @@ -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; } -- 2.39.5