Browse Source

Bugzilla 47027: Correction for interpretation of pixel-lengths, as suggested by Jeremias.

+ minor changes to the fotreetest-classes: distinguish between fatal errors due to malformed testcases, and genuine assertion failures.


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@766492 13f79535-47bb-0310-9956-ffa450edef68
pull/37/head
Andreas L. Delmelle 15 years ago
parent
commit
5ef6dcbcbc

+ 9
- 6
src/java/org/apache/fop/fo/expr/PropertyParser.java View File

@@ -19,6 +19,12 @@

package org.apache.fop.fo.expr;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.apache.xmlgraphics.util.UnitConv;

import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.LengthBase;
import org.apache.fop.datatypes.Numeric;
@@ -31,10 +37,6 @@ import org.apache.fop.fo.properties.PercentLength;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.StringProperty;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
* Class to parse XSL-FO property expressions.
* This class is heavily based on the epxression parser in James Clark's
@@ -312,10 +314,11 @@ public final class PropertyParser extends PropertyTokenizer {
if ("px".equals(unitPart)) {
//pass the ratio between target-resolution and
//the default resolution of 72dpi
float resolution = propInfo.getPropertyList().getFObj()
.getUserAgent().getSourceResolution();
prop = FixedLength.getInstance(
numPart, unitPart,
propInfo.getPropertyList().getFObj()
.getUserAgent().getTargetResolution() / 72.0f);
UnitConv.IN2PT / resolution);
} else {
//use default resolution of 72dpi
prop = FixedLength.getInstance(numPart, unitPart);

+ 4
- 1
src/java/org/apache/fop/fo/properties/LengthProperty.java View File

@@ -19,6 +19,8 @@

package org.apache.fop.fo.properties;

import org.apache.xmlgraphics.util.UnitConv;

import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.Numeric;
import org.apache.fop.fo.FObj;
@@ -57,9 +59,10 @@ public abstract class LengthProperty extends Property
}
if (p instanceof NumberProperty) {
//Assume pixels (like in HTML) when there's no unit
float resolution = propertyList.getFObj().getUserAgent().getSourceResolution();
return FixedLength.getInstance(
p.getNumeric().getNumericValue(), "px",
propertyList.getFObj().getUserAgent().getTargetResolution() / 72.0f);
UnitConv.IN2PT / resolution);
}
Length val = p.getLength();
if (val != null) {

+ 34
- 0
test/fotree/testcases/pixel_length_96dpi.fo View File

@@ -0,0 +1,34 @@
<?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$ -->
<?fop-source-resolution 144?>
<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="normal" page-width="5in" page-height="5in">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="normal">
<fo:flow flow-name="xsl-region-body">
<fo:block-container inline-progression-dimension="144px">
<test:assert property="inline-progression-dimension.optimum" expected="72000mpt" />
<fo:block>Block 1</fo:block>
</fo:block-container>
</fo:flow>
</fo:page-sequence>
</fo:root>

+ 17
- 4
test/java/org/apache/fop/fotreetest/FOTreeTester.java View File

@@ -32,6 +32,7 @@ import org.xml.sax.helpers.XMLFilterImpl;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryConfigurator;
import org.apache.fop.fotreetest.ext.TestElementMapping;
import org.apache.fop.util.ConsoleEventListenerForTests;

@@ -64,8 +65,13 @@ public class FOTreeTester {
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();

//Resetting values modified by processing instructions
fopFactory.setBreakIndentInheritanceOnReferenceAreaBoundary(
FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE);
fopFactory.setSourceResolution(FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION);

FOUserAgent ua = fopFactory.newFOUserAgent();
ua.setBaseURL(testFile.getParentFile().toURL().toString());
ua.setBaseURL(testFile.getParentFile().toURI().toURL().toString());
ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua));
ua.getEventBroadcaster().addEventListener(
new ConsoleEventListenerForTests(testFile.getName()));
@@ -79,14 +85,19 @@ public class FOTreeTester {
reader.setDTDHandler(fop.getDefaultHandler());
reader.setErrorHandler(fop.getDefaultHandler());
reader.setEntityResolver(fop.getDefaultHandler());
reader.parse(testFile.toURL().toExternalForm());
try {
reader.parse(testFile.toURI().toURL().toExternalForm());
} catch (Exception e) {
collector.notifyError(e.getLocalizedMessage());
throw e;
}

List results = collector.getResults();
if (results.size() > 0) {
for (int i = 0; i < results.size(); i++) {
System.out.println(((Exception)results.get(i)).getMessage());
System.out.println((String)results.get(i));
}
throw (Exception)results.get(0);
throw new IllegalStateException((String)results.get(0));
}
}

