Return-Path: Delivered-To: apmail-xmlgraphics-commits-archive@www.apache.org Received: (qmail 59133 invoked from network); 20 Aug 2008 15:05:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Aug 2008 15:05:00 -0000 Received: (qmail 91168 invoked by uid 500); 20 Aug 2008 15:04:58 -0000 Mailing-List: contact commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: general@xmlgraphics.apache.org Delivered-To: mailing list commits@xmlgraphics.apache.org Received: (qmail 91159 invoked by uid 99); 20 Aug 2008 15:04:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 08:04:58 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 15:04:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6808F238896B; Wed, 20 Aug 2008 08:04:09 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r687367 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/util/UnitConv.java test/java/org/apache/xmlgraphics/StandardTestSuite.java test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java Date: Wed, 20 Aug 2008 15:04:09 -0000 To: commits@xmlgraphics.apache.org From: acumiskey@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080820150409.6808F238896B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: acumiskey Date: Wed Aug 20 08:04:08 2008 New Revision: 687367 URL: http://svn.apache.org/viewvc?rev=687367&view=rev Log: * Added mptToPt() and ptToMpt() to UnitConv. * Moved UnitConvTestCase from FOP and added to StandardTestSuite. Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java (with props) Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/StandardTestSuite.java Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java?rev=687367&r1=687366&r2=687367&view=diff ============================================================================== --- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java (original) +++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java Wed Aug 20 08:04:08 2008 @@ -5,9 +5,9 @@ * 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. @@ -19,6 +19,8 @@ package org.apache.xmlgraphics.util; +import java.awt.geom.AffineTransform; + /** * Utility class for unit conversions. */ @@ -26,13 +28,13 @@ /** conversion factory from millimeters to inches. */ public static final float IN2MM = 25.4f; - + /** conversion factory from centimeters to inches. */ public static final float IN2CM = 2.54f; - + /** conversion factory from inches to points. */ public static final int IN2PT = 72; - + /** * Converts millimeters (mm) to points (pt) * @param mm the value in mm @@ -59,7 +61,7 @@ public static double pt2mm(double pt) { return pt * IN2MM / IN2PT; } - + /** * Converts millimeters (mm) to inches (in) * @param mm the value in mm @@ -68,7 +70,7 @@ public static double mm2in(double mm) { return mm / IN2MM; } - + /** * Converts inches (in) to millimeters (mm) * @param in the value in inches @@ -77,7 +79,7 @@ public static double in2mm(double in) { return in * IN2MM; } - + /** * Converts inches (in) to millipoints (mpt) * @param in the value in inches @@ -86,7 +88,7 @@ public static double in2mpt(double in) { return in * IN2PT * 1000; } - + /** * Converts inches (in) to points (pt) * @param in the value in inches @@ -95,16 +97,16 @@ public static double in2pt(double in) { return in * IN2PT; } - + /** - * Converts millipoints (mpt) to inches (in) + * Converts millipoints (mpt) to inches (in) * @param mpt the value in mpt * @return the value in inches */ public static double mpt2in(double mpt) { return mpt / IN2PT / 1000; } - + /** * Converts millimeters (mm) to pixels (px) * @param mm the value in mm @@ -125,4 +127,32 @@ return mpt2in(mpt) * resolution; } + /** + * Converts a millipoint-based transformation matrix to points. + * @param at a millipoint-based transformation matrix + * @return a point-based transformation matrix + */ + public static AffineTransform mptToPt(AffineTransform at) { + double[] matrix = new double[6]; + at.getMatrix(matrix); + //Convert to points + matrix[4] = matrix[4] / 1000; + matrix[5] = matrix[5] / 1000; + return new AffineTransform(matrix); + } + + /** + * Converts a point-based transformation matrix to millipoints. + * @param at a point-based transformation matrix + * @return a millipoint-based transformation matrix + */ + public static AffineTransform ptToMpt(AffineTransform at) { + double[] matrix = new double[6]; + at.getMatrix(matrix); + //Convert to millipoints + matrix[4] = matrix[4] * 1000; + matrix[5] = matrix[5] * 1000; + return new AffineTransform(matrix); + } + } Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/StandardTestSuite.java URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/StandardTestSuite.java?rev=687367&r1=687366&r2=687367&view=diff ============================================================================== --- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/StandardTestSuite.java (original) +++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/StandardTestSuite.java Wed Aug 20 08:04:08 2008 @@ -5,9 +5,9 @@ * 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. @@ -16,7 +16,7 @@ */ /* $Id$ */ - + package org.apache.xmlgraphics; import org.apache.xmlgraphics.image.codec.png.PNGEncoderTest; @@ -25,6 +25,7 @@ import org.apache.xmlgraphics.ps.dsc.tools.DSCToolsTestCase; import org.apache.xmlgraphics.util.ClasspathResourceTest; import org.apache.xmlgraphics.util.ServiceTest; +import org.apache.xmlgraphics.util.UnitConvTestCase; import org.apache.xmlgraphics.util.io.ASCII85InputStreamTestCase; import org.apache.xmlgraphics.util.io.ASCII85OutputStreamTestCase; import org.apache.xmlgraphics.util.io.Base64Test; @@ -54,6 +55,7 @@ suite.addTest(new TestSuite(PSEscapeTestCase.class)); suite.addTest(new TestSuite(DSCValueParserTestCase.class)); suite.addTest(new TestSuite(DSCToolsTestCase.class)); + suite.addTest(new TestSuite(UnitConvTestCase.class)); //$JUnit-END$ return suite; } Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java?rev=687367&view=auto ============================================================================== --- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java (added) +++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java Wed Aug 20 08:04:08 2008 @@ -0,0 +1,48 @@ +/* + * 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$ */ + +package org.apache.xmlgraphics.util; + +import org.apache.xmlgraphics.util.UnitConv; + +import junit.framework.TestCase; + +/** + * Test class for UnitConv. + */ +public class UnitConvTestCase extends TestCase { + + /** + * Test all kinds of unit conversions. + * @throws Exception if the test fails + */ + public void testConversions() throws Exception { + assertEquals("in2mm", 25.4, UnitConv.in2mm(1), 0.00001); + assertEquals("mm2in", 1.0, UnitConv.mm2in(25.4), 0.00001); + assertEquals("mm2pt", 841.890, UnitConv.mm2pt(297), 0.001 / 2); //height of an A4 page + assertEquals("mm2mpt", 841890, UnitConv.mm2mpt(297), 1.0 / 2); + assertEquals("pt2mm", 297, UnitConv.pt2mm(841.890), 0.0001); + assertEquals("in2mpt", 792000, UnitConv.in2mpt(11.0), 1.0 / 2); //height of a letter page + assertEquals("mpt2in", 11.0, UnitConv.mpt2in(792000), 0.01 / 2); //height of a letter page + + assertEquals("mm2px/72dpi", 841.8897764234434, UnitConv.mm2px(297.0, 72), 0); + assertEquals("mm2px/300dpi", 3507.8740684310146, UnitConv.mm2px(297.0, 300), 0); + } + +} \ No newline at end of file Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java ------------------------------------------------------------------------------ svn:keywords = Revision Id --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: commits-help@xmlgraphics.apache.org