From: <doc...@us...> - 2007-06-14 22:46:26
|
Revision: 87 http://openpcl.svn.sourceforge.net/openpcl/?rev=87&view=rev Author: documentsystems Date: 2007-06-14 15:46:28 -0700 (Thu, 14 Jun 2007) Log Message: ----------- Howard Hoagland. Added class PriModifyPclBytes and changed class PosPrintPages for when printing PCL Direct, parse the PCL and remove form feeds (to not get blank pages), remove printer reset commands (ESC E), remove page size, remove paper source tray or manual feed, remove number of copies, remove duplex Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java Added Paths: ----------- openpcl/src/com/openpcl/pclrenderimage/util/PriModifyPclBytes.java Added: openpcl/src/com/openpcl/pclrenderimage/util/PriModifyPclBytes.java =================================================================== --- openpcl/src/com/openpcl/pclrenderimage/util/PriModifyPclBytes.java (rev 0) +++ openpcl/src/com/openpcl/pclrenderimage/util/PriModifyPclBytes.java 2007-06-14 22:46:28 UTC (rev 87) @@ -0,0 +1,113 @@ +package com.openpcl.pclrenderimage.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import com.openpcl.pclrenderimage.tools.PclCommandEvent; + +/** + * Modify the PCL bytes. + * 1. Remove form feed chars (FF = ^L = 12) but not FF chars in raster data. + * 2. Remove printer resets (ESC E) + * 3. Remove paper size commands (ESC & l # A) where Letter=2, Legal=3, there's more... + * 4. Remove paper source commands (ESC & l # H) where specific tray=1 and manual feed=2, lower tray=4, there's more... + * 5. Remove duplex commands (ESC & l # S) where Duplex=1,2 and Simplex=0 + * 6. Remove number of copies (ESC & l # X). + * + * @author DocMagic, Document Systems Inc, HowardH 6/13/07 + */ +public class PriModifyPclBytes implements PclCommandEvent { + private ByteArrayOutputStream mByteArrayOutputStream =null; + private static char sESC = 0x1B; // Escape char + private static char sFF = 0xC; // Form-feed + + public PriModifyPclBytes() { + // Make a new ByteArrayOutputStream that grows automatically as parsed Pcl bytes are added + mByteArrayOutputStream = new ByteArrayOutputStream(60 * 1024); // 60k bytes initially, but grows automatically + } + + public void initializeState() { + // Set the byte index to 0 to resuse it's byte array without allocating more memory + mByteArrayOutputStream.reset(); + } + + public byte[] getModifiedPclBytes() { + if (mByteArrayOutputStream != null) { + return mByteArrayOutputStream.toByteArray(); + } else { + return null; + } + } + + public void charFoundEvent(char pNextChar, int pBufferPos) { + if (pNextChar == sFF) { + // Don't add the form feed to the output PCL and return here + // PriDebug.releaseln("PriModifyPclBytes: Removed Form Feed char at input byte " + pBufferPos); + return; + + } else { + mByteArrayOutputStream.write(pNextChar); + } + } + + public void commandFoundEvent( + String pCmdLeadin, String pCmdValue, String pCmdTerminator, byte[] pCmdData, int pBufferPos) { + + String pclCmd = pCmdLeadin + "," + pCmdTerminator; + // Put into char array to not do a lot of String.substring() commands later + char[] tCmdCharArray = pclCmd.toCharArray(); + + if (tCmdCharArray[0] == 'E') { +// PriDebug.releaseln("PriModifyPclBytes: Removed Printer Reset PCL command ESC E"); + return; + } else if (tCmdCharArray[0] == '&') { + if (tCmdCharArray[1] == 'l') { + if (tCmdCharArray[2] == ',') { + if (tCmdCharArray[3] == 'A') { // &l,A is paper size +// PriDebug.releaseln("PriModifyPclBytes: Removed paper size PCL command ESC & l " + +// pCmdValue + " A at input byte " + pBufferPos); + return; + } else if (tCmdCharArray[3] == 'H') { // &l,H is paper source +// PriDebug.releaseln("PriModifyPclBytes: Removed paper source PCL command ESC & l " + +// pCmdValue + " H at input byte " + pBufferPos); + return; + } else if (tCmdCharArray[3] == 'S') { // &l,S is Simplex/Duplex +// PriDebug.releaseln("PriModifyPclBytes: Removed Simplex/Duplex PCL command ESC & l " + +// pCmdValue + " S at input byte " + pBufferPos); + return; + } else if (tCmdCharArray[3] == 'X') { // &l,X is number of copies +// PriDebug.releaseln("PriModifyPclBytes: Removed number of copies PCL command ESC & l " + +// pCmdValue + " X at input byte " + pBufferPos); + return; + } + } + } + } + + mByteArrayOutputStream.write(sESC); + try { + // Write the char after the ESC + if (pCmdLeadin != null && pCmdLeadin.length() > 0) { + mByteArrayOutputStream.write(pCmdLeadin.getBytes()); + } + + // Write the String of numbers + if (pCmdValue != null && pCmdValue.length() > 0) { + mByteArrayOutputStream.write(pCmdValue.getBytes()); + } + + // Write the terminating char + if (pCmdTerminator != null && pCmdTerminator.length() > 0) { + mByteArrayOutputStream.write(pCmdTerminator.getBytes()); + } + + // Write the raster data or soft font data bytes + if (pCmdData != null && pCmdData.length > 0) { + mByteArrayOutputStream.write(pCmdData); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } +} Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-06-12 20:38:29 UTC (rev 86) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-06-14 22:46:28 UTC (rev 87) @@ -33,7 +33,9 @@ import javax.swing.JPanel; import javax.swing.JProgressBar; +import com.openpcl.pclrenderimage.tools.PclParser; import com.openpcl.pclrenderimage.util.PriDebug; +import com.openpcl.pclrenderimage.util.PriModifyPclBytes; import com.openpcl.viewer.panels.PosView; import com.openpcl.viewer.tree.PosTreeNode; import com.openpcl.viewer.util.SwingWorker; @@ -67,7 +69,9 @@ "Print All", "Print Selected", "Print Changed", "Print Remaining"}; public static byte sbESC = 0x1B; // Escape char public static byte sbFF = 0xC; // Form Feed ( char(12) ) - + private PriModifyPclBytes mPriModifyPclBytes = null; + private PclParser mPclParser = null; + /** * Constructor * @author howard 6/1/06 @@ -79,6 +83,7 @@ mParentFrame = mPosView.getOpenPCLViewer().getAppFrame(); mPosPrintBufferedImage = new PosPrintBufferedImage(mPosView); mPosPrintPageableInterface = new PosPrintPageableInterface(mPosView); + mPriModifyPclBytes = new PriModifyPclBytes(); mAttributes = new HashPrintRequestAttributeSet(); mPosPrintSetupDialogChoices = new PosPrintSetupDialogChoices(); mPrintingProgressBar = new JProgressBar(); @@ -126,7 +131,7 @@ StringBuffer tStringBuffer = new StringBuffer(); // Depending on if print all, print selected, print changed, print remaining, get which pages to print - switch (pProcessPrintType) { + switch (mProcessPrintType) { case sProcessPrintAll: mPagesToPrintArrayList = mPosView.getPosBuildListOfPagesToPrint().makeArrayListofAllPages(); tStringBuffer.append("\"Print all\""); @@ -315,6 +320,15 @@ // If no bytes on this page then continue to the next page if (tPclBytes == null || tPclBytes.length < 1) { continue; } + // Modify the PCL bytes + mPriModifyPclBytes.initializeState(); + mPclParser = new PclParser(tPclBytes, mPriModifyPclBytes); + mPclParser.ParsePCL(); + + byte[] tModifiedPclBytes = mPriModifyPclBytes.getModifiedPclBytes(); + + // PriDebug.releaseln("Pcl page before, after bytes: " + tPclBytes.length + ", " + tModifiedPclBytes.length); + try { if (pPosPrintSetupDialogChoices != null && pPosPrintSetupDialogChoices.shouldPrintAllOnLegalSize()) { // The user has a check in the Print Setup dialog box for "Print all Documents on Legal size" @@ -339,7 +353,7 @@ // Write the current page bytes try { - tByteArrayOutputStream.write(tPclBytes); + tByteArrayOutputStream.write(tModifiedPclBytes); if (mShouldOutputFormFeedBetweenPages) { tByteArrayOutputStream.write(sbFF); } } catch (IOException e) { return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |