/*\r
- * Copyright 1999-2005 The Apache Software Foundation.\r
+ * Copyright 2005 The Apache Software Foundation.\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* limitations under the License.\r
*/\r
\r
+/* $Id$ */\r
\r
package org.apache.fop.image;\r
\r
-// Java\r
-import java.io.ByteArrayOutputStream;\r
-\r
import org.apache.commons.io.IOUtils;\r
\r
/**\r
* Enhanced metafile image.\r
- * This supports loading a emf image.\r
+ * This supports loading a EMF image.\r
*\r
* @author Peter Herweg\r
* @see AbstractFopImage\r
* @see FopImage\r
*/\r
public class EmfImage extends AbstractFopImage {\r
+ \r
/**\r
* Create a bitmap image with the image data.\r
*\r
}\r
\r
/**\r
- * Load the original jpeg data.\r
- * This loads the original jpeg data and reads the color space,\r
+ * Load the original EMF data.\r
+ * This loads the original EMF data and reads the color space,\r
* and icc profile if any.\r
*\r
* @return true if loaded false for any error\r
*/\r
protected boolean loadOriginalData() {\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
-\r
try {\r
- byte[] readBuf = new byte[4096];\r
- int bytesRead;\r
- while ((bytesRead = inputStream.read(readBuf)) != -1) {\r
- baos.write(readBuf, 0, bytesRead);\r
- }\r
+ this.raw = IOUtils.toByteArray(inputStream);\r
} catch (java.io.IOException ex) {\r
- log.error("Error while loading image (Emf): " + ex.getMessage(), ex);\r
+ log.error("Error while loading image (EMF): " + ex.getMessage(), ex);\r
return false;\r
} finally {\r
IOUtils.closeQuietly(inputStream);\r
inputStream = null;\r
}\r
\r
- this.raw = baos.toByteArray();\r
- \r
return true;\r
}\r
}\r
/*\r
- * Copyright 1999-2005 The Apache Software Foundation.\r
+ * Copyright 2005 The Apache Software Foundation.\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* limitations under the License.\r
*/\r
\r
+/* $Id$ */\r
+\r
package org.apache.fop.image.analyser;\r
\r
// Java\r
public FopImage.ImageInfo verifySignature(String uri, InputStream bis,\r
FOUserAgent ua) throws IOException {\r
byte[] header = getDefaultHeader(bis);\r
- boolean supported = \r
- ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20)\r
+ boolean supported \r
+ = ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20)\r
&& (header[SIGNATURE_OFFSET + 1] == (byte) 0x45)\r
&& (header[SIGNATURE_OFFSET + 2] == (byte) 0x4D)\r
&& (header[SIGNATURE_OFFSET + 3] == (byte) 0x46) );\r
byte4 = header[VRES_PIXEL_OFFSET + 3] & 0xff;\r
long vresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);\r
\r
- info.dpiHorizontal = hresPixel / (hresMM/25.4);\r
- info.dpiVertical = vresPixel / (vresMM/25.4);;\r
+ info.dpiHorizontal = hresPixel / (hresMM / 25.4f);\r
+ info.dpiVertical = vresPixel / (vresMM / 25.4f);\r
\r
//width\r
byte1 = header[WIDTH_OFFSET] & 0xff;\r
byte4 = header[WIDTH_OFFSET + 3] & 0xff;\r
value = (long) ((byte4 << 24) | (byte3 << 16)\r
| (byte2 << 8) | byte1);\r
- value = (long) (value / 100f / 25.4 * info.dpiHorizontal);\r
+ value = Math.round(value / 100f / 25.4f * info.dpiHorizontal);\r
info.width = (int) (value & 0xffffffff);\r
\r
//height\r
byte3 = header[HEIGHT_OFFSET + 2] & 0xff;\r
byte4 = header[HEIGHT_OFFSET + 3] & 0xff;\r
value = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);\r
- value = (long) (value / 100f / 25.4 * info.dpiVertical);\r
+ value = Math.round(value / 100f / 25.4f * info.dpiVertical);\r
info.height = (int) (value & 0xffffffff);\r
\r
return info;\r
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);
/*
- * 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.
private byte[] imagedata = null;
/** The image format */
- FormatBase imageformat;
+ private FormatBase imageformat;
//////////////////////////////////////////////////
// @@ Construction
--- /dev/null
+<?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>