Browse Source

Alternative set of rules for text indent calculation (start-indent and end-indent) which tries to mimic many commercial FO implementation that have chosen to break the specification in this aspect. I think I have found the behaviour for most cases. But I'm operating in reverse-engineering mode here and not all FO implementations behave in the same way!

This is an optional feature that has to be explicitely enabled through the user agent. Otherwise, FOP will behave like before.
In the FO tree tests a processing instruction is used to enable the feature/bug ;-) in the user agent so I can test both cases.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@354763 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_91-beta
Jeremias Maerki 18 years ago
parent
commit
973d676bae

+ 22
- 0
src/documentation/content/xdocs/trunk/configuration.xml View File

@@ -75,6 +75,28 @@
<td>Integer, dpi</td>
<td>Resolution in dpi (dots per inch) which is used internally.</td>
</tr>
<tr>
<td>strict-validation</td>
<td>Boolean (true, false)</td>
<td>
Setting this option to 'false' causes FOP to be more forgiving about XSL-FO validity,
for example, you're allowed to specify a border on a region-body which is supported
by some FO implementations but is non-standard. Note that such a border would
currently have no effect in Apache FOP.</td>
</tr>
<tr>
<td>break-indent-inheritance</td>
<td>Boolean (true, false)</td>
<td>
Setting this option to 'true' causes FOP to use an alternative rule set to determine
text indents specified through margins, start-indent and end-indent. Many commercial
FO implementations have chosen to break the XSL specification in this aspect. This
option tries to mimic their behaviour. Please note that Apache FOP may still not
behave exactly like those implementations either because FOP has not fully matched
the desired behaviour and because the behaviour among the commercial implementations
varies. The default for this option (i.e. false) is to behave exactly like the
specification describes.</td>
</tr>
<tr>
<td>default-page-settings</td>
<td>n/a</td>

+ 9
- 0
src/documentation/content/xdocs/trunk/embedding.xml View File

@@ -359,6 +359,15 @@ Fop fop = new Fop(MimeConstants.MIME_POSTSCRIPT, userAgent);]]></source>
</p>
<source>userAgent.setPDFEncryptionParams(new PDFEncryptionParams(null, "owner", false, false, true, true));</source>
</li>
<li>
<p>
Enable an <strong>alternative set of rules for text indents</strong> that tries to mimic the behaviour of many commercial
FO implementations that chose to break the specification in this aspect. The default of this option is
'false' which causes Apache FOP to behave exactly as describes in the specification. To enable the
alternative behaviour, call:
</p>
<source>userAgent.setBreakIndentInheritanceOnReferenceAreaBoundary(true);</source>
</li>
</ul>
<note>
You should not reuse an FOUserAgent instance between FOP rendering runs although you can. Especially

+ 35
- 1
src/java/org/apache/fop/apps/FOUserAgent.java View File

@@ -111,6 +111,9 @@ public class FOUserAgent {
* ability for FOP to halt on all content model violations if desired.
*/
private boolean strictValidation = true;
/** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
private boolean breakIndentInheritanceOnReferenceAreaBoundary = false;

/* Additional fo.ElementMapping subclasses set by user */
private List additionalElementMappings = null;
@@ -207,6 +210,31 @@ public class FOUserAgent {
return strictValidation;
}

/**
* @return true if the indent inheritance should be broken when crossing reference area
* boundaries (for more info, see the javadoc for the relative member variable)
*/
public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
return breakIndentInheritanceOnReferenceAreaBoundary;
}

