diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2008-07-25 10:55:49 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2008-07-25 10:55:49 +0000 |
commit | d058e870151a49af34ec1e7204edd0ffc64aaefc (patch) | |
tree | 14c346af79c0d2207f98b17e1e9f0212c8c32f44 /src/java/org/apache/fop/render/pcl | |
parent | cc5d6604bde87fca098633ceccd66fc92808bddc (diff) | |
download | xmlgraphics-fop-d058e870151a49af34ec1e7204edd0ffc64aaefc.tar.gz xmlgraphics-fop-d058e870151a49af34ec1e7204edd0ffc64aaefc.zip |
Merged revisions 679052-679352 via svnmerge from
https://svn.eu.apache.org/repos/asf/xmlgraphics/fop/trunk
........
r679060 | acumiskey | 2008-07-23 11:39:11 +0100 (Wed, 23 Jul 2008) | 2 lines
My bad.. copy paste error I introduced which broke forrest.
........
r679164 | jeremias | 2008-07-23 20:33:24 +0100 (Wed, 23 Jul 2008) | 1 line
Only update the generated files if any source file is newer than the generated ones.
........
r679326 | vhennebert | 2008-07-24 10:35:34 +0100 (Thu, 24 Jul 2008) | 2 lines
Fed up with all those trailing whitespaces. Let's remove them all (once... and for all?)
........
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@679758 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/pcl')
12 files changed, 174 insertions, 174 deletions
diff --git a/src/java/org/apache/fop/render/pcl/DefaultMonochromeBitmapConverter.java b/src/java/org/apache/fop/render/pcl/DefaultMonochromeBitmapConverter.java index 10fcfde3d..418810401 100644 --- a/src/java/org/apache/fop/render/pcl/DefaultMonochromeBitmapConverter.java +++ b/src/java/org/apache/fop/render/pcl/DefaultMonochromeBitmapConverter.java @@ -36,10 +36,10 @@ public class DefaultMonochromeBitmapConverter implements public void setHint(String name, String value) { //ignore, not supported } - + /** {@inheritDoc} */ public RenderedImage convertToMonochrome(BufferedImage img) { - BufferedImage buf = new BufferedImage(img.getWidth(), img.getHeight(), + BufferedImage buf = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_BYTE_BINARY); RenderingHints hints = new RenderingHints(null); //This hint doesn't seem to make a difference :-( diff --git a/src/java/org/apache/fop/render/pcl/JAIMonochromeBitmapConverter.java b/src/java/org/apache/fop/render/pcl/JAIMonochromeBitmapConverter.java index 89e54b917..e9611edac 100644 --- a/src/java/org/apache/fop/render/pcl/JAIMonochromeBitmapConverter.java +++ b/src/java/org/apache/fop/render/pcl/JAIMonochromeBitmapConverter.java @@ -46,20 +46,20 @@ public class JAIMonochromeBitmapConverter implements MonochromeBitmapConverter { private boolean isErrorDiffusion = false; - + /** {@inheritDoc} */ public void setHint(String name, String value) { if ("quality".equalsIgnoreCase(name)) { isErrorDiffusion = "true".equalsIgnoreCase(value); } } - + /** {@inheritDoc} */ public RenderedImage convertToMonochrome(BufferedImage img) { if (img.getColorModel().getColorSpace().getNumComponents() != 1) { throw new IllegalArgumentException("Source image must be a grayscale image!"); } - + // Load the ParameterBlock for the dithering operation // and set the operation name. ParameterBlock pb = new ParameterBlock(); @@ -78,7 +78,7 @@ public class JAIMonochromeBitmapConverter implements pb.add(colorMap); pb.add(KernelJAI.DITHER_MASK_441); } - + //Create an image layout for a monochrome b/w image ImageLayout layout = new ImageLayout(); byte[] map = new byte[] {(byte)0x00, (byte)0xff}; @@ -89,8 +89,8 @@ public class JAIMonochromeBitmapConverter implements RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); // Dither the image. - PlanarImage dst = JAI.create(opName, pb, hints); - + PlanarImage dst = JAI.create(opName, pb, hints); + //Convert it to a BufferedImage return dst.getAsBufferedImage(); } diff --git a/src/java/org/apache/fop/render/pcl/MonochromeBitmapConverter.java b/src/java/org/apache/fop/render/pcl/MonochromeBitmapConverter.java index aae0b90ce..9a960f871 100644 --- a/src/java/org/apache/fop/render/pcl/MonochromeBitmapConverter.java +++ b/src/java/org/apache/fop/render/pcl/MonochromeBitmapConverter.java @@ -33,12 +33,12 @@ public interface MonochromeBitmapConverter { * @param value the value */ void setHint(String name, String value); - + /** - * Converts a grayscale bitmap image to a monochrome (1-bit) b/w bitmap image. + * Converts a grayscale bitmap image to a monochrome (1-bit) b/w bitmap image. * @param img the grayscale image * @return the converted monochrome image */ RenderedImage convertToMonochrome(BufferedImage img); - + } diff --git a/src/java/org/apache/fop/render/pcl/PCLEventProducer.java b/src/java/org/apache/fop/render/pcl/PCLEventProducer.java index 3e72de293..3e95bd4f9 100644 --- a/src/java/org/apache/fop/render/pcl/PCLEventProducer.java +++ b/src/java/org/apache/fop/render/pcl/PCLEventProducer.java @@ -31,7 +31,7 @@ public interface PCLEventProducer extends EventProducer { /** Provider class for the event producer. */ class Provider { - + /** * Returns an event producer. * @param broadcaster the event broadcaster to use @@ -50,9 +50,9 @@ public interface PCLEventProducer extends EventProducer { public EventModel createEventModel() { return loadModel(getClass(), "event-model.xml"); } - + } - + /** * Paper type could not be determined. Falling back to another. * @param source the event source @@ -62,5 +62,5 @@ public interface PCLEventProducer extends EventProducer { * @event.severity WARN */ void paperTypeUnavailable(Object source, long pageWidth, long pageHeight, String fallbackPaper); - + } diff --git a/src/java/org/apache/fop/render/pcl/PCLGenerator.java b/src/java/org/apache/fop/render/pcl/PCLGenerator.java index 6a4425012..d1b6f6578 100644 --- a/src/java/org/apache/fop/render/pcl/PCLGenerator.java +++ b/src/java/org/apache/fop/render/pcl/PCLGenerator.java @@ -55,24 +55,24 @@ public class PCLGenerator { /** The ESC (escape) character */ public static final char ESC = '\033'; - + /** A list of all supported resolutions in PCL (values in dpi) */ public static final int[] PCL_RESOLUTIONS = new int[] {75, 100, 150, 200, 300, 600}; - + /** Selects a 4x4 Bayer dither matrix (17 grayscales) */ public static final int DITHER_MATRIX_4X4 = 4; /** Selects a 8x8 Bayer dither matrix (65 grayscales) */ public static final int DITHER_MATRIX_8X8 = 8; - - private final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); + + private final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US); private final DecimalFormat df2 = new DecimalFormat("0.##", symbols); private final DecimalFormat df4 = new DecimalFormat("0.####", symbols); - + private OutputStream out; - + private boolean currentSourceTransparency = true; private boolean currentPatternTransparency = true; - + private int maxBitmapResolution = PCL_RESOLUTIONS[PCL_RESOLUTIONS.length - 1]; /** @@ -80,7 +80,7 @@ public class PCLGenerator { * to create custom dither patterns for better grayscale quality. */ private boolean usePCLShades = false; - + /** * Main constructor. * @param out the OutputStream to write the PCL stream to @@ -88,7 +88,7 @@ public class PCLGenerator { public PCLGenerator(OutputStream out) { this.out = out; } - + /** * Main constructor. * @param out the OutputStream to write the PCL stream to @@ -108,17 +108,17 @@ public class PCLGenerator { } this.maxBitmapResolution = maxResolution; } - + /** @return the OutputStream that this generator writes to */ public OutputStream getOutputStream() { return this.out; } - + /** @return the maximum resolution to encode bitmap images at */ public int getMaximumBitmapResolution() { return this.maxBitmapResolution; } - + /** * Writes a PCL escape command to the output stream. * @param cmd the command (without the ESCAPE character) @@ -128,7 +128,7 @@ public class PCLGenerator { out.write(27); //ESC out.write(cmd.getBytes("US-ASCII")); } - + /** * Writes raw text (in ISO-8859-1 encoding) to the output stream. * @param s the text @@ -140,7 +140,7 @@ public class PCLGenerator { /** * Formats a double value with two decimal positions for PCL output. - * + * * @param value value to format * @return the formatted value */ @@ -150,7 +150,7 @@ public class PCLGenerator { /** * Formats a double value with four decimal positions for PCL output. - * + * * @param value value to format * @return the formatted value */ @@ -165,7 +165,7 @@ public class PCLGenerator { public void universalEndOfLanguage() throws IOException { writeCommand("%-12345X"); } - + /** * Resets the printer and restores the user default environment. * @throws IOException In case of an I/O error @@ -173,7 +173,7 @@ public class PCLGenerator { public void resetPrinter() throws IOException { writeCommand("E"); } - + /** * Sends the job separation command. * @throws IOException In case of an I/O error @@ -181,7 +181,7 @@ public class PCLGenerator { public void separateJobs() throws IOException { writeCommand("&l1T"); } - + /** * Sends the form feed character. * @throws IOException In case of an I/O error @@ -198,7 +198,7 @@ public class PCLGenerator { public void setUnitOfMeasure(int value) throws IOException { writeCommand("&u" + value + "D"); } - + /** * Sets the raster graphics resolution * @param value the resolution value (units per inch) @@ -207,7 +207,7 @@ public class PCLGenerator { public void setRasterGraphicsResolution(int value) throws IOException { writeCommand("*t" + value + "R"); } - + /** * Selects the page size. * @param selector the integer representing the page size @@ -218,7 +218,7 @@ public class PCLGenerator { } /** - * Selects the paper source. The parameter is usually printer-specific. Usually, "1" is the + * Selects the paper source. The parameter is usually printer-specific. Usually, "1" is the * default tray, "2" is the manual paper feed, "3" is the manual envelope feed, "4" is the * "lower" tray and "7" is "auto-select". Consult the technical reference for your printer * for all available values. @@ -230,8 +230,8 @@ public class PCLGenerator { } /** - * Selects the duplexing mode for the page. - * The parameter is usually printer-specific. + * Selects the duplexing mode for the page. + * The parameter is usually printer-specific. * "0" means Simplex, * "1" means Duplex, Long-Edge Binding, * "2" means Duplex, Short-Edge Binding. @@ -249,7 +249,7 @@ public class PCLGenerator { public void clearHorizontalMargins() throws IOException { writeCommand("9"); } - + /** * The Top Margin command designates the number of lines between * the top of the logical page and the top of the text area. @@ -303,7 +303,7 @@ public class PCLGenerator { public void pushCursorPos() throws IOException { writeCommand("&f0S"); } - + /** * Pops the current cursor position from the stack. * @throws IOException In case of an I/O error @@ -311,7 +311,7 @@ public class PCLGenerator { public void popCursorPos() throws IOException { writeCommand("&f1S"); } - + /** * Changes the current print direction while maintaining the current cursor position. * @param rotate the rotation angle (counterclockwise), one of 0, 90, 180 and 270. @@ -320,10 +320,10 @@ public class PCLGenerator { public void changePrintDirection(int rotate) throws IOException { writeCommand("&a" + rotate + "P"); } - + /** * Enters the HP GL/2 mode. - * @param restorePreviousHPGL2Cursor true if the previous HP GL/2 pen position should be + * @param restorePreviousHPGL2Cursor true if the previous HP GL/2 pen position should be * restored, false if the current position is maintained * @throws IOException In case of an I/O error */ @@ -334,7 +334,7 @@ public class PCLGenerator { writeCommand("%1B"); } } - + /** * Enters the PCL mode. * @param restorePreviousPCLCursor true if the previous PCL cursor position should be restored, @@ -348,7 +348,7 @@ public class PCLGenerator { writeCommand("%1A"); } } - + /** * Generate a filled rectangle at the current cursor position. * @@ -367,10 +367,10 @@ public class PCLGenerator { //y += h; } setPatternTransparencyMode(false); - if (usePCLShades + if (usePCLShades || Color.black.equals(col) || Color.white.equals(col)) { - writeCommand("*c" + formatDouble4(w / 100.0) + "h" + writeCommand("*c" + formatDouble4(w / 100.0) + "h" + formatDouble4(h / 100.0) + "V"); int lineshade = convertToPCLShade(col); writeCommand("*c" + lineshade + "G"); @@ -378,7 +378,7 @@ public class PCLGenerator { } else { defineGrayscalePattern(col, 32, DITHER_MATRIX_4X4); - writeCommand("*c" + formatDouble4(w / 100.0) + "h" + writeCommand("*c" + formatDouble4(w / 100.0) + "h" + formatDouble4(h / 100.0) + "V"); writeCommand("*c32G"); writeCommand("*c4P"); //User-defined pattern @@ -391,19 +391,19 @@ public class PCLGenerator { private static final int[] BAYER_D2 = new int[] {0, 2, 3, 1}; private static final int[] BAYER_D4; private static final int[] BAYER_D8; - + static { BAYER_D4 = deriveBayerMatrix(BAYER_D2); BAYER_D8 = deriveBayerMatrix(BAYER_D4); } - + 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; dn[matrixIndex] = value; } - + private static int[] deriveBayerMatrix(int[] d) { int[] dn = new int[d.length * 4]; int half = (int)Math.sqrt(d.length); @@ -414,7 +414,7 @@ public class PCLGenerator { } return dn; } - + /** * Generates a user-defined pattern for a dithering pattern matching the grayscale value * of the color given. @@ -423,7 +423,7 @@ public class PCLGenerator { * @param ditherMatrixSize the size of the Bayer dither matrix to use (4 or 8 supported) * @throws IOException In case of an I/O error */ - public void defineGrayscalePattern(Color col, int patternID, int ditherMatrixSize) + public void defineGrayscalePattern(Color col, int patternID, int ditherMatrixSize) throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(baout); @@ -436,36 +436,36 @@ public class PCLGenerator { //data.writeShort(600); //X Resolution (didn't manage to get that to work) //data.writeShort(600); //Y Resolution int gray255 = convertToGray(col.getRed(), col.getGreen(), col.getBlue()); - + byte[] pattern; if (ditherMatrixSize == 8) { int gray65 = gray255 * 65 / 255; - + pattern = new byte[BAYER_D8.length / 8]; - + for (int i = 0, c = BAYER_D8.length; i < c; i++) { boolean dot = !(BAYER_D8[i] < gray65 - 1); if (dot) { int byteIdx = i / 8; - pattern[byteIdx] |= 1 << (i % 8); + pattern[byteIdx] |= 1 << (i % 8); } } } else { int gray17 = gray255 * 17 / 255; - - //Since a 4x4 pattern did not work, the 4x4 pattern is applied 4 times to an - //8x8 pattern. Maybe this could be changed to use an 8x8 bayer dither pattern + + //Since a 4x4 pattern did not work, the 4x4 pattern is applied 4 times to an + //8x8 pattern. Maybe this could be changed to use an 8x8 bayer dither pattern //instead of the 4x4 one. pattern = new byte[BAYER_D4.length / 8 * 4]; - + for (int i = 0, c = BAYER_D4.length; i < c; i++) { boolean dot = !(BAYER_D4[i] < gray17 - 1); if (dot) { int byteIdx = i / 4; - pattern[byteIdx] |= 1 << (i % 4); - pattern[byteIdx] |= 1 << ((i % 4) + 4); - pattern[byteIdx + 4] |= 1 << (i % 4); - pattern[byteIdx + 4] |= 1 << ((i % 4) + 4); + pattern[byteIdx] |= 1 << (i % 4); + pattern[byteIdx] |= 1 << ((i % 4) + 4); + pattern[byteIdx + 4] |= 1 << (i % 4); + pattern[byteIdx + 4] |= 1 << ((i % 4) + 4); } } } @@ -525,7 +525,7 @@ public class PCLGenerator { public final int convertToGray(int r, int g, int b) { return (r * 30 + g * 59 + b * 11) / 100; } - + /** * Convert a Color value to a PCL shade value (0-100). * @param col the color @@ -535,7 +535,7 @@ public class PCLGenerator { float gray = convertToGray(col.getRed(), col.getGreen(), col.getBlue()) / 255f; return (int)(100 - (gray * 100f)); } - + /** * Selects the current grayscale color (the given color is converted to grayscales). * @param col the color @@ -555,7 +555,7 @@ public class PCLGenerator { } } } - + /** * Select the current pattern * @param patternID the pattern ID (<ESC>*c#G command) @@ -583,7 +583,7 @@ public class PCLGenerator { return false; } } - + /** * Indicates whether an image is a grayscale image. * @param img the image @@ -592,7 +592,7 @@ public class PCLGenerator { public static boolean isGrayscaleImage(RenderedImage img) { return (img.getColorModel().getColorSpace().getNumComponents() == 1); } - + private MonochromeBitmapConverter createMonochromeBitmapConverter() { MonochromeBitmapConverter converter = null; try { @@ -621,7 +621,7 @@ public class PCLGenerator { private int calculatePCLResolution(int resolution) { return calculatePCLResolution(resolution, false); } - + /** * Calculates the ideal PCL resolution for a given resolution. * @param resolution the input resolution @@ -653,35 +653,35 @@ public class PCLGenerator { } return PCL_RESOLUTIONS[choice]; } - + private boolean isValidPCLResolution(int resolution) { return resolution == calculatePCLResolution(resolution); } - - private Dimension getAdjustedDimension(Dimension orgDim, double orgResolution, + + private Dimension getAdjustedDimension(Dimension orgDim, double orgResolution, int pclResolution) { if (orgResolution == pclResolution) { return orgDim; } else { Dimension result = new Dimension(); - result.width = (int)Math.round((double)orgDim.width * pclResolution / orgResolution); - result.height = (int)Math.round((double)orgDim.height * pclResolution / orgResolution); + result.width = (int)Math.round((double)orgDim.width * pclResolution / orgResolution); + result.height = (int)Math.round((double)orgDim.height * pclResolution / orgResolution); return result; } } - + //Threshold table to convert an alpha channel (8-bit) into a clip mask (1-bit) private static final byte[] THRESHOLD_TABLE = new byte[256]; static { // Initialize the arrays for (int i = 0; i < 256; i++) { THRESHOLD_TABLE[i] = (byte) ((i < 240) ? 255 : 0); } - } - + } + private RenderedImage getMask(RenderedImage img, Dimension targetDim) { - ColorModel cm = img.getColorModel(); + ColorModel cm = img.getColorModel(); if (cm.hasAlpha()) { - BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(), + BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Raster raster = img.getData(); GraphicsUtil.copyBand(raster, cm.getNumColorComponents(), alpha.getRaster(), 0); @@ -700,7 +700,7 @@ public class PCLGenerator { targetDim.width, targetDim.height, 1, 1, null); mask = new BufferedImage(colorModel, wraster, false, null); } - + Graphics2D g2d = mask.createGraphics(); try { AffineTransform at = new AffineTransform(); @@ -732,7 +732,7 @@ public class PCLGenerator { * @param sourceTransparency true if the background should not be erased * @throws IOException In case of an I/O error */ - public void paintBitmap(RenderedImage img, Dimension targetDim, boolean sourceTransparency) + public void paintBitmap(RenderedImage img, Dimension targetDim, boolean sourceTransparency) throws IOException { double targetResolution = img.getWidth() / UnitConv.mpt2in(targetDim.width); int resolution = (int)Math.round(targetResolution); @@ -745,7 +745,7 @@ public class PCLGenerator { if (!monochrome) { //Transparency mask disabled. Doesn't work reliably final boolean transparencyDisabled = true; - RenderedImage mask = (transparencyDisabled ? null : getMask(img, effDim)); + RenderedImage mask = (transparencyDisabled ? null : getMask(img, effDim)); if (mask != null) { pushCursorPos(); selectCurrentPattern(0, 1); //Solid white @@ -753,11 +753,11 @@ public class PCLGenerator { paintMonochromeBitmap(mask, effResolution); popCursorPos(); } - + BufferedImage src = null; if (img instanceof BufferedImage && !scaled) { if (!isGrayscaleImage(img) || img.getColorModel().hasAlpha()) { - src = new BufferedImage(effDim.width, effDim.height, + src = new BufferedImage(effDim.width, effDim.height, BufferedImage.TYPE_BYTE_GRAY); ColorConvertOp op = new ColorConvertOp( ColorSpace.getInstance(ColorSpace.CS_GRAY), null); @@ -767,7 +767,7 @@ public class PCLGenerator { } } if (src == null) { - src = new BufferedImage(effDim.width, effDim.height, + src = new BufferedImage(effDim.width, effDim.height, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g2d = src.createGraphics(); try { @@ -784,7 +784,7 @@ public class PCLGenerator { converter.setHint("quality", "false"); BufferedImage buf = (BufferedImage)converter.convertToMonochrome(src); - + RenderedImage red = buf; selectCurrentPattern(0, 0); //Solid black setTransparencyMode(sourceTransparency || mask != null, true); @@ -793,7 +793,7 @@ public class PCLGenerator { //TODO untested! RenderedImage effImg = img; if (scaled) { - BufferedImage buf = new BufferedImage(effDim.width, effDim.height, + BufferedImage buf = new BufferedImage(effDim.width, effDim.height, BufferedImage.TYPE_BYTE_BINARY); Graphics2D g2d = buf.createGraphics(); try { @@ -831,7 +831,7 @@ public class PCLGenerator { if (!monochrome) { throw new IllegalArgumentException("img must be a monochrome image"); } - + int x = 0; int y = 0; int imgw = img.getWidth(); @@ -856,7 +856,7 @@ public class PCLGenerator { if ((sample == 0)) { ib |= (1 << (7 - (x % 8))); } - + //RLE encoding if ((x % 8) == 7 || ((x + 1) == imgw)) { if (rlewidth < bytewidth) { diff --git a/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java b/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java index ef777e20a..3eef38b6b 100644 --- a/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java +++ b/src/java/org/apache/fop/render/pcl/PCLGraphics2D.java @@ -54,10 +54,10 @@ public class PCLGraphics2D extends AbstractGraphics2D { /** The PCL generator */ protected PCLGenerator gen; - + private boolean failOnUnsupportedFeature = true; private boolean clippingDisabled = false; - + /** * Create a new PCLGraphics2D. * @param gen the PCL Generator to paint with @@ -103,7 +103,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { public void setClippingDisabled(boolean value) { this.clippingDisabled = value; } - + /** * Central handler for IOExceptions for this class. * @param ioe IOException to handle @@ -124,7 +124,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { throw new UnsupportedOperationException(msg); } } - + /** {@inheritDoc} */ public GraphicsConfiguration getDeviceConfiguration() { return GraphicsEnvironment.getLocalGraphicsEnvironment(). @@ -142,7 +142,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { float[] da = bs.getDashArray(); if (da != null) { - + gen.writeText("UL1,"); int len = Math.min(20, da.length); float patternLen = 0.0f; @@ -161,7 +161,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { } if (len == 1) { gen.writeText("," + gen.formatDouble2(da[0] * 100 / patternLen )); - + } gen.writeText(";"); /* TODO Dash phase NYI @@ -209,7 +209,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { float ml = bs.getMiterLimit(); gen.writeText(",3" + gen.formatDouble4(ml)); - + float lw = bs.getLineWidth(); Point2D ptSrc = new Point2D.Double(lw, 0); //Pen widths are set as absolute metric values (WU0;) @@ -217,7 +217,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { double transDist = UnitConv.pt2mm(ptDest.distance(0, 0)); //System.out.println("--" + ptDest.distance(0, 0) + " " + transDist); gen.writeText(";PW" + gen.formatDouble4(transDist) + ";"); - + } else { handleUnsupportedFeature("Unsupported Stroke: " + stroke.getClass().getName()); } @@ -246,7 +246,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { //gen.writeText("IW;"); } else { handleUnsupportedFeature("Clipping is not supported. Shape: " + imclip); - /* This is an attempt to clip using the "InputWindow" (IW) but this only allows to + /* This is an attempt to clip using the "InputWindow" (IW) but this only allows to * clip a rectangular area. Force falling back to bitmap mode for now. Rectangle2D bounds = imclip.getBounds2D(); Point2D p1 = new Point2D.Double(bounds.getX(), bounds.getY()); @@ -266,16 +266,16 @@ public class PCLGraphics2D extends AbstractGraphics2D { public void draw(Shape s) { try { AffineTransform trans = getTransform(); - + Shape imclip = getClip(); writeClip(imclip); - + if (!Color.black.equals(getColor())) { //TODO PCL 5 doesn't support colored pens, PCL5c has a pen color (PC) command handleUnsupportedFeature("Only black is supported as stroke color: " + getColor()); } applyStroke(getStroke()); - + PathIterator iter = s.getPathIterator(trans); processPathIteratorStroke(iter); writeClip(null); @@ -290,7 +290,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { AffineTransform trans = getTransform(); Shape imclip = getClip(); writeClip(imclip); - + applyPaint(getPaint()); PathIterator iter = s.getPathIterator(trans); @@ -371,7 +371,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { sb.append("\n"); gen.writeText(sb.toString()); } - + /** * Processes a path iterator generating the nexessary painting operations. * @param iter PathIterator to process @@ -440,7 +440,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { sb.append("\n"); gen.writeText(sb.toString()); } - + private void fillPolygon(int windingRule, StringBuffer sb) { int fillMethod = (windingRule == PathIterator.WIND_EVEN_ODD ? 0 : 1); sb.append("FP").append(fillMethod).append(";"); @@ -461,16 +461,16 @@ public class PCLGraphics2D extends AbstractGraphics2D { sb.append(",").append(gen.formatDouble4(y3)).append(";"); } - private void quadraticBezierAbsolute(double originX, double originY, + private void quadraticBezierAbsolute(double originX, double originY, double x1, double y1, double x2, double y2, StringBuffer sb) { //Quadratic Bezier curve can be mapped to a normal bezier curve //See http://pfaedit.sourceforge.net/bezier.html double nx1 = originX + (2.0 / 3.0) * (x1 - originX); double ny1 = originY + (2.0 / 3.0) * (y1 - originY); - + double nx2 = nx1 + (1.0 / 3.0) * (x2 - originX); double ny2 = ny1 + (1.0 / 3.0) * (y2 - originY); - + bezierAbsolute(nx1, ny1, nx2, ny2, x2, y2, sb); } @@ -554,7 +554,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { at.transform(p1, p1); pclContext.getTransform().transform(p1, p1); gen.setCursorPos(p1.getX(), p1.getY()); - gen.paintBitmap(buf, 72); + gen.paintBitmap(buf, 72); gen.enterHPGL2Mode(false); } catch (IOException ioe) { handleIOException(ioe); @@ -596,7 +596,7 @@ public class PCLGraphics2D extends AbstractGraphics2D { return new BufferedImage(size.width, size.height, BufferedImage.TYPE_BYTE_GRAY); } - + /** {@inheritDoc} */ public java.awt.FontMetrics getFontMetrics(java.awt.Font f) { return fmg.getFontMetrics(f); diff --git a/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java b/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java index 06a4d37a0..3878a84fb 100644 --- a/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java +++ b/src/java/org/apache/fop/render/pcl/PCLGraphics2DAdapter.java @@ -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.fop.render.pcl; import java.awt.Dimension; @@ -49,15 +49,15 @@ public class PCLGraphics2DAdapter extends AbstractGraphics2DAdapter { */ public PCLGraphics2DAdapter() { } - + /** {@inheritDoc} */ - public void paintImage(Graphics2DImagePainter painter, + public void paintImage(Graphics2DImagePainter painter, RendererContext context, int x, int y, int width, int height) throws IOException { PCLRendererContext pclContext = PCLRendererContext.wrapRendererContext(context); PCLRenderer pcl = (PCLRenderer)context.getRenderer(); PCLGenerator gen = pcl.gen; - + // get the 'width' and 'height' attributes of the image/document Dimension dim = painter.getImageSize(); float imw = (float)dim.getWidth(); @@ -80,11 +80,11 @@ public class PCLGraphics2DAdapter extends AbstractGraphics2DAdapter { graphics.setClippingDisabled(pclContext.isClippingDisabled()); Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); painter.paint(graphics, area); - + //If we arrive here, the graphic is natively paintable, so write the graphic pcl.saveGraphicsState(); pcl.setCursorPos(x, y); - gen.writeCommand("*c" + gen.formatDouble4(width / 100f) + "x" + gen.writeCommand("*c" + gen.formatDouble4(width / 100f) + "x" + gen.formatDouble4(height / 100f) + "Y"); gen.writeCommand("*c0T"); gen.enterHPGL2Mode(false); @@ -92,7 +92,7 @@ public class PCLGraphics2DAdapter extends AbstractGraphics2DAdapter { gen.writeText("SP1;"); //One Plotter unit is 0.025mm! double scale = imw / UnitConv.mm2pt(imw * 0.025); - gen.writeText("SC0," + gen.formatDouble4(scale) + gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;"); gen.writeText("IR0,100,0,100;"); gen.writeText("PU;PA0,0;\n"); @@ -104,11 +104,11 @@ public class PCLGraphics2DAdapter extends AbstractGraphics2DAdapter { painted = true; } catch (UnsupportedOperationException uoe) { log.debug( - "Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + "Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + uoe.getMessage()); } } - + if (!painted) { //Fallback solution: Paint to a BufferedImage int resolution = (int)Math.round(context.getUserAgent().getTargetResolution()); diff --git a/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java b/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java index ebff61f0f..e8c8814ab 100644 --- a/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java +++ b/src/java/org/apache/fop/render/pcl/PCLPageDefinition.java @@ -33,17 +33,17 @@ 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; - + static { createPageDefinitions(); } - + /** * Main constructor * @param name the name of the page definition @@ -52,7 +52,7 @@ public class PCLPageDefinition { * @param logicalPageRect the rectangle defining the logical page * @param landscape true if it is a landscape format */ - public PCLPageDefinition(String name, int selector, Dimension physicalPageSize, + public PCLPageDefinition(String name, int selector, Dimension physicalPageSize, Rectangle logicalPageRect, boolean landscape) { this.name = name; this.selector = selector; @@ -60,17 +60,17 @@ public class PCLPageDefinition { this.logicalPageRect = logicalPageRect; this.landscape = landscape; } - + /** @return the name of the page definition */ public String getName() { return this.name; } - + /** @return the selector used by the <ESC>&l#A command (page size) */ public int getSelector() { return this.selector; } - + /** @return true if it is a landscape format */ public boolean isLandscapeFormat() { return this.landscape; @@ -80,17 +80,17 @@ public class PCLPageDefinition { public Dimension getPhysicalPageSize() { return this.physicalPageSize; } - + /** @return the rectangle defining the logical page */ public Rectangle getLogicalPageRect() { return this.logicalPageRect; } - + private boolean matches(long width, long height, int errorMargin) { - return (Math.abs(this.physicalPageSize.width - width) < errorMargin) + return (Math.abs(this.physicalPageSize.width - width) < errorMargin) && (Math.abs(this.physicalPageSize.height - height) < errorMargin); } - + /** {@inheritDoc} */ public String toString() { return getName(); @@ -113,12 +113,12 @@ public class PCLPageDefinition { } return null; } - + /** @return the default page definition (letter) */ public static PCLPageDefinition getDefaultPageDefinition() { return defaultPageDefinition; } - + /** * Converts an offset values for logical pages to millipoints. The values are given as pixels * in a 300dpi environment. @@ -128,34 +128,34 @@ public class PCLPageDefinition { private static int convert300dpiDotsToMpt(int offset) { return (int)Math.round(((double)offset) * 72000 / 300); } - + private static Dimension createPhysicalPageSizeInch(float width, float height) { return new Dimension( - (int)Math.round(UnitConv.in2mpt(width)), + (int)Math.round(UnitConv.in2mpt(width)), (int)Math.round(UnitConv.in2mpt(height))); } - + private static Dimension createPhysicalPageSizeMm(float width, float height) { return new Dimension( - (int)Math.round(UnitConv.mm2mpt(width)), + (int)Math.round(UnitConv.mm2mpt(width)), (int)Math.round(UnitConv.mm2mpt(height))); } - + private static Rectangle createLogicalPageRect(int x, int y, int width, int height) { - return new Rectangle(convert300dpiDotsToMpt(x), convert300dpiDotsToMpt(y), + return new Rectangle(convert300dpiDotsToMpt(x), convert300dpiDotsToMpt(y), convert300dpiDotsToMpt(width), convert300dpiDotsToMpt(height)); } - + private static void createPageDefinitions() { pageDefinitions = new java.util.ArrayList(); pageDefinitions.add(new PCLPageDefinition("Letter", 2, createPhysicalPageSizeInch(8.5f, 11), createLogicalPageRect(75, 0, 2400, 3300), false)); - defaultPageDefinition = new PCLPageDefinition("Legal", 3, + defaultPageDefinition = new PCLPageDefinition("Legal", 3, createPhysicalPageSizeInch(8.5f, 14), createLogicalPageRect(75, 0, 2400, 4200), false); pageDefinitions.add(defaultPageDefinition); - pageDefinitions.add(new PCLPageDefinition("Executive", 1, + pageDefinitions.add(new PCLPageDefinition("Executive", 1, createPhysicalPageSizeInch(7.25f, 10.5f), createLogicalPageRect(75, 0, 2025, 3150), false)); pageDefinitions.add(new PCLPageDefinition("Ledger", 6, @@ -164,19 +164,19 @@ public class PCLPageDefinition { pageDefinitions.add(new PCLPageDefinition("A4", 26, createPhysicalPageSizeMm(210, 297), createLogicalPageRect(71, 0, 2338, 3507), false)); - pageDefinitions.add(new PCLPageDefinition("A3", 27, + pageDefinitions.add(new PCLPageDefinition("A3", 27, createPhysicalPageSizeMm(297, 420), createLogicalPageRect(71, 0, 3365, 4960), false)); //TODO Add envelope definitions - + pageDefinitions.add(new PCLPageDefinition("LetterL", 2, createPhysicalPageSizeInch(11, 8.5f), createLogicalPageRect(60, 0, 3180, 2550), true)); pageDefinitions.add(new PCLPageDefinition("LegalL", 3, createPhysicalPageSizeInch(14, 8.5f), createLogicalPageRect(60, 0, 4080, 2550), true)); - pageDefinitions.add(new PCLPageDefinition("ExecutiveL", 1, + pageDefinitions.add(new PCLPageDefinition("ExecutiveL", 1, createPhysicalPageSizeInch(10.5f, 7.25f), createLogicalPageRect(60, 0, 3030, 2175), true)); pageDefinitions.add(new PCLPageDefinition("LedgerL", 6, @@ -189,5 +189,5 @@ public class PCLPageDefinition { createPhysicalPageSizeMm(420, 297), createLogicalPageRect(59, 0, 4842, 3507), true)); } - + } diff --git a/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java b/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java index b9c772dcb..6d57825cd 100644 --- a/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java +++ b/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java @@ -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. @@ -27,10 +27,10 @@ import org.apache.fop.render.PrintRendererConfigurator; import org.apache.fop.render.Renderer; /** - * PCL Renderer configurator + * PCL Renderer configurator */ public class PCLRendererConfigurator extends PrintRendererConfigurator { - + /** * Default constructor * @param userAgent user agent @@ -41,7 +41,7 @@ public class PCLRendererConfigurator extends PrintRendererConfigurator { /** * Configure the PCL renderer. - * + * * @param renderer PCL renderer * @throws FOPException fop exception */ @@ -49,7 +49,7 @@ public class PCLRendererConfigurator extends PrintRendererConfigurator { Configuration cfg = super.getRendererConfig(renderer); if (cfg != null) { PCLRenderer pclRenderer = (PCLRenderer)renderer; - + String rendering = cfg.getChild("rendering").getValue(null); if ("quality".equalsIgnoreCase(rendering)) { pclRenderer.setQualityBeforeSpeed(true); @@ -57,10 +57,10 @@ public class PCLRendererConfigurator extends PrintRendererConfigurator { pclRenderer.setQualityBeforeSpeed(false); } else if (rendering != null) { throw new FOPException( - "Valid values for 'rendering' are 'quality' and 'speed'. Value found: " + "Valid values for 'rendering' are 'quality' and 'speed'. Value found: " + rendering); } - + String textRendering = cfg.getChild("text-rendering").getValue(null); if ("bitmap".equalsIgnoreCase(textRendering)) { pclRenderer.setAllTextAsBitmaps(true); @@ -68,10 +68,10 @@ public class PCLRendererConfigurator extends PrintRendererConfigurator { pclRenderer.setAllTextAsBitmaps(false); } else if (textRendering != null) { throw new FOPException( - "Valid values for 'text-rendering' are 'auto' and 'bitmap'. Value found: " + "Valid values for 'text-rendering' are 'auto' and 'bitmap'. Value found: " + textRendering); } - + pclRenderer.setPJLDisabled(cfg.getChild("disable-pjl").getValueAsBoolean(false)); } super.configure(renderer); diff --git a/src/java/org/apache/fop/render/pcl/PCLRendererContext.java b/src/java/org/apache/fop/render/pcl/PCLRendererContext.java index 422b9d51d..aa6271fe5 100644 --- a/src/java/org/apache/fop/render/pcl/PCLRendererContext.java +++ b/src/java/org/apache/fop/render/pcl/PCLRendererContext.java @@ -25,7 +25,7 @@ import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.render.RendererContext; /** - * Wrapper on the RendererContext to access the information structure for drawing + * Wrapper on the RendererContext to access the information structure for drawing * the XML document. */ public class PCLRendererContext extends RendererContext.RendererContextWrapper { @@ -48,18 +48,18 @@ public class PCLRendererContext extends RendererContext.RendererContextWrapper { public PCLRendererContext(RendererContext context) { super(context); } - + /** @return true if the SVG image should be rendered as a bitmap */ public boolean paintAsBitmap() { QName qName = new QName(ExtensionElementMapping.URI, null, "conversion-mode"); - return getForeignAttributes() != null + return getForeignAttributes() != null && "bitmap".equalsIgnoreCase((String)getForeignAttributes().get(qName)); } - + /** @return true if clipping is disabled inside the PCLGraphics2D. */ public boolean isClippingDisabled() { QName qName = new QName(ExtensionElementMapping.URI, null, "disable-clipping"); - return getForeignAttributes() != null + return getForeignAttributes() != null && "true".equalsIgnoreCase((String)getForeignAttributes().get(qName)); } @@ -69,10 +69,10 @@ public class PCLRendererContext extends RendererContext.RendererContextWrapper { */ public boolean isSourceTransparency() { QName qName = new QName(ExtensionElementMapping.URI, null, "source-transparency"); - return getForeignAttributes() != null + return getForeignAttributes() != null && "true".equalsIgnoreCase((String)getForeignAttributes().get(qName)); } - + /** * Indicates whether an RGB canvas should be used rather than one with grayscales. * This can be used to work around limitations of Apache Batik if you get error while @@ -82,8 +82,8 @@ public class PCLRendererContext extends RendererContext.RendererContextWrapper { public boolean isColorCanvas() { QName qName = new QName(ExtensionElementMapping.URI, null, "color-canvas"); Boolean prop = (Boolean)context.getProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS); - return Boolean.TRUE.equals(prop) - || (getForeignAttributes() != null + return Boolean.TRUE.equals(prop) + || (getForeignAttributes() != null && "true".equalsIgnoreCase((String)getForeignAttributes().get(qName))); } diff --git a/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java b/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java index f18446506..a7651a6ac 100644 --- a/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java +++ b/src/java/org/apache/fop/render/pcl/PCLRendererMaker.java @@ -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. @@ -34,7 +34,7 @@ public class PCLRendererMaker extends AbstractRendererMaker { MimeConstants.MIME_PCL, MimeConstants.MIME_PCL_ALT }; - + /**{@inheritDoc} */ public Renderer makeRenderer(FOUserAgent userAgent) { return new PCLRenderer(); diff --git a/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java b/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java index a016c692f..fb2389758 100644 --- a/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java +++ b/src/java/org/apache/fop/render/pcl/PCLSVGHandler.java @@ -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. @@ -36,13 +36,13 @@ public class PCLSVGHandler extends AbstractGenericSVGHandler { public boolean supportsRenderer(Renderer renderer) { return (renderer instanceof PCLRenderer); } - + /** {@inheritDoc} */ protected void updateRendererContext(RendererContext context) { //Work around a problem in Batik: Gradients cannot be done in ColorSpace.CS_GRAY context.setProperty(PCLRendererContextConstants.PCL_COLOR_CANVAS, Boolean.TRUE); } - + } |