aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-08-20 15:13:56 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-08-20 15:13:56 +0000
commite4a6a478b3506acb88943481ce1e1cb79419c831 (patch)
tree7c9b60f515f747d49137d6c15e072722d55a9231
parent93cf2f0568fa528b79b511c53ff6f1a5a5e69439 (diff)
downloadxmlgraphics-fop-e4a6a478b3506acb88943481ce1e1cb79419c831.tar.gz
xmlgraphics-fop-e4a6a478b3506acb88943481ce1e1cb79419c831.zip
* Updated xmlgraphics-commons-14svn.jar to reflect UnitConv additions.
* Removed UnitConv and its unit test case (now resides in commons). * Updated all fop util package references fpr UnitConv to xmlgraphics commons util package. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@687369 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--lib/xmlgraphics-commons-1.4svn.jarbin518201 -> 522588 bytes
-rw-r--r--src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java2
-rw-r--r--src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java8
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLGenerator.java9
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLGraphics2D.java4
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java4
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLPageDefinition.java12
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLRenderer.java20
-rw-r--r--src/java/org/apache/fop/render/txt/TXTRenderer.java8
-rw-r--r--src/java/org/apache/fop/util/UnitConv.java158
-rw-r--r--test/java/org/apache/fop/UtilityCodeTestSuite.java6
-rw-r--r--test/java/org/apache/fop/util/UnitConvTestCase.java46
12 files changed, 35 insertions, 242 deletions
diff --git a/lib/xmlgraphics-commons-1.4svn.jar b/lib/xmlgraphics-commons-1.4svn.jar
index 6c836d46c..5072d3fc7 100644
--- a/lib/xmlgraphics-commons-1.4svn.jar
+++ b/lib/xmlgraphics-commons-1.4svn.jar
Binary files differ
diff --git a/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java b/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
index 3f9135d2a..5861fb042 100644
--- a/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
+++ b/src/java/org/apache/fop/render/AbstractGraphics2DAdapter.java
@@ -35,7 +35,7 @@ import java.awt.image.WritableRaster;
import java.io.IOException;
import org.apache.fop.render.RendererContext.RendererContextWrapper;
-import org.apache.fop.util.UnitConv;
+import org.apache.xmlgraphics.util.UnitConv;
/**
* Abstract base class for Graphics2DAdapter implementations.
diff --git a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
index 0bfd7980b..65bb450f3 100644
--- a/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
+++ b/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
@@ -48,7 +48,7 @@ import org.apache.fop.fo.Constants;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fonts.FontMetrics;
import org.apache.fop.traits.BorderProps;
-import org.apache.fop.util.UnitConv;
+import org.apache.xmlgraphics.util.UnitConv;
/**
* Abstract base class for renderers like PDF and PostScript where many painting operations
@@ -485,8 +485,8 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer {
int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore();
//This is the content-rect
- float width = (float)bv.getIPD() / 1000f;
- float height = (float)bv.getBPD() / 1000f;
+ float width = bv.getIPD() / 1000f;
+ float height = bv.getBPD() / 1000f;
if (bv.getPositioning() == Block.ABSOLUTE
|| bv.getPositioning() == Block.FIXED) {
@@ -581,7 +581,7 @@ public abstract class AbstractPathOrientedRenderer extends PrintRenderer {
currentIPPosition = saveIP;
currentBPPosition = saveBP;
- currentBPPosition += (int)(bv.getAllocBPD());
+ currentBPPosition += (bv.getAllocBPD());
}
}
diff --git a/src/java/org/apache/fop/render/pcl/PCLGenerator.java b/src/java/org/apache/fop/render/pcl/PCLGenerator.java
index d1b6f6578..45af4df89 100644
--- a/src/java/org/apache/fop/render/pcl/PCLGenerator.java
+++ b/src/java/org/apache/fop/render/pcl/PCLGenerator.java
@@ -45,8 +45,7 @@ import java.util.Locale;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.xmlgraphics.image.GraphicsUtil;
-
-import org.apache.fop.util.UnitConv;
+import org.apache.xmlgraphics.util.UnitConv;
/**
* This class provides methods for generating PCL print files.
@@ -68,7 +67,7 @@ public class PCLGenerator {
private final DecimalFormat df2 = new DecimalFormat("0.##", symbols);
private final DecimalFormat df4 = new DecimalFormat("0.####", symbols);
- private OutputStream out;
+ private final OutputStream out;
private boolean currentSourceTransparency = true;
private boolean currentPatternTransparency = true;
@@ -79,7 +78,7 @@ public class PCLGenerator {
* true: Standard PCL shades are used (poor quality). false: user-defined pattern are used
* to create custom dither patterns for better grayscale quality.
*/
- private boolean usePCLShades = false;
+ private final boolean usePCLShades = false;
/**
* Main constructor.
@@ -400,7 +399,7 @@ public class PCLGenerator {
private static void setValueInMatrix(int[] dn, int half, int part, int idx, int value) {
int xoff = (part & 1) * half;
int yoff = (part & 2) * half * half;
- int matrixIndex = yoff + ((int)(idx / half) * half * 2) + (idx % half) + xoff;
+ int matrixIndex = yoff + ((idx / half) * half * 2) + (idx % half) + xoff;
dn[matrixIndex] = value;
}
diff --git a/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java b/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java
index 3eef38b6b..ded87a057 100644
--- a/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java
+++ b/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java
@@ -42,9 +42,9 @@ import java.awt.image.renderable.RenderableImage;
import java.io.IOException;
import java.text.AttributedCharacterIterator;
-import org.apache.fop.util.UnitConv;
import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.util.UnitConv;
/**
* Graphics2D implementation implementing PCL and HP GL/2.
@@ -55,7 +55,7 @@ public class PCLGraphics2D extends AbstractGraphics2D {
/** The PCL generator */
protected PCLGenerator gen;
- private boolean failOnUnsupportedFeature = true;
+ private final boolean failOnUnsupportedFeature = true;
private boolean clippingDisabled = false;
/**
diff --git a/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java b/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
index 3878a84fb..f8c9682e9 100644
--- a/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
+++ b/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java
@@ -34,7 +34,7 @@ import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
import org.apache.fop.render.AbstractGraphics2DAdapter;
import org.apache.fop.render.RendererContext;
-import org.apache.fop.util.UnitConv;
+import org.apache.xmlgraphics.util.UnitConv;
/**
* Graphics2DAdapter implementation for PCL and HP GL/2.
@@ -111,7 +111,7 @@ public class PCLGraphics2DAdapter extends AbstractGraphics2DAdapter {
if (!painted) {
//Fallback solution: Paint to a BufferedImage
- int resolution = (int)Math.round(context.getUserAgent().getTargetResolution());
+ int resolution = Math.round(context.getUserAgent().getTargetResolution());
BufferedImage bi = paintToBufferedImage(painter, pclContext,
resolution, !pclContext.isColorCanvas(), false);
diff --git a/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java b/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java
index e8c8814ab..e03a86b94 100644
--- a/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java
+++ b/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java
@@ -24,7 +24,7 @@ import java.awt.Rectangle;
import java.util.Iterator;
import java.util.List;
-import org.apache.fop.util.UnitConv;
+import org.apache.xmlgraphics.util.UnitConv;
/**
* This class represents a page format with PCL-specific properties.
@@ -34,11 +34,11 @@ public class PCLPageDefinition {
private static List pageDefinitions;
private static PCLPageDefinition defaultPageDefinition;
- private String name;
- private int selector;
- private Dimension physicalPageSize;
- private Rectangle logicalPageRect;
- private boolean landscape;
+ private final String name;
+ private final int selector;
+ private final Dimension physicalPageSize;
+ private final Rectangle logicalPageRect;
+ private final boolean landscape;
static {
createPageDefinitions();
diff --git a/src/java/org/apache/fop/render/pcl/PCLRenderer.java b/src/java/org/apache/fop/render/pcl/PCLRenderer.java
index 627e31b95..5896ad318 100644
--- a/src/java/org/apache/fop/render/pcl/PCLRenderer.java
+++ b/src/java/org/apache/fop/render/pcl/PCLRenderer.java
@@ -97,7 +97,7 @@ import org.apache.fop.render.java2d.InstalledFontCollection;
import org.apache.fop.render.java2d.Java2DRenderer;
import org.apache.fop.render.pcl.extensions.PCLElementMapping;
import org.apache.fop.traits.BorderProps;
-import org.apache.fop.util.UnitConv;
+import org.apache.xmlgraphics.util.UnitConv;
/* Note:
* There are some commonalities with AbstractPathOrientedRenderer but it's not possible
@@ -128,7 +128,7 @@ public class PCLRenderer extends PrintRenderer {
protected PCLGenerator gen;
private boolean ioTrouble = false;
- private Stack graphicContextStack = new Stack();
+ private final Stack graphicContextStack = new Stack();
private GraphicContext graphicContext = new GraphicContext();
private PCLPageDefinition currentPageDefinition;
@@ -153,7 +153,7 @@ public class PCLRenderer extends PrintRenderer {
* This can be used to work around problems with Apache Batik, for example, but setting
* this to true will increase memory consumption.
*/
- private boolean useColorCanvas = false;
+ private final boolean useColorCanvas = false;
/**
* Controls whether the generation of PJL commands gets disabled.
@@ -245,7 +245,7 @@ public class PCLRenderer extends PrintRenderer {
/** @return the target resolution */
protected int getResolution() {
- int resolution = (int)Math.round(userAgent.getTargetResolution());
+ int resolution = Math.round(userAgent.getTargetResolution());
if (resolution <= 300) {
return 300;
} else {
@@ -945,8 +945,8 @@ public class PCLRenderer extends PrintRenderer {
int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore();
//This is the content-rect
- float width = (float)bv.getIPD() / 1000f;
- float height = (float)bv.getBPD() / 1000f;
+ float width = bv.getIPD() / 1000f;
+ float height = bv.getBPD() / 1000f;
if (bv.getPositioning() == Block.ABSOLUTE
@@ -1034,7 +1034,7 @@ public class PCLRenderer extends PrintRenderer {
currentIPPosition = saveIP;
currentBPPosition = saveBP;
- currentBPPosition += (int)(bv.getAllocBPD());
+ currentBPPosition += (bv.getAllocBPD());
}
//currentFontName = saveFontName;
}
@@ -1433,13 +1433,13 @@ public class PCLRenderer extends PrintRenderer {
borderRect.width,
borderRect.height);
final Rectangle paintRect = new Rectangle(
- (int)Math.round(borderRect.x * 1000f),
- (int)Math.round(borderRect.y * 1000f),
+ Math.round(borderRect.x * 1000f),
+ Math.round(borderRect.y * 1000f),
(int)Math.floor(borderRect.width * 1000f) + 1,
(int)Math.floor(borderRect.height * 1000f) + 1);
//Add one pixel wide safety margin around the paint area
int pixelWidth = (int)Math.round(UnitConv.in2mpt(1) / userAgent.getTargetResolution());
- final int xoffset = (int)Math.round(-effBorderRect.x * 1000f) + pixelWidth;
+ final int xoffset = Math.round(-effBorderRect.x * 1000f) + pixelWidth;
final int yoffset = pixelWidth;
paintRect.x += xoffset;
paintRect.y += yoffset;
diff --git a/src/java/org/apache/fop/render/txt/TXTRenderer.java b/src/java/org/apache/fop/render/txt/TXTRenderer.java
index 29f1ef954..575f1232f 100644
--- a/src/java/org/apache/fop/render/txt/TXTRenderer.java
+++ b/src/java/org/apache/fop/render/txt/TXTRenderer.java
@@ -37,7 +37,7 @@ import org.apache.fop.area.inline.TextArea;
import org.apache.fop.render.AbstractPathOrientedRenderer;
import org.apache.fop.render.txt.border.AbstractBorderElement;
import org.apache.fop.render.txt.border.BorderManager;
-import org.apache.fop.util.UnitConv;
+import org.apache.xmlgraphics.util.UnitConv;
/**
* Renderer that renders areas to plain text.
@@ -86,10 +86,10 @@ public class TXTRenderer extends AbstractPathOrientedRenderer {
* Every line except the last line on a page (which will end with
* pageEnding) will be terminated with this string.
*/
- private String lineEnding = "\r\n";
+ private final String lineEnding = "\r\n";
/** Every page except the last one will end with this string. */
- private String pageEnding = "\f";
+ private final String pageEnding = "\f";
/** Equals true, if current page is first. */
private boolean firstPage = false;
@@ -101,7 +101,7 @@ public class TXTRenderer extends AbstractPathOrientedRenderer {
private char fillChar;
/** Saves current coordinate transformation. */
- private TXTState currentState = new TXTState();
+ private final TXTState currentState = new TXTState();
private String encoding;
diff --git a/src/java/org/apache/fop/util/UnitConv.java b/src/java/org/apache/fop/util/UnitConv.java
deleted file mode 100644
index 475e3dcc0..000000000
--- a/src/java/org/apache/fop/util/UnitConv.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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.fop.util;
-
-import java.awt.geom.AffineTransform;
-
-/**
- * Utility class for unit conversions.
- */
-public final class UnitConv {
-
- /** 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
- * @return the value in pt
- */
- public static double mm2pt(double mm) {
- return mm * IN2PT / IN2MM;
- }
-
- /**
- * Converts millimeters (mm) to millipoints (mpt)
- * @param mm the value in mm
- * @return the value in mpt
- */
- public static double mm2mpt(double mm) {
- return mm * 1000 * IN2PT / IN2MM;
- }
-
- /**
- * Converts points (pt) to millimeters (mm)
- * @param pt the value in pt
- * @return the value in mm
- */
- public static double pt2mm(double pt) {
- return pt * IN2MM / IN2PT;
- }
-
- /**
- * Converts millimeters (mm) to inches (in)
- * @param mm the value in mm
- * @return the value in inches
- */
- public static double mm2in(double mm) {
- return mm / IN2MM;
- }
-
- /**
- * Converts inches (in) to millimeters (mm)
- * @param in the value in inches
- * @return the value in mm
- */
- public static double in2mm(double in) {
- return in * IN2MM;
- }
-
- /**
- * Converts inches (in) to millipoints (mpt)
- * @param in the value in inches
- * @return the value in mpt
- */
- public static double in2mpt(double in) {
- return in * IN2PT * 1000;
- }
-
- /**
- * Converts inches (in) to points (pt)
- * @param in the value in inches
- * @return the value in pt
- */
- public static double in2pt(double in) {
- return in * IN2PT;
- }
-
- /**
- * 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
- * @param resolution the resolution in dpi (dots per inch)
- * @return the value in pixels
- */
- public static double mm2px(double mm, int resolution) {
- return mm2in(mm) * resolution;
- }
-
- /**
- * Converts millipoints (mpt) to pixels (px)
- * @param mpt the value in mpt
- * @param resolution the resolution in dpi (dots per inch)
- * @return the value in pixels
- */
- public static double mpt2px(double mpt, int resolution) {
- 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);
- }
-
-}
diff --git a/test/java/org/apache/fop/UtilityCodeTestSuite.java b/test/java/org/apache/fop/UtilityCodeTestSuite.java
index af467102c..6611f532e 100644
--- a/test/java/org/apache/fop/UtilityCodeTestSuite.java
+++ b/test/java/org/apache/fop/UtilityCodeTestSuite.java
@@ -22,14 +22,13 @@ package org.apache.fop;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.fop.pdf.PDFObjectTestCase;
import org.apache.fop.events.BasicEventTestCase;
+import org.apache.fop.pdf.PDFObjectTestCase;
import org.apache.fop.traits.BorderPropsTestCase;
+import org.apache.fop.util.ColorUtilTestCase;
import org.apache.fop.util.DataURIResolverTestCase;
import org.apache.fop.util.ElementListUtilsTestCase;
import org.apache.fop.util.PDFNumberTestCase;
-import org.apache.fop.util.ColorUtilTestCase;
-import org.apache.fop.util.UnitConvTestCase;
import org.apache.fop.util.XMLResourceBundleTestCase;
/**
@@ -47,7 +46,6 @@ public class UtilityCodeTestSuite {
//$JUnit-BEGIN$
suite.addTest(new TestSuite(PDFNumberTestCase.class));
suite.addTest(new TestSuite(PDFObjectTestCase.class));
- suite.addTest(new TestSuite(UnitConvTestCase.class));
suite.addTest(new TestSuite(ColorUtilTestCase.class));
suite.addTest(new TestSuite(BorderPropsTestCase.class));
suite.addTest(new TestSuite(ElementListUtilsTestCase.class));
diff --git a/test/java/org/apache/fop/util/UnitConvTestCase.java b/test/java/org/apache/fop/util/UnitConvTestCase.java
deleted file mode 100644
index a10619199..000000000
--- a/test/java/org/apache/fop/util/UnitConvTestCase.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.fop.util;
-
-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