From: <doc...@us...> - 2007-07-30 22:20:20
|
Revision: 134 http://openpcl.svn.sourceforge.net/openpcl/?rev=134&view=rev Author: documentsystems Date: 2007-07-30 15:20:21 -0700 (Mon, 30 Jul 2007) Log Message: ----------- Howard Hoagland. In PosPrintPages, added new code to implement duplexing for Pcl Direct (Windows Print not working yet). 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-07-30 22:16:14 UTC (rev 133) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-30 22:20:21 UTC (rev 134) @@ -53,7 +53,6 @@ private ArrayList<PosTreeNode> mPagesToPrintArrayList = null; private JProgressBar mPrintingProgressBar = null; private boolean mPrintedOkReturn = false; - private boolean mShouldOutputFormFeedBetweenPages = true; private JDialog mPrintingProgressJDialog = null; public static final int sProcessPrintAll = 0; public static final int sProcessPrintSelected = 1; @@ -67,6 +66,10 @@ "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; @@ -194,7 +197,13 @@ mIndexNumbersStringBuffer.append(", "); } } - + + // Send the built string to the Java Console + // 1. "Print All" or "Print Selected" or "Print Remaining" or "Print Changed" + // 2. N pages + // 3. Index numbers are: n, n, n, ... n + PriDebug.releaseln(mIndexNumbersStringBuffer.toString()); + // Get a new PrinterJob using its static method mPrinterJob = PrinterJob.getPrinterJob(); @@ -259,47 +268,44 @@ StringBuffer tMsgStringBuffer = new StringBuffer(); // Java Console output window will show all the below: - // "Windows Print" or "Print PCL Direct" + + // 1. To Java Console window: "Windows Print" or "Print PCL Direct" if (mPosPrintSetupDialogChoices.isPrintFormatPclDirect()) { - tMsgStringBuffer.append("\"Print PCL Direct\""); + tMsgStringBuffer.append(" Print PCL Direct"); } else { - tMsgStringBuffer.append("\"Windows Print\""); + tMsgStringBuffer.append(" Windows Print"); } - // to printer selected - tMsgStringBuffer.append(" to printer selected: "); + // 2. To Java Console window: Show printer selected + tMsgStringBuffer.append(" to printer: "); tMsgStringBuffer.append(mPrintService.getName()); - // The 5 radio buttons in the "Paper Size" group box + // 3. To Java Console window: Which of the 5 radio buttons in the "Paper Size" group box if (mPosPrintSetupDialogChoices.isPaperSizeAsDisplayedOrSelected()) { - tMsgStringBuffer.append("\n Print as displayed/selected (no order change and no paper size change)."); + tMsgStringBuffer.append(", as displayed/selected (no order change and no paper size change)"); } else if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { - tMsgStringBuffer.append("\n Print Legal first, then Letter."); + tMsgStringBuffer.append(", Legal first, then Letter"); } else if (mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { - tMsgStringBuffer.append("\n Print Letter first, then Legal."); + tMsgStringBuffer.append(", Letter first, then Legal"); } else if (mPosPrintSetupDialogChoices.isPaperSizePrintAllOnLegal()) { - tMsgStringBuffer.append("\n Print all on Legal paper."); + tMsgStringBuffer.append(", all on Legal paper"); } else if (mPosPrintSetupDialogChoices.isPaperSizePrintAllOnLetterShrinksLegal()) { - tMsgStringBuffer.append("\n Print all on Letter paper (shrinks Legal). "); + tMsgStringBuffer.append(", all on Letter paper (shrinks Legal)"); } - // Additional copies - tMsgStringBuffer.append("\n Additional Copies is " + mPosPrintSetupDialogChoices.getNumAdditionalCopies()); + // 4. To Java Console window: Additional copies=N + tMsgStringBuffer.append(". Additional Copies=" + mPosPrintSetupDialogChoices.getNumAdditionalCopies()); - // Print Form Names - if (mPosPrintSetupDialogChoices.shouldPrintFormNames()) { - tMsgStringBuffer.append("\n Print Form Names."); - } + // 5. To Java Console window: Print Form Names=Yes/No + tMsgStringBuffer.append(", Print Form Names=" + (mPosPrintSetupDialogChoices.shouldPrintFormNames()? "Yes" : "No")); - // "Print All" or "Print Selected" or "Print Remaining" or "Print Changed" - // N pages - // Index numbers are: n, n, n, ... n - tMsgStringBuffer.append("\n " + mIndexNumbersStringBuffer); - + // 6. To Java Console window: Duplex=Yes/No + tMsgStringBuffer.append(", Duplex=" + (mPosPrintSetupDialogChoices.shouldDuplex()? "Yes" : "No")); + // Send the built multi line string to the Java Console PriDebug.releaseln(tMsgStringBuffer.toString()); @@ -513,7 +519,6 @@ DocFlavor tDocFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE; SimpleDoc tSimpleDoc = null; DocPrintJob tDocPrintJob = null; - PrintService tPrintService = null; PosTreeNode tPrintThisTreeNode = null; ByteArrayInputStream tByteArrayInputStream = null; ByteArrayOutputStream tByteArrayOutputStream =null; @@ -531,6 +536,21 @@ // by allocating a new bigger byte array then doing a memcopy to the new one. tByteArrayOutputStream = new ByteArrayOutputStream(20 * 1024); + // Send a printer reset ESC E + tByteArrayOutputStream.write(sbESC); + tByteArrayOutputStream.write('E'); + + // 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); + } else { + tByteArrayOutputStream.write(sDuplexOffBytes); + } + } catch (IOException e) { + PriDebug.releaseln("Error. Couldn't write Duplex on/off PCL bytes to printer.\n" + e); + } + // for each page that the user selected in the tree (could be one page or multi page), get the PCL bytes for (tPageNumber = 0; tPageNumber < pPagesToPrintArrayList.size(); tPageNumber++) { // Get the tree node user object for this print page by indexing into the print ArrayList to get the passed in page number @@ -551,8 +571,26 @@ byte[] tModifiedPclBytes = mPriModifyPclBytes.getModifiedPclBytes(); // PriDebug.releaseln("Pcl page before, after bytes: " + tPclBytes.length + ", " + tModifiedPclBytes.length); + + 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); + } + try { - if (pPosPrintSetupDialogChoices != null && pPosPrintSetupDialogChoices.isPaperSizePrintAllOnLegal()) { + 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 @@ -579,16 +617,16 @@ if (tPrintTimePclBytes != null) { try { tByteArrayOutputStream.write(tPrintTimePclBytes); - } catch (IOException e) { + } catch (IOException e3) { + PriDebug.releaseln("Error. Couldn't write print time only PCL bytes to printer.\n" + e3); } } - // Write the current page bytes try { + // Write the current page bytes tByteArrayOutputStream.write(tModifiedPclBytes); - if (mShouldOutputFormFeedBetweenPages) { tByteArrayOutputStream.write(sbFF); } } catch (IOException e) { - return false; + PriDebug.releaseln("Error. Couldn't write base page PCL bytes to printer.\n" + e); } // Update the progress bar at each page @@ -604,10 +642,9 @@ tSimpleDoc = new SimpleDoc(tByteArrayInputStream, tDocFlavor, mDocAttributeSet); if (tSimpleDoc == null) { return false; } - tPrintService = pPosPrintSetupDialogChoices.getSelectedPrintService(); - if (tPrintService == null) { return false; } + if (mPrintService == null) { return false; } - tDocPrintJob = tPrintService.createPrintJob(); + tDocPrintJob = mPrintService.createPrintJob(); if (tDocPrintJob == null) { return false; } try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |