diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-11-08 12:56:25 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-11-08 12:56:25 +0000 |
commit | 01945b97d64b065915c7d3ab75d5c51ffd5a8778 (patch) | |
tree | 638f685ee9da4d0337f1bec5fa2c77798d88e0f8 | |
parent | 702b0ce1e73c84b5c39683aff2cec76ed2c53934 (diff) | |
download | xmlgraphics-fop-01945b97d64b065915c7d3ab75d5c51ffd5a8778.tar.gz xmlgraphics-fop-01945b97d64b065915c7d3ab75d5c51ffd5a8778.zip |
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
-rw-r--r-- | src/java/org/apache/fop/image/EmfImage.java | 25 | ||||
-rw-r--r-- | src/java/org/apache/fop/image/analyser/EMFReader.java | 16 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/pdf/PDFRenderer.java | 3 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java | 4 | ||||
-rw-r--r-- | test/layoutengine/testcases/external-graphic_emf.xml | 48 | ||||
-rw-r--r-- | test/resources/images/img.emf | bin | 0 -> 604 bytes |
6 files changed, 70 insertions, 26 deletions
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 diff --git a/test/layoutengine/testcases/external-graphic_emf.xml b/test/layoutengine/testcases/external-graphic_emf.xml new file mode 100644 index 000000000..6cf940530 --- /dev/null +++ b/test/layoutengine/testcases/external-graphic_emf.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + 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$ --> +<testcase> + <info> + <p> + This test checks external-graphics. + </p> + </info> + <fo> + <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in"> + <fo:region-body/> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="normal"> + <fo:flow flow-name="xsl-region-body"> + <fo:block>EMF external-graphic</fo:block> + <fo:block> + <fo:external-graphic src="../../resources/images/img.emf"/>EOG + </fo:block> + <fo:block>EOF</fo:block> + </fo:flow> + </fo:page-sequence> + </fo:root> + </fo> + <checks> + <eval expected="56692" xpath="//flow/block[2]/lineArea/viewport/@ipd"/> + <eval expected="56692" xpath="//flow/block[2]/lineArea/viewport/@ipda"/> + <eval expected="56692" xpath="//flow/block[2]/lineArea/viewport/@bpd"/> + <eval expected="56692" xpath="//flow/block[2]/lineArea/viewport/@bpda"/> + </checks> +</testcase> diff --git a/test/resources/images/img.emf b/test/resources/images/img.emf Binary files differnew file mode 100644 index 000000000..f8534daa5 --- /dev/null +++ b/test/resources/images/img.emf |