@@ -104,6 +115,8 @@ public class FOTreeTester {
if ("fop-useragent-break-indent-inheritance".equals(target)) {
userAgent.getFactory().setBreakIndentInheritanceOnReferenceAreaBoundary(
Boolean.valueOf(data).booleanValue());
} else if ("fop-source-resolution".equals(target)) {
userAgent.getFactory().setSourceResolution(Float.parseFloat(data));
}
super.processingInstruction(target, data);
}

+ 18
- 7
test/java/org/apache/fop/fotreetest/ResultCollector.java View File

@@ -23,7 +23,7 @@ import java.util.Collections;
import java.util.List;

/**
* This class collects the results from assertions injected into the FO stream.
* This class collects failures for assertions injected into the FO stream.
*/
public class ResultCollector {

@@ -31,7 +31,7 @@ public class ResultCollector {

private List results = new java.util.ArrayList();

/** @return the ResultColletor singleton */
/** @return the ResultCollector singleton */
public static ResultCollector getInstance() {
if (instance == null) {
instance = new ResultCollector();
@@ -45,12 +45,23 @@ public class ResultCollector {
}

/**
* This notifies the ResultCollector about an Exception.
* @param e the exception
* This notifies the ResultCollector about an assertion failure.
*
* @param message the message containing the details
*/
public void notifyException(Exception e) {
System.out.println(e.getMessage());
results.add(e);
public void notifyAssertionFailure(String message) {
System.out.println(message);
results.add(message);
}

/**
* This notifies the ResultCollector about a testcase that ended
* with a fatal error
*
* @param message the message containing the details
*/
public void notifyError(String message) {
results.add(message);
}

/** Resets the result list. */

+ 10
- 9
test/java/org/apache/fop/fotreetest/ext/AssertElement.java View File

@@ -41,7 +41,10 @@ import org.xml.sax.Locator;
public class AssertElement extends TestObj {

/**
* @see org.apache.fop.fo.FONode#FONode(FONode)
* Creates a new AssertElement instance that is a child
* of the given {@link FONode}
*
* @param parent the parent {@link FONode}
*/
public AssertElement(FONode parent) {
super(parent);
@@ -58,6 +61,7 @@ public class AssertElement extends TestObj {

ResultCollector collector = ResultCollector.getInstance();
String propName = attlist.getValue("property");
String expected = attlist.getValue("expected");
String component = null;
int dotIndex = propName.indexOf('.');
if (dotIndex >= 0) {
@@ -66,8 +70,7 @@ public class AssertElement extends TestObj {
}
int propID = FOPropertyMapping.getPropertyId(propName);
if (propID < 0) {
collector.notifyException(new IllegalArgumentException(
"Property not found: " + propName));
collector.notifyAssertionFailure("Property not found: " + propName);
} else {
Property prop;
prop = propertyList.getParentPropertyList().get(propID);
@@ -94,21 +97,20 @@ public class AssertElement extends TestObj {
}
String s;
if (prop instanceof PercentLength) {
s = ((PercentLength)prop).getString();
s = prop.getString();
} else {
s = String.valueOf(prop);
}
String expected = attlist.getValue("expected");
if (!expected.equals(s)) {
collector.notifyException(
new IllegalStateException(locator.getSystemId()
collector.notifyAssertionFailure(
locator.getSystemId()
+ "\nProperty '" + propName
+ "' expected to evaluate to '" + expected
+ "' but got '" + s
+ "'\n(test:assert in "
+ propertyList.getParentFObj().getName()
+ " at line #" + locator.getLineNumber()
+ ", column #" + locator.getColumnNumber() + ")\n"));
+ ", column #" + locator.getColumnNumber() + ")\n");
}
}

@@ -120,4 +122,3 @@ public class AssertElement extends TestObj {
}

}


Loading…
Cancel
Save