From 01945b97d64b065915c7d3ab75d5c51ffd5a8778 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Tue, 8 Nov 2005 12:56:25 +0000 Subject: EMF support review: Copyright years, rounding problems, code simplifications PDF Renderer should not fail with an exception if it receives an EMF image. It should ignore it. Test case for EMF image and an EMF image added. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@331805 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/image/EmfImage.java | 25 +++++++--------------- .../org/apache/fop/image/analyser/EMFReader.java | 16 ++++++++------ .../org/apache/fop/render/pdf/PDFRenderer.java | 3 +++ .../rtf/rtflib/rtfdoc/RtfExternalGraphic.java | 4 ++-- 4 files changed, 22 insertions(+), 26 deletions(-) (limited to 'src/java/org/apache/fop') diff --git a/src/java/org/apache/fop/image/EmfImage.java b/src/java/org/apache/fop/image/EmfImage.java index bbe3794c5..0954e97d7 100644 --- a/src/java/org/apache/fop/image/EmfImage.java +++ b/src/java/org/apache/fop/image/EmfImage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,22 @@ * limitations under the License. */ +/* $Id$ */ package org.apache.fop.image; -// Java -import java.io.ByteArrayOutputStream; - import org.apache.commons.io.IOUtils; /** * Enhanced metafile image. - * This supports loading a emf image. + * This supports loading a EMF image. * * @author Peter Herweg * @see AbstractFopImage * @see FopImage */ public class EmfImage extends AbstractFopImage { + /** * Create a bitmap image with the image data. * @@ -41,31 +40,23 @@ public class EmfImage extends AbstractFopImage { } /** - * Load the original jpeg data. - * This loads the original jpeg data and reads the color space, + * Load the original EMF data. + * This loads the original EMF data and reads the color space, * and icc profile if any. * * @return true if loaded false for any error */ protected boolean loadOriginalData() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - byte[] readBuf = new byte[4096]; - int bytesRead; - while ((bytesRead = inputStream.read(readBuf)) != -1) { - baos.write(readBuf, 0, bytesRead); - } + this.raw = IOUtils.toByteArray(inputStream); } catch (java.io.IOException ex) { - log.error("Error while loading image (Emf): " + ex.getMessage(), ex); + log.error("Error while loading image (EMF): " + ex.getMessage(), ex); return false; } finally { IOUtils.closeQuietly(inputStream); inputStream = null; } - this.raw = baos.toByteArray(); - return true; } } diff --git a/src/java/org/apache/fop/image/analyser/EMFReader.java b/src/java/org/apache/fop/image/analyser/EMFReader.java index a5c01845f..404c65945 100644 --- a/src/java/org/apache/fop/image/analyser/EMFReader.java +++ b/src/java/org/apache/fop/image/analyser/EMFReader.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ * limitations under the License. */ +/* $Id$ */ + package org.apache.fop.image.analyser; // Java @@ -53,8 +55,8 @@ public class EMFReader implements ImageReader { public FopImage.ImageInfo verifySignature(String uri, InputStream bis, FOUserAgent ua) throws IOException { byte[] header = getDefaultHeader(bis); - boolean supported = - ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20) + boolean supported + = ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20) && (header[SIGNATURE_OFFSET + 1] == (byte) 0x45) && (header[SIGNATURE_OFFSET + 2] == (byte) 0x4D) && (header[SIGNATURE_OFFSET + 3] == (byte) 0x46) ); @@ -114,8 +116,8 @@ public class EMFReader implements ImageReader { byte4 = header[VRES_PIXEL_OFFSET + 3] & 0xff; long vresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); - info.dpiHorizontal = hresPixel / (hresMM/25.4); - info.dpiVertical = vresPixel / (vresMM/25.4);; + info.dpiHorizontal = hresPixel / (hresMM / 25.4f); + info.dpiVertical = vresPixel / (vresMM / 25.4f); //width byte1 = header[WIDTH_OFFSET] & 0xff; @@ -124,7 +126,7 @@ public class EMFReader implements ImageReader { byte4 = header[WIDTH_OFFSET + 3] & 0xff; value = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); - value = (long) (value / 100f / 25.4 * info.dpiHorizontal); + value = Math.round(value / 100f / 25.4f * info.dpiHorizontal); info.width = (int) (value & 0xffffffff); //height @@ -133,7 +135,7 @@ public class EMFReader implements ImageReader { byte3 = header[HEIGHT_OFFSET + 2] & 0xff; byte4 = header[HEIGHT_OFFSET + 3] & 0xff; value = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); - value = (long) (value / 100f / 25.4 * info.dpiVertical); + value = Math.round(value / 100f / 25.4f * info.dpiVertical); info.height = (int) (value & 0xffffffff); return info; diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index d9591802e..f30b0e0d0 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -1394,6 +1394,9 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { placeImage((float) pos.getX() / 1000, (float) pos.getY() / 1000, w, h, xobj); } else { + if (!fopimage.load(FopImage.BITMAP)) { + return; + } FopPDFImage pdfimage = new FopPDFImage(fopimage, url); int xobj = pdfDoc.addImage(currentContext, pdfimage).getXNumber(); fact.releaseImage(url, userAgent); diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java index 5f0bb1e3d..a0d8ebbae 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -280,7 +280,7 @@ public class RtfExternalGraphic extends RtfElement { private byte[] imagedata = null; /** The image format */ - FormatBase imageformat; + private FormatBase imageformat; ////////////////////////////////////////////////// // @@ Construction -- cgit v1.2.3