/**
* Controls whether to enable a feature that breaks indent inheritance when crossing
* reference area boundaries.
* <p>
* This flag controls whether FOP will enable special code that breaks property
* inheritance for start-indent and end-indent when the evaluation of the inherited
* value would cross a reference area. This is described under
* http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to
* improve interoperability with commercial FO implementations and to produce
* results that are more in line with the expectation of unexperienced FO users.
* Note: Enabling this features violates the XSL specification!
* @param value true to enable the feature
*/
public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) {
this.breakIndentInheritanceOnReferenceAreaBoundary = value;
}
/**
* Sets an explicit LayoutManagerMaker instance which overrides the one
* defined by the AreaTreeHandler.
@@ -394,6 +422,13 @@ public class FOUserAgent {
log.info("resolution set to: " + resolution
+ "dpi (px2mm=" + getPixelUnitToMillimeter() + ")");
}
if (userConfig.getChild("strict-validation", false) != null) {
this.strictValidation = userConfig.getChild("strict-validation").getValueAsBoolean();
}
if (userConfig.getChild("break-indent-inheritance", false) != null) {
this.breakIndentInheritanceOnReferenceAreaBoundary
= userConfig.getChild("break-indent-inheritance").getValueAsBoolean();
}
Configuration pageConfig = userConfig.getChild("default-page-settings");
if (pageConfig.getAttribute("height", null) != null) {
setPageHeight(pageConfig.getAttribute("height"));
@@ -616,6 +651,5 @@ public class FOUserAgent {
return this.xmlHandlers;
}
}


+ 88
- 0
src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java View File

@@ -19,6 +19,8 @@
package org.apache.fop.fo.properties;

import org.apache.fop.datatypes.Numeric;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.expr.NumericOp;
import org.apache.fop.fo.expr.PropertyException;
@@ -68,6 +70,19 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker {
* @see CorrespondingPropertyMaker#compute(PropertyList)
*/
public Property compute(PropertyList propertyList) throws PropertyException {
if (propertyList.getFObj().getUserAgent()
.isBreakIndentInheritanceOnReferenceAreaBoundary()) {
return computeAlternativeRuleset(propertyList);
} else {
return computeConforming(propertyList);
}
}
/**
* Calculate the corresponding value for start-indent and end-indent.
* @see CorrespondingPropertyMaker#compute(PropertyList)
*/
public Property computeConforming(PropertyList propertyList) throws PropertyException {
PropertyList pList = getWMPropertyList(propertyList);
if (pList == null) {
return null;
@@ -107,6 +122,79 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker {
return (Property) v;
}
private boolean isInherited(PropertyList pList) {
if (pList.getFObj().getUserAgent().isBreakIndentInheritanceOnReferenceAreaBoundary()) {
FONode nd = pList.getFObj().getParent();
return !((nd instanceof FObj) && ((FObj)nd).generatesReferenceAreas());
} else {
return true;
}
}
/**
* Calculate the corresponding value for start-indent and end-indent.
* This method calculates indent following an alternative rule set that
* tries to mimic many commercial solutions that chose to violate the
* XSL specification.
* @see CorrespondingPropertyMaker#compute(PropertyList)
*/
public Property computeAlternativeRuleset(PropertyList propertyList) throws PropertyException {
PropertyList pList = getWMPropertyList(propertyList);
if (pList == null) {
return null;
}

// Calculate the values as described in 5.3.2.

Numeric padding = getCorresponding(paddingCorresponding, propertyList).getNumeric();
Numeric border = getCorresponding(borderWidthCorresponding, propertyList).getNumeric();
int marginProp = pList.getWritingMode(lr_tb, rl_tb, tb_rl);

//Determine whether the nearest anscestor indent was specified through
//start-indent|end-indent or through a margin property.
boolean marginNearest = false;
PropertyList pl = propertyList.getParentPropertyList();
while (pl != null) {
if (pl.getExplicit(baseMaker.propId) != null) {
break;
} else if (pl.getExplicitOrShorthand(marginProp) != null) {
marginNearest = true;
break;
}
pl = pl.getParentPropertyList();
}
Numeric margin;
// Calculate the absolute margin.
if (propertyList.getExplicitOrShorthand(marginProp) == null) {
Property indent = propertyList.getExplicit(baseMaker.propId);
if (indent == null) {
//Neither start-indent nor margin is specified, use inherited
if (isInherited(propertyList) || !marginNearest) {
return null;
} else {
return new FixedLength(0);
}
} else {
return indent;
}
} else {
margin = propertyList.get(marginProp).getNumeric();
}
Numeric v = new FixedLength(0);
if (isInherited(propertyList)) {
// The inherited_value_of([start|end]-indent)
v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric());
}
// The corresponding absolute margin-[right|left}.
v = NumericOp.addition(v, margin);
v = NumericOp.addition(v, padding);
v = NumericOp.addition(v, border);
return (Property) v;
}
private Property getCorresponding(int[] corresponding, PropertyList propertyList)
throws PropertyException {
PropertyList pList = getWMPropertyList(propertyList);

+ 53
- 0
test/fotree/testcases/indent-inheritance1.fo View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2005 The Apache Software Foundation

Licensed 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$ -->
<!-- This test verifies basic start-indent and end-indent inheritance. -->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:test="http://xmlgraphics.apache.org/fop/test">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21cm" margin="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block>Hello World!
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block start-indent="10pt" end-indent="15pt">Hello World!
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="15000mpt"/>
<fo:block>nested
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="15000mpt"/>
</fo:block>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="15000mpt"/>
<fo:block>nested in b-c
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="15000mpt"/>
<fo:block>nested2 in b-c
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="15000mpt"/>
</fo:block>
</fo:block>
</fo:block-container>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>

+ 133
- 0
test/fotree/testcases/indent-inheritance2.fo View File

@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2005 The Apache Software Foundation

Licensed 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$ -->
<!-- This test verifies basic start-indent and end-indent inheritance. -->
<?fop-useragent-break-indent-inheritance false?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:test="http://xmlgraphics.apache.org/fop/test">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21cm" margin="2cm">
<fo:region-body background-color="lightgrey"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-style="italic">start-indent specified on outer block</fo:block>
<fo:block background-color="#FFFFCC">unindented
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block background-color="yellow" start-indent="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">start-indent specified on outer block (reset to 0pt on inner block and the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" start-indent="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block start-indent="0pt" background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container start-indent="0pt">
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">start-indent specified on outer block (reset to 0pt on nested block in the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" start-indent="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block start-indent="0pt" background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">margin-left specified on outer block</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" margin-left="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">margin-left specified on outer block (set to 0pt on inner block and the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" margin-left="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block margin-left="0pt" background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container margin-left="0pt">
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">margin-left specified on outer block (reset to 0pt on nested block in the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" margin-left="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block margin-left="0pt" background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>

+ 163
- 0
test/fotree/testcases/indent-inheritance2a.fo View File

@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2005 The Apache Software Foundation

Licensed 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$ -->
<!-- This test verifies basic start-indent and end-indent inheritance with broken indent inheritance enabled. -->
<?fop-useragent-break-indent-inheritance true?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:test="http://xmlgraphics.apache.org/fop/test">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21cm" margin="2cm">
<fo:region-body background-color="lightgrey"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-style="italic">start-indent specified on outer block</fo:block>
<fo:block background-color="#FFFFCC">unindented
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block background-color="yellow" start-indent="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">start-indent specified on outer block (reset to 0pt on inner block and the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" start-indent="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block start-indent="0pt" background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container start-indent="0pt">
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">start-indent specified on outer block (reset to 0pt on nested block in the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" start-indent="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block start-indent="0pt" background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">margin-left specified on outer block</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" margin-left="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block margin-left="5pt" background-color="orange">fo:block|fo:block (further indented using margin-left)
<test:assert property="start-indent" expected="15000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">margin-left specified on outer block (set to 0pt on inner block and the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" margin-left="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block margin-left="0pt" background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container margin-left="0pt">
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">margin-left specified on outer block (reset to 0pt on nested block in the block-container)</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" margin-left="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block-container>
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block margin-left="0pt" background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
<fo:block space-before="10pt" font-style="italic">margin-left specified on outer block and start-indent on nested elements</fo:block>
<fo:block background-color="#FFFFCC">unindented</fo:block>
<fo:block background-color="yellow" margin-left="10pt">fo:block
<test:assert property="start-indent" expected="10000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block start-indent="30pt" background-color="orange">fo:block|fo:block
<test:assert property="start-indent" expected="30000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block-container start-indent="30pt" background-color="gray">
<test:assert property="start-indent" expected="30000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
<fo:block background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="30000mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block start-indent="0pt" background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
<fo:block margin-left="0pt" background-color="red">fo:block|fo:block-container|fo:block
<test:assert property="start-indent" expected="0mpt"/>
<test:assert property="end-indent" expected="0mpt"/>
</fo:block>
</fo:block-container>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>

+ 40
- 5
test/java/org/apache/fop/fotreetest/FOTreeTester.java View File

@@ -21,6 +21,8 @@ package org.apache.fop.fotreetest;
import java.io.File;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.sax.SAXResult;
@@ -32,6 +34,10 @@ import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;

import org.apache.fop.fotreetest.ext.TestElementMapping;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLFilterImpl;

/**
* Test driver class for FO tree tests.
@@ -50,19 +56,28 @@ public class FOTreeTester {
ResultCollector collector = ResultCollector.getInstance();
collector.reset();
//Setup identity Transformer
Transformer transformer = tfactory.newTransformer();
Source src = new StreamSource(testFile);
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(false);
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
//Setup FOP for area tree rendering
FOUserAgent ua = new FOUserAgent();
ua.setBaseURL(testFile.getParentFile().toURL().toString());
ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua));
ua.addElementMapping(new TestElementMapping());

//Used to set values in the user agent through processing instructions
reader = new PIListener(reader, ua);
Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua);
SAXResult fores = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, fores);
reader.setContentHandler(fop.getDefaultHandler());
reader.setDTDHandler(fop.getDefaultHandler());
reader.setErrorHandler(fop.getDefaultHandler());
reader.setEntityResolver(fop.getDefaultHandler());
reader.parse(testFile.toURL().toExternalForm());
List results = collector.getResults();
if (results.size() > 0) {
@@ -73,4 +88,24 @@ public class FOTreeTester {
}
}

private class PIListener extends XMLFilterImpl {
private FOUserAgent userAgent;
public PIListener(XMLReader parent, FOUserAgent userAgent) {
super(parent);
this.userAgent = userAgent;
}

/** @see org.xml.sax.helpers.XMLFilterImpl */
public void processingInstruction(String target, String data) throws SAXException {
if ("fop-useragent-break-indent-inheritance".equals(target)) {
userAgent.setBreakIndentInheritanceOnReferenceAreaBoundary(
Boolean.valueOf(data).booleanValue());
}
super.processingInstruction(target, data);
}
}
}

Loading…
Cancel
Save