You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2008/05/31 12:56:06 UTC
svn commit: r661999 - in /xmlgraphics/fop/trunk:
src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java status.xml
test/layoutengine/standard-testcases/inline_white-space-treatment_bugzilla45097.xml
Author: adelmelle
Date: Sat May 31 03:56:05 2008
New Revision: 661999
URL: http://svn.apache.org/viewvc?rev=661999&view=rev
Log:
Bugzilla 45097:
Leading/trailing white-space not removed from nested inline-content when there is no preceding/following text.
Added:
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/inline_white-space-treatment_bugzilla45097.xml (with props)
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
xmlgraphics/fop/trunk/status.xml
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java?rev=661999&r1=661998&r2=661999&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java Sat May 31 03:56:05 2008
@@ -87,39 +87,49 @@
* @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 @@
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 @@
|| 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 @@
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 @@
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
Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=661999&r1=661998&r2=661999&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Sat May 31 03:56:05 2008
@@ -57,6 +57,10 @@
<action context="Renderers" dev="AC" importance="high" type="add">
Added SVG support for AFP (GOCA).
</action -->
+ <action context="Code" dev="AD" type="fix" fixes-bug="45097">
+ Corrected white-space-treatment for situations where an inline-node is the first/last
+ child node of an fo:block, without preceding/following text.
+ </action>
<action context="Layout" dev="MB" type="add">
Implemented word-by-ford font-selection strategy on text.
</action>
Added: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/inline_white-space-treatment_bugzilla45097.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/inline_white-space-treatment_bugzilla45097.xml?rev=661999&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/inline_white-space-treatment_bugzilla45097.xml (added)
+++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/inline_white-space-treatment_bugzilla45097.xml Sat May 31 03:56:05 2008
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+ <info>
+ <p>
+ This test checks for white-space related bugs as reported in Bugzilla 45097.
+ </p>
+ </info>
+ <fo>
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="all-pages" margin-top="0.5in" margin-bottom="0.5in" margin-left="0.38in" margin-right="0.38in" page-width="8.5in" page-height="11in">
+ <fo:region-body margin-top="0.5in + 1mm" margin-bottom="0.5in + 1mm"/>
+ <fo:region-before extent="0.5in"/>
+ <fo:region-after extent="0.5in"/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="all-pages">
+ <fo:static-content flow-name="xsl-region-before"><fo:block/></fo:static-content>
+ <fo:static-content flow-name="xsl-region-after"><fo:block/></fo:static-content>
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block>
+ <fo:block><fo:leader leader-pattern="space"/></fo:block>
+ <fo:block text-decoration="underline">Example 1: white-space-collapse="false" linefeed-treatment="preserve" white-space-treatment="preserve"</fo:block>
+ <fo:block font-family="Courier"
+ white-space-collapse="false"
+ linefeed-treatment="preserve"
+ white-space-treatment="preserve"><fo:block><fo:inline id="inline-1a" border="1mm solid red"> *** </fo:inline></fo:block><fo:block><fo:inline border="1mm solid red">*************</fo:inline></fo:block><fo:block><fo:inline id="inline-1b" border="1mm solid red"> *** </fo:inline></fo:block></fo:block>
+
+ <fo:block><fo:leader leader-pattern="space"/></fo:block>
+ <fo:block text-decoration="underline">Example 2: white-space-collapse="false" linefeed-treatment="preserve" w/ inlines</fo:block>
+ <fo:block font-family="Courier"
+ white-space-collapse="false"
+ linefeed-treatment="preserve"><fo:block><fo:inline id="inline-2a" border="1mm solid red"> *** </fo:inline></fo:block><fo:block><fo:inline border="1mm solid red">*************</fo:inline></fo:block><fo:block><fo:inline id="inline-2b" border="1mm solid red"> *** </fo:inline></fo:block></fo:block>
+
+ </fo:block>
+ <fo:block><fo:leader leader-pattern="space"/></fo:block>
+ <fo:block text-decoration="underline">Example 1: white-space-collapse="false" linefeed-treatment="preserve" white-space-treatment="preserve"</fo:block>
+ <fo:block font-family="Courier"
+ white-space-collapse="false"
+ linefeed-treatment="preserve"
+ white-space-treatment="preserve"><fo:block><fo:inline id="inline-3a" border="1mm solid red"> *** </fo:inline></fo:block><fo:block><fo:inline border="1mm solid red">*************</fo:inline></fo:block><fo:block><fo:inline id="inline-3b" border="1mm solid red"> *** </fo:inline></fo:block></fo:block>
+
+ <fo:block><fo:leader leader-pattern="space"/></fo:block>
+ <fo:block text-decoration="underline">Example 2: white-space-collapse="false" linefeed-treatment="preserve" w/ inlines</fo:block>
+ <fo:block font-family="Courier"
+ white-space-collapse="false"
+ linefeed-treatment="preserve"><fo:block><fo:inline id="inline-4a" border="1mm solid red"> *** </fo:inline></fo:block><fo:block><fo:inline border="1mm solid red">*************</fo:inline></fo:block><fo:block><fo:inline id="inline-4b" border="1mm solid red"> *** </fo:inline></fo:block></fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+ </fo>
+ <checks>
+ <eval expected="10" xpath="count(//inlineparent[@prod-id='inline-1a']//space)" />
+ <eval expected="10" xpath="count(//inlineparent[@prod-id='inline-1b']//space)" />
+ <eval expected="0" xpath="count(//inlineparent[@prod-id='inline-2a']//space)" />
+ <eval expected="0" xpath="count(//inlineparent[@prod-id='inline-2b']//space)" />
+ <eval expected="10" xpath="count(//inlineparent[@prod-id='inline-3a']//space)" />
+ <eval expected="10" xpath="count(//inlineparent[@prod-id='inline-3b']//space)" />
+ <eval expected="0" xpath="count(//inlineparent[@prod-id='inline-4a']//space)" />
+ <eval expected="0" xpath="count(//inlineparent[@prod-id='inline-4b']//space)" />
+ </checks>
+</testcase>
\ No newline at end of file
Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/inline_white-space-treatment_bugzilla45097.xml
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org