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.
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
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) {
currentIPPosition = saveIP;
currentBPPosition = saveBP;
- currentBPPosition += (int)(bv.getAllocBPD());
+ currentBPPosition += (bv.getAllocBPD());
}
}
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.
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;
* 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.
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;
}
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.
/** The PCL generator */
protected PCLGenerator gen;
- private boolean failOnUnsupportedFeature = true;
+ private final boolean failOnUnsupportedFeature = true;
private boolean clippingDisabled = false;
/**
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.
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);
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.
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();
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
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;
* 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.
/** @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 {
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
currentIPPosition = saveIP;
currentBPPosition = saveBP;
- currentBPPosition += (int)(bv.getAllocBPD());
+ currentBPPosition += (bv.getAllocBPD());
}
//currentFontName = saveFontName;
}
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;
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.
* 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;
private char fillChar;
/** Saves current coordinate transformation. */
- private TXTState currentState = new TXTState();
+ private final TXTState currentState = new TXTState();
private String encoding;
+++ /dev/null
-/*
- * 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);
- }
-
-}
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;
/**
//$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));
+++ /dev/null
-/*
- * 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