Browse Source

Slight enhancement to white-space-handling: removal of trailing white-space for trailing inlines

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@367395 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_92-beta
Andreas L. Delmelle 18 years ago
parent
commit
5343a4a4d6
1 changed files with 52 additions and 13 deletions
  1. 52
    13
      src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java

+ 52
- 13
src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java View File

@@ -46,6 +46,8 @@ public class XMLWhiteSpaceHandler {
private RecursiveCharIterator charIter;
private List discardableFOCharacters;
private List pendingInlines;
private CharIterator firstWhiteSpaceInSeq;
/**
* Marks a Character object as discardable, so that it is effectively
@@ -80,19 +82,36 @@ public class XMLWhiteSpaceHandler {
}
charIter = new RecursiveCharIterator(fo, firstTextNode);
inWhiteSpace = false;
if (fo.getNameId() == Constants.FO_BLOCK) {
int textNodeIndex = -1;
if (fo.childNodes != null) {
textNodeIndex = fo.childNodes.indexOf(firstTextNode);
}
afterLinefeed = (textNodeIndex == 0
|| ((FONode) fo.childNodes.get(textNodeIndex - 1))
.getNameId() == Constants.FO_BLOCK);
int textNodeIndex = -1;
if (currentFO == currentBlock) {
textNodeIndex = fo.childNodes.indexOf(firstTextNode);
afterLinefeed = ((textNodeIndex == 0)
|| (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);
&& 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*/
for (int i = pendingInlines.size(); --i >= 0;) {
PendingInline p = (PendingInline) pendingInlines.get(i);
currentFO = p.fo;
charIter = (RecursiveCharIterator) p.firstTrailingWhiteSpace;
handleWhiteSpace();
}
}
pendingInlines.clear();
}
}
}
/**
@@ -159,6 +178,9 @@ 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') {
@@ -190,7 +212,7 @@ public class XMLWhiteSpaceHandler {

case CharUtilities.EOT:
// A "boundary" objects such as non-character inline
// or nested block object was encountered.
// or nested block object was encountered. (? can't happen)
// If any whitespace run in progress, finish it.
// FALL THROUGH

@@ -209,12 +231,19 @@ public class XMLWhiteSpaceHandler {
}
}
private void addPendingInline(FObjMixed fo) {
if (pendingInlines == null) {
pendingInlines = new java.util.ArrayList(5);
}
pendingInlines.add(new PendingInline(fo, firstWhiteSpaceInSeq));
}
private class EOLchecker {
private boolean nextIsEOL = false;
private RecursiveCharIterator charIter;

EOLchecker(RecursiveCharIterator charIter) {
this.charIter = charIter;
EOLchecker(CharIterator charIter) {
this.charIter = (RecursiveCharIterator) charIter;
}

boolean beforeLinefeed() {
@@ -243,4 +272,14 @@ public class XMLWhiteSpaceHandler {
nextIsEOL = false;
}
}
private class PendingInline {
protected FObjMixed fo;
protected CharIterator firstTrailingWhiteSpace;
PendingInline(FObjMixed fo, CharIterator firstTrailingWhiteSpace) {
this.fo = fo;
this.firstTrailingWhiteSpace = firstTrailingWhiteSpace;
}
}
}

Loading…
Cancel
Save