You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/12/06 21:35:23 UTC
svn commit: r354537 - in /xmlgraphics/fop/trunk:
src/java/org/apache/fop/render/bitmap/PNGRenderer.java
src/java/org/apache/fop/render/bitmap/PNGRenderer_onthefly.java status.xml
Author: jeremias
Date: Tue Dec 6 12:35:15 2005
New Revision: 354537
URL: http://svn.apache.org/viewcvs?rev=354537&view=rev
Log:
Bugfix: OutputStreams created by the PNG Renderer were not properly closed.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer_onthefly.java
xmlgraphics/fop/trunk/status.xml
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java?rev=354537&r1=354536&r2=354537&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java Tue Dec 6 12:35:15 2005
@@ -1,3 +1,21 @@
+/*
+ * 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$ */
+
package org.apache.fop.render.bitmap;
import java.awt.image.RenderedImage;
@@ -10,6 +28,7 @@
import org.apache.batik.ext.awt.image.codec.PNGEncodeParam;
import org.apache.batik.ext.awt.image.codec.PNGImageEncoder;
+import org.apache.commons.io.IOUtils;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.PageViewport;
@@ -42,9 +61,6 @@
return MIME_TYPE;
}
- /** default constructor */
- public PNGRenderer() {}
-
/** @see org.apache.fop.render.Renderer#startRenderer(java.io.OutputStream) */
public void startRenderer(OutputStream outputStream) throws IOException {
log.info("rendering areas to PNG");
@@ -79,6 +95,7 @@
}
+ /** @see org.apache.fop.render.Renderer#stopRenderer() */
public void stopRenderer() throws IOException {
super.stopRenderer();
@@ -91,24 +108,30 @@
+ " Stopping early after the first page.");
break;
}
- // Do the rendering: get the image for this page
- RenderedImage image = (RenderedImage) getPageImage((PageViewport) pageViewportList
- .get(i));
-
- // Encode this image
- log.debug("Encoding page " + (i + 1));
- renderParams = PNGEncodeParam.getDefaultEncodeParam(image);
-
- // Set resolution
- float pixSzMM = userAgent.getPixelUnitToMillimeter();
- // num Pixs in 1 Meter
- int numPix = (int)((1000 / pixSzMM) + 0.5);
- renderParams.setPhysicalDimension(numPix, numPix, 1); // 1 means 'pix/meter'
-
- // Encode PNG image
- PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);
- encoder.encode(image);
- os.flush();
+ try {
+ // Do the rendering: get the image for this page
+ RenderedImage image = (RenderedImage) getPageImage((PageViewport) pageViewportList
+ .get(i));
+
+ // Encode this image
+ log.debug("Encoding page " + (i + 1));
+ renderParams = PNGEncodeParam.getDefaultEncodeParam(image);
+
+ // Set resolution
+ float pixSzMM = userAgent.getPixelUnitToMillimeter();
+ // num Pixs in 1 Meter
+ int numPix = (int)((1000 / pixSzMM) + 0.5);
+ renderParams.setPhysicalDimension(numPix, numPix, 1); // 1 means 'pix/meter'
+
+ // Encode PNG image
+ PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);
+ encoder.encode(image);
+ } finally {
+ //Only close self-created OutputStreams
+ if (os != firstOutputStream) {
+ IOUtils.closeQuietly(os);
+ }
+ }
}
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer_onthefly.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer_onthefly.java?rev=354537&r1=354536&r2=354537&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer_onthefly.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer_onthefly.java Tue Dec 6 12:35:15 2005
@@ -1,3 +1,21 @@
+/*
+ * 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$ */
+
package org.apache.fop.render.bitmap;
import java.awt.image.RenderedImage;
@@ -10,6 +28,7 @@
import org.apache.batik.ext.awt.image.codec.PNGEncodeParam;
import org.apache.batik.ext.awt.image.codec.PNGImageEncoder;
+import org.apache.commons.io.IOUtils;
import org.apache.fop.apps.FOPException;
import org.apache.fop.area.PageViewport;
import org.apache.fop.render.java2d.Java2DRenderer;
@@ -36,14 +55,12 @@
/** The OutputStream for the first Image */
private OutputStream firstOutputStream;
- /** default constructor */
- public PNGRenderer_onthefly() {}
-
/** @see org.apache.fop.render.AbstractRenderer */
public String getMimeType() {
return MIME_TYPE;
}
+ /** @see org.apache.fop.render.Renderer#supportsOutOfOrder() */
public boolean supportsOutOfOrder() {
return true;
}
@@ -76,6 +93,7 @@
fileSyntax = s.substring(0, i);
}
+ /** @see org.apache.fop.render.Renderer#renderPage(org.apache.fop.area.PageViewport) */
public void renderPage(PageViewport pageViewport) throws IOException,
FOPException {
@@ -86,9 +104,17 @@
log.debug("Encoding page" + (getCurrentPageNumber() + 1));
renderParams = PNGEncodeParam.getDefaultEncodeParam(image);
OutputStream os = getCurrentOutputStream(getCurrentPageNumber());
- PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);
- encoder.encode(image);
- os.flush();
+ if (os != null) {
+ try {
+ PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);
+ encoder.encode(image);
+ } finally {
+ //Only close self-created OutputStreams
+ if (os != firstOutputStream) {
+ IOUtils.closeQuietly(os);
+ }
+ }
+ }
setCurrentPageNumber(getCurrentPageNumber() + 1);
}
Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/status.xml?rev=354537&r1=354536&r2=354537&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Tue Dec 6 12:35:15 2005
@@ -27,6 +27,9 @@
<changes>
<release version="FOP Trunk">
+ <action context="Code" dev="JM" type="fix">
+ Bugfix: Self-created OutputStreams in PNG Renderer were not properly closed.
+ </action>
<action context="Code" dev="JM" type="update">
The border-collapse property on fo:table is now forced to the value "separate" until the collapsing
border has been implemented.
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org