xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r331805 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/image/ src/java/org/apache/fop/image/analyser/ src/java/org/apache/fop/render/pdf/ src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ test/layoutengine/testcases/ test/resources/im...
Date Tue, 08 Nov 2005 12:56:49 GMT
Author: jeremias
Date: Tue Nov  8 04:56:25 2005
New Revision: 331805

URL: http://svn.apache.org/viewcvs?rev=331805&view=rev
Log:
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.

Added:
    xmlgraphics/fop/trunk/test/layoutengine/testcases/external-graphic_emf.xml   (with props)
    xmlgraphics/fop/trunk/test/resources/images/img.emf   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/image/EmfImage.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/image/analyser/EMFReader.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/EmfImage.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/EmfImage.java?rev=331805&r1=331804&r2=331805&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/EmfImage.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/EmfImage.java Tue Nov  8 04:56:25
2005
@@ -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 @@
     }
 
     /**
-     * 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;
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/analyser/EMFReader.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/analyser/EMFReader.java?rev=331805&r1=331804&r2=331805&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/analyser/EMFReader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/analyser/EMFReader.java Tue Nov  8
04:56:25 2005
@@ -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 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 @@
         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 @@
         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 @@
         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;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=331805&r1=331804&r2=331805&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java Tue Nov  8 04:56:25
2005
@@ -1394,6 +1394,9 @@
             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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java?rev=331805&r1=331804&r2=331805&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java
Tue Nov  8 04:56:25 2005
@@ -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 @@
      private byte[] imagedata = null;
 
      /** The image format */
-     FormatBase imageformat;
+     private FormatBase imageformat;
 
     //////////////////////////////////////////////////
     // @@ Construction

Added: xmlgraphics/fop/trunk/test/layoutengine/testcases/external-graphic_emf.xml
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/layoutengine/testcases/external-graphic_emf.xml?rev=331805&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/layoutengine/testcases/external-graphic_emf.xml (added)
+++ xmlgraphics/fop/trunk/test/layoutengine/testcases/external-graphic_emf.xml Tue Nov  8
04:56:25 2005
@@ -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>

Propchange: xmlgraphics/fop/trunk/test/layoutengine/testcases/external-graphic_emf.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/layoutengine/testcases/external-graphic_emf.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/trunk/test/resources/images/img.emf
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/resources/images/img.emf?rev=331805&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop/trunk/test/resources/images/img.emf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message