aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-06-02 14:05:52 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-06-02 14:05:52 +0000
commit92f144a66ef5f789019687047756ac870782ef0a (patch)
tree4e0801a4aa22a7c876f1633b22f723e472b7f34f /src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
parentdf16894515e5927bc1442225fb0210d2db4c11c9 (diff)
downloadxmlgraphics-fop-92f144a66ef5f789019687047756ac870782ef0a.tar.gz
xmlgraphics-fop-92f144a66ef5f789019687047756ac870782ef0a.zip
Merged revisions 660979,660998,661276,661310,661999,662009,662203 via svnmerge from
https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk ........ r660979 | vhennebert | 2008-05-28 16:24:23 +0100 (Wed, 28 May 2008) | 3 lines Bugzilla 37579: added support for footnotes in lists and table bodies (not header nor footer). This is /not/ to be considered a final fix: similar code is duplicated over several classes (LineLayoutManager, ListItemLayoutManager and to less extent TableStepper). Footnotes should probably be handled another way. ........ r660998 | maxberger | 2008-05-28 17:10:32 +0100 (Wed, 28 May 2008) | 1 line Implemented Font auto-selection word-by-word ........ r661276 | vhennebert | 2008-05-29 10:58:06 +0100 (Thu, 29 May 2008) | 2 lines Set svn:keywords and svn:eol-style properties for files added in revision 660998 ........ r661310 | maxberger | 2008-05-29 13:03:48 +0100 (Thu, 29 May 2008) | 1 line Added docs for my recent commit (word-by-word character selection) ........ r661999 | adelmelle | 2008-05-31 11:56:05 +0100 (Sat, 31 May 2008) | 3 lines Bugzilla 45097: Leading/trailing white-space not removed from nested inline-content when there is no preceding/following text. ........ r662009 | maxberger | 2008-05-31 12:45:55 +0100 (Sat, 31 May 2008) | 1 line Code Cleanups (no functional change) ........ r662203 | maxberger | 2008-06-01 12:57:33 +0100 (Sun, 01 Jun 2008) | 1 line More code Cleanups (no functional changes) ........ git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@662442 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java')
-rw-r--r--src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java144
1 files changed, 91 insertions, 53 deletions
diff --git a/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java b/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
index 557a1778e..d8915b124 100644
--- a/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
+++ b/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
@@ -87,39 +87,49 @@ public class XMLWhiteSpaceHandler {
* @param nextChild the node that will be added to the list
* after firstTextNode
*/
- public void handleWhiteSpace(FObjMixed fo, FONode firstTextNode, FONode nextChild) {
-
+ public void handleWhiteSpace(FObjMixed fo,
+ FONode firstTextNode,
+ FONode nextChild) {
+
Block currentBlock = null;
int foId = fo.getNameId();
- if (foId == Constants.FO_BLOCK) {
- currentBlock = (Block) fo;
- if (nestedBlockStack.isEmpty() || fo != nestedBlockStack.peek()) {
- if (nextChild != null) {
- /* if already in a block, push the current block
- * onto the stack of nested blocks
- */
- nestedBlockStack.push(currentBlock);
+ /* set the current block */
+ switch (foId) {
+ case Constants.FO_BLOCK:
+ currentBlock = (Block) fo;
+ if (nestedBlockStack.empty() || fo != nestedBlockStack.peek()) {
+ if (nextChild != null) {
+ /* if already in a block, push the current block
+ * onto the stack of nested blocks
+ */
+ nestedBlockStack.push(currentBlock);
+ }
+ } else {
+ if (nextChild == null) {
+ nestedBlockStack.pop();
+ }
}
- } else {
- if (nextChild == null) {
- nestedBlockStack.pop();
+ break;
+
+ case Constants.FO_RETRIEVE_MARKER:
+ /* look for the nearest block ancestor, if any */
+ FONode ancestor = fo;
+ do {
+ ancestor = ancestor.getParent();
+ } while (ancestor.getNameId() != Constants.FO_BLOCK
+ && ancestor.getNameId() != Constants.FO_STATIC_CONTENT);
+
+ if (ancestor.getNameId() == Constants.FO_BLOCK) {
+ currentBlock = (Block) ancestor;
+ nestedBlockStack.push(currentBlock);
}
- }
- } else if (foId == Constants.FO_RETRIEVE_MARKER) {
- /* look for the nearest block ancestor, if any */
- FONode ancestor = fo;
- do {
- ancestor = ancestor.getParent();
- } while (ancestor.getNameId() != Constants.FO_BLOCK
- && ancestor.getNameId() != Constants.FO_STATIC_CONTENT);
+ break;
- if (ancestor.getNameId() == Constants.FO_BLOCK) {
- currentBlock = (Block) ancestor;
- nestedBlockStack.push(currentBlock);
- }
- } else if (!nestedBlockStack.isEmpty()) {
- currentBlock = (Block) nestedBlockStack.peek();
+ default:
+ if (!nestedBlockStack.empty()) {
+ currentBlock = (Block) nestedBlockStack.peek();
+ }
}
if (currentBlock != null) {
@@ -132,8 +142,15 @@ public class XMLWhiteSpaceHandler {
whiteSpaceTreatment = Constants.EN_IGNORE_IF_SURROUNDING_LINEFEED;
}
+ endOfBlock = (nextChild == null && fo == currentBlock);
+
if (firstTextNode == null) {
- //nothing to do but initialize related properties
+ //no text means no white-space to handle; return early
+ afterLinefeed = (fo == currentBlock && fo.firstChild == null);
+ nonWhiteSpaceCount = 0;
+ if (endOfBlock) {
+ handlePendingInlines();
+ }
return;
}
@@ -144,13 +161,32 @@ public class XMLWhiteSpaceHandler {
|| currentBlock == null
|| (foId == Constants.FO_RETRIEVE_MARKER
&& fo.getParent() == currentBlock)) {
- afterLinefeed = (
- (firstTextNode == fo.firstChild)
- || (firstTextNode.siblings[0].getNameId()
- == Constants.FO_BLOCK));
+ if (firstTextNode == fo.firstChild) {
+ afterLinefeed = true;
+ } else {
+ int previousChildId = firstTextNode.siblings[0].getNameId();
+ afterLinefeed = (previousChildId == Constants.FO_BLOCK
+ || previousChildId == Constants.FO_TABLE_AND_CAPTION
+ || previousChildId == Constants.FO_TABLE
+ || previousChildId == Constants.FO_LIST_BLOCK
+ || previousChildId == Constants.FO_BLOCK_CONTAINER);
+ }
}
- endOfBlock = (nextChild == null && fo == currentBlock);
+ if (foId == Constants.FO_WRAPPER) {
+ FONode parent = fo.parent;
+ int parentId = parent.getNameId();
+ while (parentId == Constants.FO_WRAPPER) {
+ parent = parent.parent;
+ parentId = parent.getNameId();
+ }
+ if (parentId == Constants.FO_FLOW
+ || parentId == Constants.FO_STATIC_CONTENT
+ || parentId == Constants.FO_BLOCK_CONTAINER
+ || parentId == Constants.FO_TABLE_CELL) {
+ endOfBlock = (nextChild == null);
+ }
+ }
if (nextChild != null) {
int nextChildId = nextChild.getNameId();
@@ -167,26 +203,8 @@ public class XMLWhiteSpaceHandler {
handleWhiteSpace();
if (fo == currentBlock
- && pendingInlines != null
- && !pendingInlines.isEmpty()) {
- /* current FO is a block, and has pending inlines */
- if (endOfBlock || nextChildIsBlockLevel) {
- if (nonWhiteSpaceCount == 0) {
- /* handle white-space for all pending inlines*/
- PendingInline p;
- for (int i = pendingInlines.size(); --i >= 0;) {
- 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();
- }
- }
+ && (endOfBlock || nextChildIsBlockLevel)) {
+ handlePendingInlines();
}
if (nextChild == null) {
@@ -333,6 +351,26 @@ public class XMLWhiteSpaceHandler {
pendingInlines.add(new PendingInline(fo, firstWhiteSpaceInSeq));
}
+ private void handlePendingInlines() {
+ if (!(pendingInlines == null || pendingInlines.isEmpty())) {
+ if (nonWhiteSpaceCount == 0) {
+ /* handle white-space for all pending inlines*/
+ PendingInline p;
+ for (int i = pendingInlines.size(); --i >= 0;) {
+ 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();
+ }
+ }
+ }
+
/**
* Helper class, used during white-space handling to look ahead, and
* see if the next character is a linefeed (or if there will be