From: <doc...@us...> - 2007-07-26 18:29:28
|
Revision: 128 http://openpcl.svn.sourceforge.net/openpcl/?rev=128&view=rev Author: documentsystems Date: 2007-07-26 11:29:28 -0700 (Thu, 26 Jul 2007) Log Message: ----------- Howard Hoagland. In PclRenderImage added a ByteArrayOutputStream that is constructed once and resused for each print page to build the resulting PCL bytes to parse and draw to the bitmap for Windows Print, in the method getImageForPage() appending the added parameter byte[] pPrintTimePclBytes then the base page PCL bytes to implement the "Print Form Names" for Windows Print (PCL Direct print was already implemented previously). Modified Paths: -------------- openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java Modified: openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java =================================================================== --- openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java 2007-07-26 18:24:22 UTC (rev 127) +++ openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java 2007-07-26 18:29:28 UTC (rev 128) @@ -4,6 +4,7 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -75,6 +76,7 @@ protected double mCurrentZoomFactor = sDefaultZoomFactor; protected PriPclPage mPriPclPage = null; protected ArrayList<PriPclPage> mPagesArrayList = null; + protected ByteArrayOutputStream mByteArrayOutputStream = null; protected String mFullFilePathAndName = null; protected String mFileNameNoPath = null; @@ -112,7 +114,12 @@ mPriRasterDrawing = new PriRasterDrawing(this, mBufferedImageToDrawOn); mPriRectDrawing = new PriRectDrawing(this, mGraphics2D); mPriPclPage = new PriPclPage(); - mPagesArrayList = new ArrayList<PriPclPage>(4); + mPagesArrayList = new ArrayList<PriPclPage>(10); // Grows automatically if max is reached + + // Make a new ByteArrayOutputStream to hold the Pcl bytes gotten from the BLK page or from the PCL file page, + // and make it 20k bytes. Note that ByteArrayOutputStream automatically grows the storage space if it + // runs out of room by allocating a new bigger byte array then doing a memcopy to the new one. + mByteArrayOutputStream = new ByteArrayOutputStream(20 * 1024); } } @@ -910,12 +917,14 @@ * In DocMaster, this is getImage(). * * @param pPageNumber. The Pcl page number to render to the image. + * @param pPrintTimePclBytes. Draw these additional PCL bytes on the print image. * @param pIsForPrinting. If true non printing items like signature blocks won't be rendered. * @param pPaperSize. If a paper size is not specified in the PCL, this paper size will be used. "LTR" or "LGL". * @param pZoomFactor. This is mandatory (see note for why). * @return BufferedImage. If null is returned, then call getLastErrorString() */ - public BufferedImage getImageForPage(int pPageNumber, boolean pIsForPrinting, String pPaperSize, double pZoomFactor) { + public BufferedImage getImageForPage(int pPageNumber, byte[] pPrintTimePclBytes, + boolean pIsForPrinting, String pPaperSize, double pZoomFactor) { // PriDebug.infoln("PclRenderImage> getImageForPage(page=" + pPageNumber + ", boolean printing=" + // pIsForPrinting + "String paperSize=" + pPaperSize + ", double zoom=" + pZoomFactor + ")"); @@ -929,6 +938,17 @@ return null; } + // Set the char pointer in the ByteArrayOutputStream to 0 bytes, to reuse it without doing a "new" to make a new one + mByteArrayOutputStream.reset(); + + // If rendering for printing, and there are additional print time PCL bytes to draw, then write those bytes here + if (pIsForPrinting && pPrintTimePclBytes != null) { + try { + mByteArrayOutputStream.write(pPrintTimePclBytes); + } catch (IOException e) { + } + } + // Pull the Pcl bytes for this page out of the PriPclPage byte[] tPclBytes = tPriPclPage.getPclBytes(); if (tPclBytes == null || tPclBytes.length < 1) { @@ -936,12 +956,24 @@ return null; } + // Save passed in parameter to class instance variable to be accessed during the printing mIsDrawingForPrinting = pIsForPrinting; + + // Write the Pcl bytes from the page + try { + mByteArrayOutputStream.write(tPclBytes); + } catch (IOException e) { + } // PriDebug.infoln("PclRenderImage> getImageForPage() calling parseAndRender(#bytes=" + tPclBytes.length + // ", printing=" + pIsForPrinting + ", zoom=" + pZoomFactor); - - return parseAndRender(tPclBytes, pIsForPrinting, pZoomFactor); + + // Get the byte[] out of the ByteArrayOutputStream + byte[] tBytesToRender = mByteArrayOutputStream.toByteArray(); + // Draw the PCL bytes on the BufferedImage + BufferedImage tBufferedImage = parseAndRender(tBytesToRender, pIsForPrinting, pZoomFactor); + // Return the BufferedImage + return tBufferedImage; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |