xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adelme...@apache.org
Subject svn commit: r766492 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fo/expr/ src/java/org/apache/fop/fo/properties/ test/fotree/testcases/ test/java/org/apache/fop/fotreetest/ test/java/org/apache/fop/fotreetest/ext/
Date Sun, 19 Apr 2009 17:54:06 GMT
Author: adelmelle
Date: Sun Apr 19 17:54:06 2009
New Revision: 766492

URL: http://svn.apache.org/viewvc?rev=766492&view=rev
Log:
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.

Added:
    xmlgraphics/fop/trunk/test/fotree/testcases/pixel_length_96dpi.fo   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ResultCollector.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ext/AssertElement.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java?rev=766492&r1=766491&r2=766492&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java Sun Apr 19 17:54:06
2009
@@ -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.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 @@
                 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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java?rev=766492&r1=766491&r2=766492&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java Sun Apr
19 17:54:06 2009
@@ -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 @@
             }
             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) {

Added: xmlgraphics/fop/trunk/test/fotree/testcases/pixel_length_96dpi.fo
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/fotree/testcases/pixel_length_96dpi.fo?rev=766492&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/fotree/testcases/pixel_length_96dpi.fo (added)
+++ xmlgraphics/fop/trunk/test/fotree/testcases/pixel_length_96dpi.fo Sun Apr 19 17:54:06
2009
@@ -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>

Propchange: xmlgraphics/fop/trunk/test/fotree/testcases/pixel_length_96dpi.fo
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/fotree/testcases/pixel_length_96dpi.fo
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java?rev=766492&r1=766491&r2=766492&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java Sun Apr 19
17:54:06 2009
@@ -32,6 +32,7 @@
 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 @@
         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 @@
         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 @@
             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);
         }

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ResultCollector.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ResultCollector.java?rev=766492&r1=766491&r2=766492&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ResultCollector.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ResultCollector.java Sun Apr
19 17:54:06 2009
@@ -23,7 +23,7 @@
 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 @@
 
     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 @@
     }
 
     /**
-     * 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. */

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ext/AssertElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ext/AssertElement.java?rev=766492&r1=766491&r2=766492&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ext/AssertElement.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/ext/AssertElement.java Sun Apr
19 17:54:06 2009
@@ -41,7 +41,10 @@
 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 @@
 
         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 @@
         }
         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 @@
             }
             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 @@
     }
 
 }
-



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message