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;
|| (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);
+ }
}
}
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
if (bIgnore) {
charIter.remove();
} else {
- if (!inWhiteSpace) {
- firstWhiteSpaceInSeq = charIter.mark();
- }
// this is to retain a single space between words
inWhiteSpace = true;
if (currentChar != '\u0020') {
// Any other character
inWhiteSpace = false;
afterLinefeed = false;
+ nonWhiteSpaceCount++;
lfCheck.reset();
break;
}
}
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) {
}
}
- /**
- * 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
*/
<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"/>