aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas L. Delmelle <adelmelle@apache.org>2006-02-01 21:13:42 +0000
committerAndreas L. Delmelle <adelmelle@apache.org>2006-02-01 21:13:42 +0000
commitae44bf2f4429d982e604d6202a2905dcd24da658 (patch)
treebd9616ed183d9a94e068acdb732c8c32f5dfbde6 /src
parent36540e2591b3bfc1060d540536c5dad01ceed8e5 (diff)
downloadxmlgraphics-fop-ae44bf2f4429d982e604d6202a2905dcd24da658.tar.gz
xmlgraphics-fop-ae44bf2f4429d982e604d6202a2905dcd24da658.zip
Further fine-tuning of white-space-handling during refinement
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@374174 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java53
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java53
2 files changed, 38 insertions, 68 deletions
diff --git a/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java b/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
index 8af878dc9..4abef6528 100644
--- a/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
+++ b/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
@@ -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;
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
index 601b5ca62..3822cbc3a 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
@@ -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) {
@@ -290,57 +288,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
*/
public boolean containsBox() {