Return-Path: Delivered-To: apmail-xmlgraphics-fop-commits-archive@www.apache.org Received: (qmail 30181 invoked from network); 9 Jun 2005 12:57:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Jun 2005 12:57:05 -0000 Received: (qmail 56378 invoked by uid 500); 9 Jun 2005 12:57:04 -0000 Delivered-To: apmail-xmlgraphics-fop-commits-archive@xmlgraphics.apache.org Received: (qmail 56361 invoked by uid 500); 9 Jun 2005 12:57:04 -0000 Mailing-List: contact fop-commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: fop-dev@xmlgraphics.apache.org Delivered-To: mailing list fop-commits@xmlgraphics.apache.org Received: (qmail 56347 invoked by uid 500); 9 Jun 2005 12:57:04 -0000 Delivered-To: apmail-xml-fop-cvs@apache.org Received: (qmail 56344 invoked by uid 99); 9 Jun 2005 12:57:04 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 09 Jun 2005 05:57:03 -0700 Received: (qmail 27925 invoked by uid 1482); 9 Jun 2005 12:50:14 -0000 Date: 9 Jun 2005 12:50:14 -0000 Message-ID: <20050609125014.27924.qmail@minotaur.apache.org> From: jeremias@apache.org To: xml-fop-cvs@apache.org Subject: cvs commit: xml-fop/src/java/org/apache/fop/render/bitmap PNGRenderer.java X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N jeremias 2005/06/09 05:50:14 Modified: src/java/org/apache/fop/render/bitmap PNGRenderer.java Log: Avoid NPEs when no filename is set on the UserAgent. Only the first page is rendered in this case. The resolution is written to the PNG file. Revision Changes Path 1.2 +42 -19 xml-fop/src/java/org/apache/fop/render/bitmap/PNGRenderer.java Index: PNGRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/bitmap/PNGRenderer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PNGRenderer.java 9 Jun 2005 08:49:27 -0000 1.1 +++ PNGRenderer.java 9 Jun 2005 12:50:14 -0000 1.2 @@ -25,7 +25,7 @@ public static final String MIME_TYPE = "image/png"; /** The file syntax prefix, eg. "page" will output "page1.png" etc */ - private String fileSyntax; + private String filePrefix; /** The output directory where images are to be written */ private File outputDir; @@ -60,16 +60,22 @@ // the file provided on the command line File f = getUserAgent().getOutputFile(); - - outputDir = f.getParentFile(); - - // extracting file name syntax - String s = f.getName(); - int i = s.lastIndexOf("."); - if (s.charAt(i - 1) == '1') { - i--; // getting rid of the "1" + if (f == null) { + //No filename information available. Only the first page will be rendered. + outputDir = null; + filePrefix = null; + } else { + outputDir = f.getParentFile(); + + // extracting file name syntax + String s = f.getName(); + int i = s.lastIndexOf("."); + if (s.charAt(i - 1) == '1') { + i--; // getting rid of the "1" + } + filePrefix = s.substring(0, i); } - fileSyntax = s.substring(0, i); + } public void stopRenderer() throws IOException { @@ -78,14 +84,27 @@ for (int i = 0; i < pageViewportList.size(); i++) { + OutputStream os = getCurrentOutputStream(i); + if (os == null) { + getLogger().warn("No filename information available." + + " 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 - getLogger().debug("Encoding Page " + (i + 1)); + getLogger().debug("Encoding page " + (i + 1)); renderParams = PNGEncodeParam.getDefaultEncodeParam(image); - OutputStream os = getCurrentOutputStream(i); + + // 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(); @@ -103,14 +122,18 @@ return firstOutputStream; } - File f = new File(outputDir + File.separator + fileSyntax - + (pageNumber + 1) + ".png"); - try { - OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); - return os; - } catch (FileNotFoundException e) { - new FOPException("Can't build the OutputStream\n" + e); + if (filePrefix == null) { return null; + } else { + File f = new File(outputDir + File.separator + filePrefix + + (pageNumber + 1) + ".png"); + try { + OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); + return os; + } catch (FileNotFoundException e) { + new FOPException("Can't build the OutputStream\n" + e); + return null; + } } } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org