From: <doc...@us...> - 2007-08-02 18:31:23
|
Revision: 136 http://openpcl.svn.sourceforge.net/openpcl/?rev=136&view=rev Author: documentsystems Date: 2007-08-02 11:31:26 -0700 (Thu, 02 Aug 2007) Log Message: ----------- Howard Hoagland. Put in more code to fix the duplexing to force back pages to be front pages when the DSP info in a Blockument says that form is "Duplex=No" and also force to a front page all Page 1's of forms. Fixed the problem of pages that were supposed to print on the back side were going to the front of the next page, by sending the page size commands to the printer only if the page size changed, and not at the start of every page. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-08-02 18:26:07 UTC (rev 135) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-08-02 18:31:26 UTC (rev 136) @@ -41,6 +41,13 @@ */ public class PosPrintPages { + public static byte sbESC = 0x1B; // Escape char + public static byte sbFF = 0xC; // Form Feed ( char(12) ) + public static final byte[] DUPLEX_OFF_BYTES = new byte[] { sbESC, '&', 'l', '0', 'S' }; + public static final byte[] DUPLEX_ON_BYTES = new byte[] { sbESC, '&', 'l', '1', 'S' }; + public static final int DUPLEX_MODE_NEXTPAGE_ONFRONT = 1; + public static final int DUPLEX_MODE_NEXTPAGE_ONBACK = 2; + private PosView mPosView = null; private Frame mParentFrame = null; private PosPrintBufferedImage mPosPrintBufferedImage = null; @@ -64,17 +71,14 @@ private int mNumberOfPagesThatWillPrint = 0; private static final String[] mTitleBarTextForPrintDialog = { "Print All", "Print Selected", "Print Changed", "Print Remaining"}; - public static byte sbESC = 0x1B; // Escape char - public static byte sbFF = 0xC; // Form Feed ( char(12) ) - public static final byte[] sDuplexOffBytes = new byte[] { sbESC, '&', 'l', '0', 'S' }; - public static final byte[] sDuplexOnBytes = new byte[] { sbESC, '&', 'l', '1', 'S' }; - public static final byte[] sDuplexNextPageBytes = new byte[] {sbESC, '&', 'a', '0', 'G' }; - public static final byte[] sDuplexFrontPageBytes = new byte[] {sbESC, '&', 'a', '1', 'G' }; private PriModifyPclBytes mPriModifyPclBytes = null; private PclParser mPclParser = null; private StringBuffer mIndexNumbersStringBuffer = null; private int mNumberOfCopies = 1; private DocAttributeSet mDocAttributeSet = null; + private int mDuplexModePaperSide = DUPLEX_MODE_NEXTPAGE_ONFRONT; + private String mPreviousPagePaperSize = null; + private String mCurrentPagePaperSize = null; /** * Constructor @@ -527,6 +531,7 @@ byte[] tPclBytes = null; byte[] tLetterlSizePaperBytes = new byte[] {sbESC, '&', 'l', '2', 'A'}; byte[] tLegalSizePaperBytes = new byte[] {sbESC, '&', 'l', '3', 'A'}; + byte[] tTopMargin3LinesBytes = new byte[] {sbESC, '&', 'l', '3', 'E'}; // return if there's no current pages to print if (pPagesToPrintArrayList == null || pPagesToPrintArrayList.size() < 1) { return false; } @@ -536,6 +541,12 @@ // by allocating a new bigger byte array then doing a memcopy to the new one. tByteArrayOutputStream = new ByteArrayOutputStream(20 * 1024); + // Start the print job printing page 1 on the front side + mDuplexModePaperSide = DUPLEX_MODE_NEXTPAGE_ONFRONT; + + // Start with null for previous page paper size + mPreviousPagePaperSize = null; + // Send a printer reset ESC E tByteArrayOutputStream.write(sbESC); tByteArrayOutputStream.write('E'); @@ -543,9 +554,9 @@ // If user clicked Yes for Duplex on Print Setup dialog, then write "Duplex on" Pcl bytes, else write "Duplex off" Pcl bytes try { if (pPosPrintSetupDialogChoices.shouldDuplex()) { - tByteArrayOutputStream.write(sDuplexOnBytes); + tByteArrayOutputStream.write(DUPLEX_ON_BYTES); } else { - tByteArrayOutputStream.write(sDuplexOffBytes); + tByteArrayOutputStream.write(DUPLEX_OFF_BYTES); } } catch (IOException e) { PriDebug.releaseln("Error. Couldn't write Duplex on/off PCL bytes to printer.\n" + e); @@ -564,6 +575,11 @@ // If no bytes on this page then continue to the next page if (tPclBytes == null || tPclBytes.length < 1) { continue; } + // Pick the paper size by calling the below isTreeNodePageLetterSize() which may be subclassed by a plugin. + // The below uses polymorphism because the method isTreeNodePageLetterSize() is one of the subclassed + // methods specified in the interface IPluginHooksOpenPCL + mCurrentPagePaperSize = mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(tPrintThisTreeNode) ? "LTR" : "LGL"; + // Modify the PCL bytes mPriModifyPclBytes.initializeState(); mPclParser = new PclParser(tPclBytes, mPriModifyPclBytes); @@ -572,40 +588,45 @@ byte[] tModifiedPclBytes = mPriModifyPclBytes.getModifiedPclBytes(); // PriDebug.releaseln("Pcl page before, after bytes: " + tPclBytes.length + ", " + tModifiedPclBytes.length); + // On the print setup dialog, if the user clicked "Duplex Yes" if (pPosPrintSetupDialogChoices.shouldDuplex()) { - try { - if (mPosView.getOpenPCLViewer().forceFrontSideWhenDuplexing(tPrintThisTreeNode)) { - // Write "Duplex force front page" PCL bytes (don't use the back side of the page, start a new page) - tByteArrayOutputStream.write(sDuplexFrontPageBytes); - } else { - // Write "Duplex to next page" PCL bytes - tByteArrayOutputStream.write(sDuplexNextPageBytes); - } - } catch (IOException e1) { - PriDebug.releaseln("Error. Couldn't write Duplex next page PCL bytes to printer.\n" + e1); - } - } else { - // Write form feed (in Duplex off mode) - tByteArrayOutputStream.write(sbFF); + duplexingControlFrontBack(tByteArrayOutputStream, tPrintThisTreeNode); } - + try { if (pPosPrintSetupDialogChoices.isPaperSizePrintAllOnLegal()) { // The user has a check in the Print Setup dialog box for "Print all on Legal paper" // so FORCE ALL PAGES TO LEGAL SIZE no matter if LTR in the Blockument DSP values // or if this is a PCL file with a letter size PCL command - tByteArrayOutputStream.write(tLegalSizePaperBytes); + if ( (mPreviousPagePaperSize == null) || (mPreviousPagePaperSize.equalsIgnoreCase("LTR")) ) { + // Only if the previous page was null or Letter, write the Legal size page bytes + tByteArrayOutputStream.write(tLegalSizePaperBytes); + mCurrentPagePaperSize = "LGL"; + } else { + // If the page size didn't change, don't write the page size, but the top margin needs to be set after a form feed + tByteArrayOutputStream.write(tTopMargin3LinesBytes); + } } else { - // Pick the paper size by calling the below method which may be subclassed by a plugin. - // The below uses polymorphism because the method isTreeNodePageLetterSize() is one of the subclassed - // methods specified in the interface IPluginHooksOpenPCL - if (mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(tPrintThisTreeNode)) { + if (mCurrentPagePaperSize.equalsIgnoreCase("LTR")) { // Letter size - tByteArrayOutputStream.write(tLetterlSizePaperBytes); + if ( (mPreviousPagePaperSize == null) || (mPreviousPagePaperSize.equalsIgnoreCase("LGL")) ) { + // Only if the previous page was null or Legal, write the Letter size page bytes + tByteArrayOutputStream.write(tLetterlSizePaperBytes); + } else { + // If the page size didn't change, don't write the page size, but the top margin needs to be set after a form feed + tByteArrayOutputStream.write(tTopMargin3LinesBytes); + } } else { // Legal size - tByteArrayOutputStream.write(tLegalSizePaperBytes); + if ( (mPreviousPagePaperSize == null) || (mPreviousPagePaperSize.equalsIgnoreCase("LTR")) ) { + // Only if the previous page was null or Letter, write the Legal size page bytes + tByteArrayOutputStream.write(tLegalSizePaperBytes); + mCurrentPagePaperSize = "LGL"; + } else { + // If the page size didn't change, don't write the page size, but the top margin needs to be set after a form feed + tByteArrayOutputStream.write(tTopMargin3LinesBytes); + } } } } catch (IOException e) { @@ -629,6 +650,12 @@ PriDebug.releaseln("Error. Couldn't write base page PCL bytes to printer.\n" + e); } + // Write form feed at the end of each page + tByteArrayOutputStream.write(sbFF); + + // Save the current page size to the previous page size to compare the next page with this page + mPreviousPagePaperSize = mCurrentPagePaperSize; + // Update the progress bar at each page if (mPrintingProgressBar != null) { mPrintingProgressBar.setValue(tPageNumber + 1); @@ -636,6 +663,10 @@ } } // end for (tPageNumber = 0; tPageNumber < pPagesToPrintArrayList.size(); tPageNumber++) + // Send a printer reset ESC E at the end of all the pages + tByteArrayOutputStream.write(sbESC); + tByteArrayOutputStream.write('E'); + // The input stream for the DocPrintJob if (tByteArrayOutputStream == null || tByteArrayOutputStream.size() < 1) { return false; } tByteArrayInputStream = new ByteArrayInputStream(tByteArrayOutputStream.toByteArray()); @@ -658,6 +689,31 @@ return true; } + private void duplexingControlFrontBack( + ByteArrayOutputStream pByteArrayOutputStream, PosTreeNode pPosTreeNode) { + + // If the next page is going to print on the back + if (mDuplexModePaperSide == DUPLEX_MODE_NEXTPAGE_ONBACK) { + + // If this page says it must print on the front of the paper, or when the paper size changes + if (mPosView.getOpenPCLViewer().forceFrontSideWhenDuplexing(pPosTreeNode) + || ( !(mPreviousPagePaperSize.equalsIgnoreCase(mCurrentPagePaperSize)) )) { + + // Write an extra form feed here, and say the next page is going to print on the back + pByteArrayOutputStream.write(sbFF); + mDuplexModePaperSide = DUPLEX_MODE_NEXTPAGE_ONBACK; + + } else { + // This page will print on the back, so here say the next page will print on the front + mDuplexModePaperSide = DUPLEX_MODE_NEXTPAGE_ONFRONT; + } + } else { + // This page will print on the front, so here say the next page will print on the back + mDuplexModePaperSide = DUPLEX_MODE_NEXTPAGE_ONBACK; + } + + } + /** * Image print (instead of PCL Direct) * @author Howard 6/1/06. Implemented mult page printing on 8/24/06 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |