From: <doc...@us...> - 2007-06-08 17:19:50
|
Revision: 85 http://openpcl.svn.sourceforge.net/openpcl/?rev=85&view=rev Author: documentsystems Date: 2007-06-08 10:18:36 -0700 (Fri, 08 Jun 2007) Log Message: ----------- Fixed bug where the "Finished Printing" dialog was very very wide. 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-06-07 05:12:45 UTC (rev 84) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-06-08 17:18:36 UTC (rev 85) @@ -257,7 +257,7 @@ mPosView.getOpenPCLViewer().setIsDrawingForPrinting(false); mPosView.getOpenPCLViewer().renderImageCurrentPageAndZoom(); JOptionPane.showMessageDialog(mPrintingProgressJDialog, - mParentFrame + "\nFinished printing " + + mPosView.getOpenPCLViewer().getAppName() + "\nFinished printing " + mPagesToPrintArrayList.size() + " page" + (mPagesToPrintArrayList.size() > 1 ? "s." : "."), "Finished Printing", JOptionPane.INFORMATION_MESSAGE); mPrintingProgressJDialog.setVisible(false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-02 18:21:45
|
Revision: 96 http://openpcl.svn.sourceforge.net/openpcl/?rev=96&view=rev Author: documentsystems Date: 2007-07-02 11:21:48 -0700 (Mon, 02 Jul 2007) Log Message: ----------- Changed to reference class instance varialbe mProcessPrintType in several places instead of the passed in variable. 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-06-21 23:43:48 UTC (rev 95) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-02 18:21:48 UTC (rev 96) @@ -132,6 +132,7 @@ mProcessPrintType = pProcessPrintType; StringBuffer tStringBuffer = new StringBuffer(); + mPagesToPrintArrayList = null; // Depending on if print all, print selected, print changed, print remaining, get which pages to print switch (mProcessPrintType) { case sProcessPrintAll: @@ -157,24 +158,24 @@ mPosView.getOpenPCLViewer().setIsDrawingForPrinting(false); // Show error dialog depending on if print all, print selected, print changed, print remaining. - switch (pProcessPrintType) { + switch (mProcessPrintType) { case sProcessPrintAll: - JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[pProcessPrintType] + + JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[mProcessPrintType] + "\" because no pages found to print", "No pages to print", JOptionPane.INFORMATION_MESSAGE); break; case sProcessPrintSelected: - JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[pProcessPrintType] + + JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[mProcessPrintType] + "\" because you need to Left Click on the tree to select one or more pages.", "No pages to print", JOptionPane.INFORMATION_MESSAGE); break; case sProcessPrintChanged: - JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[pProcessPrintType] + + JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[mProcessPrintType] + "\" because no changed pages were found.", "No pages to print", JOptionPane.INFORMATION_MESSAGE); break; case sProcessPrintRemaining: - JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[pProcessPrintType] + + JOptionPane.showMessageDialog(mParentFrame, "Can't \"" + mTitleBarTextForPrintDialog[mProcessPrintType] + "\" because you need to Left Click on the tree to select one or more pages.", "No pages to print", JOptionPane.INFORMATION_MESSAGE); break; @@ -306,8 +307,10 @@ // return if there's no current pages to print if (pPagesToPrintArrayList == null || pPagesToPrintArrayList.size() < 1) { return false; } - // Make a new ByteArrayOutputStream with the Pcl bytes gotten from the BLK page or from the PCL file page - tByteArrayOutputStream = new ByteArrayOutputStream(20000); + // Make a new ByteArrayOutputStream with 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. + tByteArrayOutputStream = new ByteArrayOutputStream(20 * 1024); // Get the PCL bytes for each page that the user selected in the tree (could be one page or multi page) for (tPageNumber = 0; tPageNumber < pPagesToPrintArrayList.size(); tPageNumber++) { @@ -340,7 +343,7 @@ tByteArrayOutputStream.write(tLegalSizePaperBytes); } else { - // Pick the paper size by calling the below method with may be subclassed by a plugin. + // 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)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <doc...@us...> - 2007-07-16 21:39:57
|
Revision: 106 http://openpcl.svn.sourceforge.net/openpcl/?rev=106&view=rev Author: documentsystems Date: 2007-07-16 14:38:20 -0700 (Mon, 16 Jul 2007) Log Message: ----------- Howard Hoagland. Moved the initial instantiation of PrintRequestAttributeSet from PosPrintPages to OpenPCLViewer, so deleted import statements for setting PrintRequestAttributeSet items. 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-10 02:09:57 UTC (rev 105) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-16 21:38:20 UTC (rev 106) @@ -11,22 +11,13 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Locale; import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintException; import javax.print.PrintService; import javax.print.SimpleDoc; -import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; -import javax.print.attribute.Size2DSyntax; -import javax.print.attribute.standard.JobName; -import javax.print.attribute.standard.MediaPrintableArea; -import javax.print.attribute.standard.MediaSize; -import javax.print.attribute.standard.OrientationRequested; -import javax.print.attribute.standard.PrintQuality; -import javax.print.attribute.standard.Sides; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JOptionPane; @@ -457,7 +448,7 @@ // Set the Pageable Interface object on the PrinterJob. // Note that this Pageable Interface object has the Printable Interface object set in it from above mPrinterJob.setPageable(mPosPrintPageableInterface); - + try { // Set the user selected printer on the PrinterJob mPrinterJob.setPrintService(mPrintService); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-23 23:38:12
|
Revision: 113 http://openpcl.svn.sourceforge.net/openpcl/?rev=113&view=rev Author: documentsystems Date: 2007-07-23 16:38:14 -0700 (Mon, 23 Jul 2007) Log Message: ----------- For PCL Direct (not Windows Print), implemented the print "Legal first, then Letter" and "Letter first, then Legal". 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-23 23:08:15 UTC (rev 112) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-23 23:38:14 UTC (rev 113) @@ -64,9 +64,8 @@ private PriModifyPclBytes mPriModifyPclBytes = null; private PclParser mPclParser = null; private StringBuffer mIndexNumbersStringBuffer = null; - private int mNumberOfPrintPasses = 1; - private int mCurrentPrintPassNumber = 1; - + private int mNumberOfCopies = 1; + /** * Constructor * @author howard 6/1/06 @@ -278,19 +277,21 @@ PriDebug.releaseln(tMsgStringBuffer.toString()); // The number of additional copies has already been validated and is guaranteed to be 0 to 3 at this point - mNumberOfPrintPasses = 1 + mPosPrintSetupDialogChoices.getNumAdditionalCopies(); + mNumberOfCopies = 1 + mPosPrintSetupDialogChoices.getNumAdditionalCopies(); // Call the print of the all/selected/remaining/changed pages "N" times depending on Additional Copies field - for (int i = 1; i <= mNumberOfPrintPasses; i++) { + for (int tNumCopies = 1; tNumCopies <= mNumberOfCopies; tNumCopies++) { + // Call "Use Windows Print" or "Print PCL Direct" - if (mPosPrintSetupDialogChoices.isPrintFormatPclDirect()) { - mPrintedOkReturn = printPclDirect(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, + if (mPosPrintSetupDialogChoices.isPrintFormatWindowsPrint()) { + mPrintedOkReturn = imagePrint(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, mPrintingProgressBar, mPrintRequestAttributeSet); } else { - mPrintedOkReturn = imagePrint(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, + mPrintedOkReturn = printPclDirect(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, mPrintingProgressBar, mPrintRequestAttributeSet); } - } + + } // end "for (int tNumCopies = 1; tNumCopies <= mNumberOfCopies; tNumCopies++)" return null; } @@ -331,6 +332,7 @@ ByteArrayInputStream tByteArrayInputStream = null; ByteArrayOutputStream tByteArrayOutputStream =null; int tPageNumber = 0; + int tLegalLetterPassesToDo = 1; String tProgressBarBaseString = "Generating page: "; byte[] tPclBytes = null; byte[] tLetterlSizePaperBytes = new byte[] {sbESC, '&', 'l', '2', 'A'}; @@ -344,67 +346,111 @@ // by allocating a new bigger byte array then doing a memcopy to the new one. tByteArrayOutputStream = new ByteArrayOutputStream(20 * 1024); - // Get the PCL bytes for each page that the user selected in the tree (could be one page or multi page) - for (tPageNumber = 0; tPageNumber < pPagesToPrintArrayList.size(); tPageNumber++) { - // return if the passed in page number is less than 0 or greater than the number of current pages to print - if (tPageNumber < 0 || tPageNumber >= mPagesToPrintArrayList.size()) { return false; } - // Get the tree node user object for this print page by indexing into the print ArrayList to get the passed in page number - tPrintThisTreeNode = mPagesToPrintArrayList.get(tPageNumber); - // null pointer protection due to tree node user object got assigned to null from the ArrayList.get() above - if (tPrintThisTreeNode == null) { continue; } - - // Get the actual PCL bytes to send to the printer - tPclBytes = mPosView.getOpenPCLViewer().getPclBytesForTreeNode(tPrintThisTreeNode); - - // 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.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); - - } 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 + // Set the int variable that controls the "Legal first, then Letter", and "Letter first, then Legal" + if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter() || + mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { + tLegalLetterPassesToDo = 2; + } else { + tLegalLetterPassesToDo = 1; + } + + // If doing "Legal first, then Letter" or doing "Letter first, then Legal", make 2 inner print passes here + for (int tLglLtrPassCount = 1; tLglLtrPassCount <= tLegalLetterPassesToDo; tLglLtrPassCount++) { + + // 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 + tPrintThisTreeNode = mPagesToPrintArrayList.get(tPageNumber); + // null pointer protection to avoid stack dump + if (tPrintThisTreeNode == null) { continue; } + + // If doing "Legal first, then Letter" or doing "Letter first, then Legal" then skip Letter or Legal pages depending + if (tLegalLetterPassesToDo > 1) { if (mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(tPrintThisTreeNode)) { - // Letter size - tByteArrayOutputStream.write(tLetterlSizePaperBytes); + // This page is Letter size + if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { + // Print dialog setting is "Legal first, then Letter" + if (tLglLtrPassCount == 1) { + // and this is the 1st pass, so skip Letter pages + continue; + } + } else if (mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { + // Print dialog setting is "Letter first, then Legal " + if (tLglLtrPassCount == 2) { + // and this is the 2nd pass, so skip Letter pages + continue; + } + } } else { - // Legal size + // This page is Legal size + if (mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { + // Print dialog setting is "Letter first, then Legal" + if (tLglLtrPassCount == 1) { + // and this is the 1st pass, so skip Legal pages + continue; + } + } else if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { + // Print dialog setting is "Legal first, then Letter" + if (tLglLtrPassCount == 2) { + // and this is the 2nd pass, so skip Legal pages + continue; + } + } + } + } // end "if (tLegalLetterPassesToDo > 1)" + + // Get the actual PCL bytes to send to the printer + tPclBytes = mPosView.getOpenPCLViewer().getPclBytesForTreeNode(tPrintThisTreeNode); + + // 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.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); + + } 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)) { + // Letter size + tByteArrayOutputStream.write(tLetterlSizePaperBytes); + } else { + // Legal size + tByteArrayOutputStream.write(tLegalSizePaperBytes); + } } + } catch (IOException e) { + return false; } - } catch (IOException e) { - return false; - } - // Write the current page bytes - try { - tByteArrayOutputStream.write(tModifiedPclBytes); - if (mShouldOutputFormFeedBetweenPages) { tByteArrayOutputStream.write(sbFF); } - } catch (IOException e) { - return false; - } - - // Update the progress bar at each page - if (mPrintingProgressBar != null) { - mPrintingProgressBar.setValue(tPageNumber + 1); - mPrintingProgressBar.setString(tProgressBarBaseString + (tPageNumber + 1) + " of " + pPagesToPrintArrayList.size()); - } - } // end of for loop + // Write the current page bytes + try { + tByteArrayOutputStream.write(tModifiedPclBytes); + if (mShouldOutputFormFeedBetweenPages) { tByteArrayOutputStream.write(sbFF); } + } catch (IOException e) { + return false; + } + + // Update the progress bar at each page + if (mPrintingProgressBar != null) { + mPrintingProgressBar.setValue(tPageNumber + 1); + mPrintingProgressBar.setString(tProgressBarBaseString + (tPageNumber + 1) + " of " + pPagesToPrintArrayList.size()); + } + } // end for (tPageNumber = 0; tPageNumber < pPagesToPrintArrayList.size(); tPageNumber++) + } // end "for (int tLglLtrPassCount = 0; tLglLtrPassCount < mLegalLetterPassesToDo; tLglLtrPassCount++)" + // The input stream for the DocPrintJob if (tByteArrayOutputStream == null || tByteArrayOutputStream.size() < 1) { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-24 01:11:25
|
Revision: 114 http://openpcl.svn.sourceforge.net/openpcl/?rev=114&view=rev Author: documentsystems Date: 2007-07-23 18:11:27 -0700 (Mon, 23 Jul 2007) Log Message: ----------- Howard Hoagland. Made a DocAttributeSet, then added the DocumentName to the HashDocAttributeSet, then passed the DocAttributeSet in the SimpleDoc constructor. 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-23 23:38:14 UTC (rev 113) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-24 01:11:27 UTC (rev 114) @@ -11,13 +11,17 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Locale; import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintException; import javax.print.PrintService; import javax.print.SimpleDoc; +import javax.print.attribute.DocAttributeSet; +import javax.print.attribute.HashDocAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.DocumentName; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JOptionPane; @@ -65,6 +69,7 @@ private PclParser mPclParser = null; private StringBuffer mIndexNumbersStringBuffer = null; private int mNumberOfCopies = 1; + private DocAttributeSet mDocAttributeSet = null; /** * Constructor @@ -77,6 +82,8 @@ mParentFrame = mPosView.getOpenPCLViewer().getAppFrame(); mPrintRequestAttributeSet = mPosView.getOpenPCLViewer().getPrintRequestAttributeSet(); mPosPrintSetupDialogChoices = mPosView.getOpenPCLViewer().getPosPrintSetupDialogChoices(); + mDocAttributeSet = new HashDocAttributeSet(); + mDocAttributeSet.add(new DocumentName(mPosView.getOpenPCLViewer().getAppName() + " print", Locale.getDefault())); mPosPrintBufferedImage = new PosPrintBufferedImage(mPosView); mPosPrintPageableInterface = new PosPrintPageableInterface(mPosView); mPriModifyPclBytes = new PriModifyPclBytes(); @@ -455,7 +462,7 @@ // The input stream for the DocPrintJob if (tByteArrayOutputStream == null || tByteArrayOutputStream.size() < 1) { return false; } tByteArrayInputStream = new ByteArrayInputStream(tByteArrayOutputStream.toByteArray()); - tSimpleDoc = new SimpleDoc(tByteArrayInputStream, tDocFlavor, null); + tSimpleDoc = new SimpleDoc(tByteArrayInputStream, tDocFlavor, mDocAttributeSet); if (tSimpleDoc == null) { return false; } tPrintService = pPosPrintSetupDialogChoices.getSelectedPrintService(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-24 20:25:43
|
Revision: 115 http://openpcl.svn.sourceforge.net/openpcl/?rev=115&view=rev Author: documentsystems Date: 2007-07-24 13:25:46 -0700 (Tue, 24 Jul 2007) Log Message: ----------- Howard Hoagland. Implemented print "Legal first, the Letter" and "Letter first, then Legal" by reordering the page objects in the ArrayList that gets passed to the print PCL Direct and the Image Print methods. 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-24 01:11:27 UTC (rev 114) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-24 20:25:46 UTC (rev 115) @@ -230,6 +230,12 @@ mPrintingProgressBar.setValue(0); mPrintingProgressJDialog.setLocationRelativeTo(mParentFrame); + if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { + moveLegalPagesToTopOfArrayList(mPagesToPrintArrayList); + } else if (mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { + moveLetterPagesToTopOfArrayList(mPagesToPrintArrayList); + } + final SwingWorker threadShowProgressBar = new SwingWorker() { public Object construct() { mPrintingProgressJDialog.setVisible(true); @@ -318,6 +324,50 @@ return mPrintedOkReturn; } + private void moveLegalPagesToTopOfArrayList(ArrayList<PosTreeNode> pPagesToPrintArrayList) { + // Hold the Letter size page entries that should be moved to the bottom + ArrayList<PosTreeNode> tMoveToBottomArrayList = new ArrayList<PosTreeNode>(pPagesToPrintArrayList.size()); + // Look thru each entry + for (PosTreeNode eachPosTreeNode : pPagesToPrintArrayList) { + if (mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(eachPosTreeNode)) { + // This is a Letter page so add it to the "move to bottom" ArrayList + tMoveToBottomArrayList.add(eachPosTreeNode); + } + } + + // If there were any Letter size pages that got moved to the "move to bottom" ArrayList + if (tMoveToBottomArrayList.size() > 1) { + for (PosTreeNode removeThisPosTreeNode : tMoveToBottomArrayList) { + // Remove the Letter pages from the passed in ArrayList + pPagesToPrintArrayList.remove(removeThisPosTreeNode); + } + // Then move the Letter size pages to the bottom of the passed in ArrayList + pPagesToPrintArrayList.addAll(tMoveToBottomArrayList); + } + } + + private void moveLetterPagesToTopOfArrayList(ArrayList<PosTreeNode> pPagesToPrintArrayList) { + // Hold the Legal size page entries that should be moved to the bottom + ArrayList<PosTreeNode> tMoveToBottomArrayList = new ArrayList<PosTreeNode>(pPagesToPrintArrayList.size()); + // Look thru each entry + for (PosTreeNode eachPosTreeNode : pPagesToPrintArrayList) { + if ( !(mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(eachPosTreeNode)) ) { + // This is a Legal page so add it to the "move to bottom" ArrayList + tMoveToBottomArrayList.add(eachPosTreeNode); + } + } + + // If there were any Legal size pages that got moved to the "move to bottom" ArrayList + if (tMoveToBottomArrayList.size() > 1) { + for (PosTreeNode removeThisPosTreeNode : tMoveToBottomArrayList) { + // Remove the Legal pages from the passed in ArrayList + pPagesToPrintArrayList.remove(removeThisPosTreeNode); + } + // Then move the Legal size pages to the bottom of the passed in ArrayList + pPagesToPrintArrayList.addAll(tMoveToBottomArrayList); + } + } + /** * print Pcl Direct * @author Howard 6/1/06. Implemented mult page printing on 8/28/06 @@ -339,7 +389,6 @@ ByteArrayInputStream tByteArrayInputStream = null; ByteArrayOutputStream tByteArrayOutputStream =null; int tPageNumber = 0; - int tLegalLetterPassesToDo = 1; String tProgressBarBaseString = "Generating page: "; byte[] tPclBytes = null; byte[] tLetterlSizePaperBytes = new byte[] {sbESC, '&', 'l', '2', 'A'}; @@ -353,112 +402,64 @@ // by allocating a new bigger byte array then doing a memcopy to the new one. tByteArrayOutputStream = new ByteArrayOutputStream(20 * 1024); - // Set the int variable that controls the "Legal first, then Letter", and "Letter first, then Legal" - if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter() || - mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { - tLegalLetterPassesToDo = 2; - } else { - tLegalLetterPassesToDo = 1; - } - - // If doing "Legal first, then Letter" or doing "Letter first, then Legal", make 2 inner print passes here - for (int tLglLtrPassCount = 1; tLglLtrPassCount <= tLegalLetterPassesToDo; tLglLtrPassCount++) { + // 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 + tPrintThisTreeNode = mPagesToPrintArrayList.get(tPageNumber); + // null pointer protection to avoid stack dump + if (tPrintThisTreeNode == null) { continue; } - // 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 - tPrintThisTreeNode = mPagesToPrintArrayList.get(tPageNumber); - // null pointer protection to avoid stack dump - if (tPrintThisTreeNode == null) { continue; } - - // If doing "Legal first, then Letter" or doing "Letter first, then Legal" then skip Letter or Legal pages depending - if (tLegalLetterPassesToDo > 1) { - if (mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(tPrintThisTreeNode)) { - // This page is Letter size - if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { - // Print dialog setting is "Legal first, then Letter" - if (tLglLtrPassCount == 1) { - // and this is the 1st pass, so skip Letter pages - continue; - } - } else if (mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { - // Print dialog setting is "Letter first, then Legal " - if (tLglLtrPassCount == 2) { - // and this is the 2nd pass, so skip Letter pages - continue; - } - } - } else { - // This page is Legal size - if (mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { - // Print dialog setting is "Letter first, then Legal" - if (tLglLtrPassCount == 1) { - // and this is the 1st pass, so skip Legal pages - continue; - } - } else if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { - // Print dialog setting is "Legal first, then Letter" - if (tLglLtrPassCount == 2) { - // and this is the 2nd pass, so skip Legal pages - continue; - } - } - } - } // end "if (tLegalLetterPassesToDo > 1)" - - // Get the actual PCL bytes to send to the printer - tPclBytes = mPosView.getOpenPCLViewer().getPclBytesForTreeNode(tPrintThisTreeNode); + // Get the actual PCL bytes to send to the printer + tPclBytes = mPosView.getOpenPCLViewer().getPclBytesForTreeNode(tPrintThisTreeNode); - // If no bytes on this page then continue to the next page - if (tPclBytes == null || tPclBytes.length < 1) { continue; } + // 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(); + // 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.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); + byte[] tModifiedPclBytes = mPriModifyPclBytes.getModifiedPclBytes(); + // PriDebug.releaseln("Pcl page before, after bytes: " + tPclBytes.length + ", " + tModifiedPclBytes.length); + try { + if (pPosPrintSetupDialogChoices != null && 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); + } 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)) { + // Letter size + tByteArrayOutputStream.write(tLetterlSizePaperBytes); } 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)) { - // Letter size - tByteArrayOutputStream.write(tLetterlSizePaperBytes); - } else { - // Legal size - tByteArrayOutputStream.write(tLegalSizePaperBytes); - } + // Legal size + tByteArrayOutputStream.write(tLegalSizePaperBytes); } - } catch (IOException e) { - return false; } + } catch (IOException e) { + return false; + } - // Write the current page bytes - try { - tByteArrayOutputStream.write(tModifiedPclBytes); - if (mShouldOutputFormFeedBetweenPages) { tByteArrayOutputStream.write(sbFF); } - } catch (IOException e) { - return false; - } + // Write the current page bytes + try { + tByteArrayOutputStream.write(tModifiedPclBytes); + if (mShouldOutputFormFeedBetweenPages) { tByteArrayOutputStream.write(sbFF); } + } catch (IOException e) { + return false; + } - // Update the progress bar at each page - if (mPrintingProgressBar != null) { - mPrintingProgressBar.setValue(tPageNumber + 1); - mPrintingProgressBar.setString(tProgressBarBaseString + (tPageNumber + 1) + " of " + pPagesToPrintArrayList.size()); - } - } // end for (tPageNumber = 0; tPageNumber < pPagesToPrintArrayList.size(); tPageNumber++) - } // end "for (int tLglLtrPassCount = 0; tLglLtrPassCount < mLegalLetterPassesToDo; tLglLtrPassCount++)" + // Update the progress bar at each page + if (mPrintingProgressBar != null) { + mPrintingProgressBar.setValue(tPageNumber + 1); + mPrintingProgressBar.setString(tProgressBarBaseString + (tPageNumber + 1) + " of " + pPagesToPrintArrayList.size()); + } + } // end for (tPageNumber = 0; tPageNumber < pPagesToPrintArrayList.size(); tPageNumber++) - // The input stream for the DocPrintJob if (tByteArrayOutputStream == null || tByteArrayOutputStream.size() < 1) { return false; } tByteArrayInputStream = new ByteArrayInputStream(tByteArrayOutputStream.toByteArray()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-25 19:58:04
|
Revision: 121 http://openpcl.svn.sourceforge.net/openpcl/?rev=121&view=rev Author: documentsystems Date: 2007-07-25 12:57:45 -0700 (Wed, 25 Jul 2007) Log Message: ----------- Howard Hoagland. In PosPrintPages, for print "PCL Direct" (doesn't implement "Windows Print" yet) added the code that does the "Print Form Names" that is on the print setup dialog. 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-25 19:54:16 UTC (rev 120) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-25 19:57:45 UTC (rev 121) @@ -59,6 +59,8 @@ public static final int sProcessPrintSelected = 1; public static final int sProcessPrintChanged = 2; public static final int sProcessPrintRemaining = 3; + public static final int sPageOrientationPortrait = 1; + public static final int sPageOrientationLandscape = 2; private int mProcessPrintType = 0; private int mNumberOfPagesThatWillPrint = 0; private static final String[] mTitleBarTextForPrintDialog = { @@ -225,23 +227,30 @@ return false; } + // Call setters on the progress bar mPrintingProgressBar.setMaximum(mNumberOfPagesThatWillPrint); mPrintingProgressBar.setString("Initializing..."); mPrintingProgressBar.setValue(0); mPrintingProgressJDialog.setLocationRelativeTo(mParentFrame); + // Reorder ArrayList items depending on if "Legal first then Letter" or "Letter first then Legal" if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { moveLegalPagesToTopOfArrayList(mPagesToPrintArrayList); } else if (mPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal()) { moveLetterPagesToTopOfArrayList(mPagesToPrintArrayList); } + + // Add Pcl bytes for printing + addPclBytesForPrinting(mPagesToPrintArrayList); + // Thread for showing the progress bar final SwingWorker threadShowProgressBar = new SwingWorker() { public Object construct() { mPrintingProgressJDialog.setVisible(true); return null; }}; - + + // Thread for calling imagePrint() or calling printPclDirect() final SwingWorker threadPrintPages = new SwingWorker() { public Object construct() { // Show the JDialog that has the JProgressBar @@ -263,7 +272,7 @@ // The 5 radio buttons in the "Paper Size" group box if (mPosPrintSetupDialogChoices.isPaperSizeAsDisplayedOrSelected()) { - tMsgStringBuffer.append("\n Print as displayed/selected."); + tMsgStringBuffer.append("\n Print as displayed/selected (no order change and no paper size change)."); } else if (mPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter()) { tMsgStringBuffer.append("\n Print Legal first, then Letter."); @@ -281,6 +290,11 @@ // Additional copies tMsgStringBuffer.append("\n Additional Copies is " + mPosPrintSetupDialogChoices.getNumAdditionalCopies()); + // Print Form Names + if (mPosPrintSetupDialogChoices.shouldPrintFormNames()) { + tMsgStringBuffer.append("\n Print Form Names."); + } + // "Print All" or "Print Selected" or "Print Remaining" or "Print Changed" // N pages // Index numbers are: n, n, n, ... n @@ -309,6 +323,7 @@ return null; } + // After the printing thread is finished, this method is automatically called, to draw the current page being viewed again public void finished() { mPosView.getOpenPCLViewer().setIsDrawingForPrinting(false); mPosView.getOpenPCLViewer().renderImageCurrentPageAndZoom(); @@ -323,7 +338,8 @@ threadPrintPages.start(); return mPrintedOkReturn; } - + + /** Move Legal pages to the top of the ArrayList of page items */ private void moveLegalPagesToTopOfArrayList(ArrayList<PosTreeNode> pPagesToPrintArrayList) { // Hold the Letter size page entries that should be moved to the bottom ArrayList<PosTreeNode> tMoveToBottomArrayList = new ArrayList<PosTreeNode>(pPagesToPrintArrayList.size()); @@ -346,6 +362,7 @@ } } + /** Move Letter pages to the top of the ArrayList of page items */ private void moveLetterPagesToTopOfArrayList(ArrayList<PosTreeNode> pPagesToPrintArrayList) { // Hold the Legal size page entries that should be moved to the bottom ArrayList<PosTreeNode> tMoveToBottomArrayList = new ArrayList<PosTreeNode>(pPagesToPrintArrayList.size()); @@ -368,6 +385,90 @@ } } + /** Add more Pcl bytes for printing. These bytes will be used for both PCL Direct printing and Windows/Image print. */ + private void addPclBytesForPrinting(ArrayList<PosTreeNode> pPagesToPrintArrayList) { + // Where to write the Pcl bytes for printing + ByteArrayOutputStream tByteArrayOutputStream = new ByteArrayOutputStream(1024); // grows automatically if needed + + // Run through all the pages to print + for (PosTreeNode eachPosTreeNode : pPagesToPrintArrayList) { + + // If the user clicked "Yes" on "Print Form Names" on the Print Setup dialog + if (mPosPrintSetupDialogChoices.shouldPrintFormNames()) { + // Add bytes for the Form + String tFormName = mPosView.getOpenPCLViewer().getFormNameForTreeNode(eachPosTreeNode); + String tLetterOrLegal = "LGL"; + if (mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(eachPosTreeNode)) { + tLetterOrLegal = "LTR"; + } + addPclBytesForPrintingFormNames(tLetterOrLegal, tFormName, sPageOrientationPortrait, tByteArrayOutputStream); + } + + // Future use below. Add Pcl bytes for printing "xyz" on the page + // ... + + if (tByteArrayOutputStream.size() > 0) { + // Put the resulting Pcl bytes in the PosTreeNode byte[] mPrintTimePclBytes + eachPosTreeNode.setPrintTimePclBytes(tByteArrayOutputStream.toByteArray()); + } else { + // There's no extra drawing needed to be done so set to null + eachPosTreeNode.setPrintTimePclBytes(null); + } + + // Re-use the same ByteArrayOutputStream by setting the index pointer to 0 + tByteArrayOutputStream.reset(); + } + } + + private void addPclBytesForPrintingFormNames(String pLetterOrLegal, String pFormName, + int pPageOrientation, ByteArrayOutputStream pBaos) { + final byte[] tFormNameFont = new byte[] {sbESC, '(', 's', '4', '1', '4', '8', 't', // Univers typeface + '0', 'b', // not bold + '0', 's', // not italics + '8', 'v', // 8 point heigh + '1', 'P'}; // Proportional + + final byte[] tDefaultCourierFont = new byte[] {sbESC, '(', 's', '3', 't', // Courier typeface + '0', 'b', // not bold + '0', 's', // not italics + '1', '0', 'h', // 10 cpi + '1', '2', 'v', // 12 point heigh + '0', 'P'}; // Monospaced + + // Return if form name is null or blank + if (pFormName == null || pFormName.length() < 1) { return; } + + int tYPosForLetterPortrait = (300 * 11) - 205; + int tYPosForLegalPortrait = (300 * 14) - 205; + int tYPosforLetterOrLegalLandscape =(int)(Math.round(300 * 8.5d) - 205); + + // Default to Legal Portrait Y position + int tYPosForFormName = tYPosForLegalPortrait; + + if (pPageOrientation == sPageOrientationPortrait) { + if (pLetterOrLegal.equalsIgnoreCase("LTR")) { + tYPosForFormName = tYPosForLetterPortrait; + } + } else if (pPageOrientation == sPageOrientationLandscape) { + tYPosForFormName = tYPosforLetterOrLegalLandscape; + } + + try { + pBaos.write(tFormNameFont); + pBaos.write(sbESC); + pBaos.write('*'); + pBaos.write('p'); + pBaos.write('0'); + pBaos.write('x'); + pBaos.write(String.valueOf(tYPosForFormName).getBytes()); + pBaos.write('Y'); // Cursor position to (x,y) using ESC * p 0 x 123 Y + pBaos.write(pFormName.getBytes()); + pBaos.write(tDefaultCourierFont); + } catch (IOException e) { + PriDebug.releaseln("In PosPrintPages, can't write Form Name into ByteArrayOutputStream"); + } + } + /** * print Pcl Direct * @author Howard 6/1/06. Implemented mult page printing on 8/28/06 @@ -445,6 +546,15 @@ return false; } + // If there were any PCL bytes to include only at print time (not to be viewed on the screen) then write the bytes here + byte[] tPrintTimePclBytes = tPrintThisTreeNode.getPrintTimePclBytes(); + if (tPrintTimePclBytes != null) { + try { + tByteArrayOutputStream.write(tPrintTimePclBytes); + } catch (IOException e) { + } + } + // Write the current page bytes try { tByteArrayOutputStream.write(tModifiedPclBytes); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-26 18:33:20
|
Revision: 129 http://openpcl.svn.sourceforge.net/openpcl/?rev=129&view=rev Author: documentsystems Date: 2007-07-26 11:33:23 -0700 (Thu, 26 Jul 2007) Log Message: ----------- Howard Hoagland. In PosPrintPages in addpclBytesforPrintingFormNames(), changed the hard coded pixels from bottom edge of page of 205 in 3 lines to be the int variable tNumPixelsFromPageEdge with value 210, so that the bottom of the text of the form names at the bottom of the page, won't get chopped off due to it was too low to fit in the printabe area. This was needed for 8 point font. Using 6 point font then 205 is OK. 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-26 18:29:28 UTC (rev 128) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-26 18:33:23 UTC (rev 129) @@ -438,9 +438,10 @@ // Return if form name is null or blank if (pFormName == null || pFormName.length() < 1) { return; } - int tYPosForLetterPortrait = (300 * 11) - 205; - int tYPosForLegalPortrait = (300 * 14) - 205; - int tYPosforLetterOrLegalLandscape =(int)(Math.round(300 * 8.5d) - 205); + final int tNumPixelsFromPageEdge = 210; + final int tYPosForLetterPortrait = (300 * 11) - tNumPixelsFromPageEdge; + final int tYPosForLegalPortrait = (300 * 14) - tNumPixelsFromPageEdge; + final int tYPosforLetterOrLegalLandscape =(int)(Math.round(300 * 8.5d) - tNumPixelsFromPageEdge); // Default to Legal Portrait Y position int tYPosForFormName = tYPosForLegalPortrait; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-26 20:48:40
|
Revision: 130 http://openpcl.svn.sourceforge.net/openpcl/?rev=130&view=rev Author: documentsystems Date: 2007-07-26 13:48:42 -0700 (Thu, 26 Jul 2007) Log Message: ----------- Howard Hoagland. In PosPrintPages, in addPclBytesForPrintingFormNames(), added code to adjust higher the Y location of the Form Name at the bottom of the page of Legal pages shrunk to fit on Letter paper, and adjust lower to go to the bottom of the page for Letter pages printed on Legal paper. 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-26 18:33:23 UTC (rev 129) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-26 20:48:42 UTC (rev 130) @@ -439,35 +439,62 @@ if (pFormName == null || pFormName.length() < 1) { return; } final int tNumPixelsFromPageEdge = 210; + final int tNumPixelsFromPageEdgeWhenShrinkLegalOnLetter = 230; + final int tYPosForLetterPortrait = (300 * 11) - tNumPixelsFromPageEdge; final int tYPosForLegalPortrait = (300 * 14) - tNumPixelsFromPageEdge; + final int tYPosForLegalPortraitWhenShrinkToLetter = (300 * 14) - tNumPixelsFromPageEdgeWhenShrinkLegalOnLetter; final int tYPosforLetterOrLegalLandscape =(int)(Math.round(300 * 8.5d) - tNumPixelsFromPageEdge); - // Default to Legal Portrait Y position - int tYPosForFormName = tYPosForLegalPortrait; - + // Default to Letter Portrait Y position + int tYPosForFormName = tYPosForLetterPortrait; + + // Set the Y position for where to put the Form Name depending on 3 things: + // 1. Portrait/Landcape + // 2. Letter/Legal + // 3. Print all on Letter/Legal if (pPageOrientation == sPageOrientationPortrait) { - if (pLetterOrLegal.equalsIgnoreCase("LTR")) { - tYPosForFormName = tYPosForLetterPortrait; + // Here for Portrait + if (pLetterOrLegal.equalsIgnoreCase("LGL")) { + // Here for Portrait and Legal + if (mPosPrintSetupDialogChoices.isPaperSizePrintAllOnLetterShrinksLegal()) { + // Here for Portrait and Legal and Print all on Letter (shrink Legal) + tYPosForFormName = tYPosForLegalPortraitWhenShrinkToLetter; + } else { + // Here for Portrait and Legal + tYPosForFormName = tYPosForLegalPortrait; + } + + } else if (pLetterOrLegal.equalsIgnoreCase("LTR")) { + // Here for Portrait and Letter + if (mPosPrintSetupDialogChoices.isPaperSizePrintAllOnLegal()) { + // Here for Portrait and Letter and Print all on Legal + tYPosForFormName = tYPosForLegalPortrait; + } else { + // Here for Portrait and Letter + tYPosForFormName = tYPosForLetterPortrait; + } } } else if (pPageOrientation == sPageOrientationLandscape) { + // Here for Landscape. There's only one condition for now. If Landscape is implemented later, then add more here tYPosForFormName = tYPosforLetterOrLegalLandscape; } - - try { - pBaos.write(tFormNameFont); - pBaos.write(sbESC); - pBaos.write('*'); - pBaos.write('p'); - pBaos.write('0'); - pBaos.write('x'); - pBaos.write(String.valueOf(tYPosForFormName).getBytes()); - pBaos.write('Y'); // Cursor position to (x,y) using ESC * p 0 x 123 Y - pBaos.write(pFormName.getBytes()); - pBaos.write(tDefaultCourierFont); - } catch (IOException e) { - PriDebug.releaseln("In PosPrintPages, can't write Form Name into ByteArrayOutputStream"); - } + + // Save the PCL bytes needed to select the font, do (x,y) positioning, put the form name, reset the font to default + try { + pBaos.write(tFormNameFont); + pBaos.write(sbESC); + pBaos.write('*'); + pBaos.write('p'); + pBaos.write('0'); + pBaos.write('x'); + pBaos.write(String.valueOf(tYPosForFormName).getBytes()); + pBaos.write('Y'); // Cursor position to (x,y) using ESC * p 0 x 123 Y + pBaos.write(pFormName.getBytes()); + pBaos.write(tDefaultCourierFont); + } catch (IOException e) { + PriDebug.releaseln("In PosPrintPages, can't write Form Name into ByteArrayOutputStream"); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <doc...@us...> - 2007-08-29 02:21:03
|
Revision: 162 http://openpcl.svn.sourceforge.net/openpcl/?rev=162&view=rev Author: documentsystems Date: 2007-08-28 19:20:53 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Howard Hoagland. Added separate PrinterException try block for mPrinterJob.setPrintService() so it's not in the same try block with mPrinterJob.print() 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-22 00:24:16 UTC (rev 161) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-08-29 02:20:53 UTC (rev 162) @@ -751,10 +751,16 @@ try { // Set the user selected printer on the PrinterJob mPrinterJob.setPrintService(mPrintService); + } catch (PrinterException e) { + PriDebug.releaseln("PrinterException in PosPrintPages image print, mPrinterJob.setPrintService()"); + return false; + } + + try { // Print all the pages mPrinterJob.print(pPrintRequestAttributeSet); } catch (PrinterException e) { - PriDebug.error("PrinterException in PosPrintPages", e); + PriDebug.releaseln("PrinterException in PosPrintPages image print, mPrinterJob.print()"); return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-09-26 00:02:33
|
Revision: 178 http://openpcl.svn.sourceforge.net/openpcl/?rev=178&view=rev Author: documentsystems Date: 2007-09-25 17:02:33 -0700 (Tue, 25 Sep 2007) Log Message: ----------- Howard Hoagland. Changed to use Jim Gabriel's new PCLPrintJob class, which meant to remove the PCL Direct printing and Windows Printing code in PosPrintPages, but keep the building of all the PCL bytes, so that the whole print operation is handled in PCLPrintJob with it's API being the initializePrintJob parameters. Implemented print duplex for Windows Print. Fixed bug when printing two pages, and doing Letter first then Legal, the two pages wouldn't reorder. 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-09-25 23:57:34 UTC (rev 177) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-09-26 00:02:33 UTC (rev 178) @@ -7,17 +7,12 @@ import java.awt.Frame; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Locale; -import javax.print.DocFlavor; -import javax.print.DocPrintJob; -import javax.print.PrintException; import javax.print.PrintService; -import javax.print.SimpleDoc; import javax.print.attribute.DocAttributeSet; import javax.print.attribute.HashDocAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; @@ -50,9 +45,8 @@ private PosView mPosView = null; private Frame mParentFrame = null; - private PosPrintBufferedImage mPosPrintBufferedImage = null; - private PosPrintPageableInterface mPosPrintPageableInterface = null; - private PrinterJob mPrinterJob = null; + private PrinterJob mPrinterJob = null; // This is the SUN JRE java.awt.print.PrinterJob + private PCLPrintJob mPCLPrintJob = null; // This is our own com.openpcl.viewer.printing.PCLPrintJob in this project private PrintRequestAttributeSet mPrintRequestAttributeSet = null; private PrintService mPrintService = null; private PosPrintSetupDialog mPosPrintSetupDialog = null; @@ -69,6 +63,7 @@ public static final int sPageOrientationLandscape = 2; private int mProcessPrintType = 0; private int mNumberOfPagesThatWillPrint = 0; + private int mNumberBlankBackPages = 0; private static final String[] mTitleBarTextForPrintDialog = { "Print All", "Print Selected", "Print Changed", "Print Remaining"}; private PriModifyPclBytes mPriModifyPclBytes = null; @@ -88,13 +83,12 @@ public PosPrintPages(PosView pPosView) { super(); mPosView = pPosView; + mPCLPrintJob = mPosView.getOpenPCLViewer().getPCLPrintJob(); mParentFrame = mPosView.getOpenPCLViewer().getAppFrame(); mPrintRequestAttributeSet = mPosView.getOpenPCLViewer().getPrintRequestAttributeSet(); mPosPrintSetupDialogChoices = mPosView.getOpenPCLViewer().getPosPrintSetupDialogChoices(); mDocAttributeSet = new HashDocAttributeSet(); mDocAttributeSet.add(new DocumentName(mPosView.getOpenPCLViewer().getAppName() + " print", Locale.getDefault())); - mPosPrintBufferedImage = new PosPrintBufferedImage(mPosView); - mPosPrintPageableInterface = new PosPrintPageableInterface(mPosView); mPriModifyPclBytes = new PriModifyPclBytes(); mPrintingProgressBar = new JProgressBar(); mPrintingProgressBar.setStringPainted(true); @@ -112,7 +106,6 @@ mPrintingProgressJDialog.setLayout(new BorderLayout()); mPrintingProgressJDialog.add(tJPanel, BorderLayout.CENTER); mPrintingProgressJDialog.pack(); - mPosPrintBufferedImage.setPrintingProgressBar(mPrintingProgressBar); } /** @@ -319,14 +312,9 @@ // Call the print of the all/selected/remaining/changed pages "N" times depending on Additional Copies field for (int tNumCopies = 1; tNumCopies <= mNumberOfCopies; tNumCopies++) { - // Call "Use Windows Print" or "Print PCL Direct" - if (mPosPrintSetupDialogChoices.isPrintFormatWindowsPrint()) { - mPrintedOkReturn = imagePrint(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, - mPrintingProgressBar, mPrintRequestAttributeSet); - } else { - mPrintedOkReturn = printPclDirect(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, - mPrintingProgressBar, mPrintRequestAttributeSet); - } + // Call to "Print PCL Direct" or to "Windows/Image/GDI Print" + mPrintedOkReturn = printPclDirectOrWindowsPrint(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, + mPrintingProgressBar); } // end "for (int tNumCopies = 1; tNumCopies <= mNumberOfCopies; tNumCopies++)" @@ -337,9 +325,11 @@ public void finished() { mPosView.getOpenPCLViewer().setIsDrawingForPrinting(false); mPosView.getOpenPCLViewer().renderImageCurrentPageAndZoom(); + int tTotalPagesPrinted = mPrintingProgressBar.getMaximum(); + JOptionPane.showMessageDialog(mPrintingProgressJDialog, mPosView.getOpenPCLViewer().getAppName() + "\nFinished printing " + - mPagesToPrintArrayList.size() + " page" + (mPagesToPrintArrayList.size() > 1 ? "s." : "."), + tTotalPagesPrinted + " page" + (tTotalPagesPrinted > 1 ? "s." : "."), "Finished Printing", JOptionPane.INFORMATION_MESSAGE); mPrintingProgressJDialog.setVisible(false); } @@ -362,7 +352,7 @@ } // If there were any Letter size pages that got moved to the "move to bottom" ArrayList - if (tMoveToBottomArrayList.size() > 1) { + if (tMoveToBottomArrayList.size() > 0) { for (PosTreeNode removeThisPosTreeNode : tMoveToBottomArrayList) { // Remove the Letter pages from the passed in ArrayList pPagesToPrintArrayList.remove(removeThisPosTreeNode); @@ -385,7 +375,7 @@ } // If there were any Legal size pages that got moved to the "move to bottom" ArrayList - if (tMoveToBottomArrayList.size() > 1) { + if (tMoveToBottomArrayList.size() > 0) { for (PosTreeNode removeThisPosTreeNode : tMoveToBottomArrayList) { // Remove the Legal pages from the passed in ArrayList pPagesToPrintArrayList.remove(removeThisPosTreeNode); @@ -513,26 +503,20 @@ * @param pPagesToPrintArrayList * @param pPosPrintSetupDialogChoices * @param pPrintingProgressBar - * @param pPrintRequestAttributeSet * @return boolean */ - private boolean printPclDirect(ArrayList<PosTreeNode> pPagesToPrintArrayList, - PosPrintSetupDialogChoices pPosPrintSetupDialogChoices, JProgressBar pPrintingProgressBar, - PrintRequestAttributeSet pPrintRequestAttributeSet) { + private boolean printPclDirectOrWindowsPrint(ArrayList<PosTreeNode> pPagesToPrintArrayList, + PosPrintSetupDialogChoices pPosPrintSetupDialogChoices, JProgressBar pPrintingProgressBar) { - DocFlavor tDocFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE; - SimpleDoc tSimpleDoc = null; - DocPrintJob tDocPrintJob = null; PosTreeNode tPrintThisTreeNode = null; - ByteArrayInputStream tByteArrayInputStream = null; ByteArrayOutputStream tByteArrayOutputStream =null; int tPageNumber = 0; - String tProgressBarBaseString = "Generating page: "; 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'}; - + final byte[] tLetterSizePaperBytes = new byte[] {sbESC, '&', 'l', '2', 'A'}; + final byte[] tLegalSizePaperBytes = new byte[] {sbESC, '&', 'l', '3', 'A'}; + final byte[] tTopMargin3LinesBytes = new byte[] {sbESC, '&', 'l', '3', 'E'}; + mNumberBlankBackPages = 0; + // return if there's no current pages to print if (pPagesToPrintArrayList == null || pPagesToPrintArrayList.size() < 1) { return false; } @@ -596,25 +580,27 @@ 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 + // so FORCE ALL PAGES TO LEGAL SIZE no matter if LTR is in the Blockument DSP values // or if this is a PCL file with a letter size PCL command 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 + // The top margin needs to be set after the paper size change tByteArrayOutputStream.write(tTopMargin3LinesBytes); } - + } else { + // Here for both "Print all on Letter" and for "Print as in original PCL". Keep original paper size works for both. + // The PCLPrintJob print() needs to see the original page size. If Letter, keep letter. If Legal then scale down to Letter. if (mCurrentPagePaperSize.equalsIgnoreCase("LTR")) { // Letter size if ( (mPreviousPagePaperSize == null) || (mPreviousPagePaperSize.equalsIgnoreCase("LGL")) ) { // Only if the previous page was null or Legal, write the Letter size page bytes - tByteArrayOutputStream.write(tLetterlSizePaperBytes); + tByteArrayOutputStream.write(tLetterSizePaperBytes); } 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 + // The top margin needs to be set after the paper size change tByteArrayOutputStream.write(tTopMargin3LinesBytes); } } else { @@ -624,30 +610,33 @@ 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 + // The top margin needs to be set after the paper size change tByteArrayOutputStream.write(tTopMargin3LinesBytes); } } } } catch (IOException e) { + PriDebug.releaseln("Error. Couldn't write page size PCL bytes to ByteArrayOutputStream.\n" + e); return false; } - + // If there were any PCL bytes to include only at print time (not to be viewed on the screen) then write the bytes here byte[] tPrintTimePclBytes = tPrintThisTreeNode.getPrintTimePclBytes(); if (tPrintTimePclBytes != null) { try { tByteArrayOutputStream.write(tPrintTimePclBytes); } catch (IOException e3) { - PriDebug.releaseln("Error. Couldn't write print time only PCL bytes to printer.\n" + e3); + PriDebug.releaseln("Error. Couldn't write print time only PCL bytes to ByteArrayOutputStream.\n" + e3); + return false; } } try { // Write the current page bytes tByteArrayOutputStream.write(tModifiedPclBytes); - } catch (IOException e) { - PriDebug.releaseln("Error. Couldn't write base page PCL bytes to printer.\n" + e); + } catch (IOException e4) { + PriDebug.releaseln("Error. Couldn't write the page PCL bytes to ByteArrayOutputStream.\n" + e4); + return false; } // Write form feed at the end of each page @@ -655,36 +644,66 @@ // 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); - mPrintingProgressBar.setString(tProgressBarBaseString + (tPageNumber + 1) + " of " + pPagesToPrintArrayList.size()); - } } // 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()); - tSimpleDoc = new SimpleDoc(tByteArrayInputStream, tDocFlavor, mDocAttributeSet); - if (tSimpleDoc == null) { return false; } - - if (mPrintService == null) { return false; } + // Set the PrintModeEnum + PCLPrintJob.PrintModeEnum tPrintModeEnum; + if (mPosPrintSetupDialogChoices.isPrintFormatWindowsPrint()) { + tPrintModeEnum = PCLPrintJob.PrintModeEnum.PrintModeGDI; + } else { + tPrintModeEnum = PCLPrintJob.PrintModeEnum.PrintModePCLDirect; + } + + // Set the OutputPageSizeEnum + PCLPrintJob.OutputPageSizeEnum tOutputPageSizeEnum; + if (mPosPrintSetupDialogChoices.isPaperSizePrintAllOnLegal()) { + tOutputPageSizeEnum = PCLPrintJob.OutputPageSizeEnum.OutputPageSizeAllOnLegal; + } else if (mPosPrintSetupDialogChoices.isPaperSizePrintAllOnLetterShrinksLegal()) { + tOutputPageSizeEnum = PCLPrintJob.OutputPageSizeEnum.OutputPageSizeAllOnLetter; + } else { + tOutputPageSizeEnum = PCLPrintJob.OutputPageSizeEnum.OutputPageSizeAsSpecifiedInPCL; + } - tDocPrintJob = mPrintService.createPrintJob(); - if (tDocPrintJob == null) { return false; } - + // Ajust the total number of pages in the Progress bar by the number of blank back pages when duplexing + int tLogicalPageCount = pPrintingProgressBar.getMaximum(); + int tPhysicalPageCount = tLogicalPageCount + mNumberBlankBackPages; + if (mNumberBlankBackPages > 0) { + pPrintingProgressBar.setMaximum(tPhysicalPageCount); + } + + // Set the print job name + String tPrintJobName = mPosView.getOpenPCLViewer().getAppName() + // Could be name of a subclass plugin app + " " + mPosView.getShortName() + ", " + tPhysicalPageCount + " page" + (tPhysicalPageCount == 1 ? "." : "s."); + + // Set the user selected printer from the custom print options dialog on the mPrintService which is + // passed in the below PCLPrintJob.initializePrintJob() try { - tDocPrintJob.print(tSimpleDoc, pPrintRequestAttributeSet); - } catch (PrintException e) { - PriDebug.error("In PosPrintPages, PrintException trying to print PCL Direct.", e); + mPrinterJob.setPrintService(mPrintService); + } catch (PrinterException ePrintService) { + PriDebug.releaseln("PrinterException PosPrintPages calling mPrinterJob.setPrintService()"); return false; } + // Initialize the PCLPrintJob + mPCLPrintJob.initializePrintJob(tPrintModeEnum, tOutputPageSizeEnum, tPrintJobName, + tByteArrayOutputStream.toByteArray(), mPrinterJob); + + // Set the JProgressBar in the PCLPrintJob + mPCLPrintJob.setPrintingProgressBar(pPrintingProgressBar); + + // Kick off the actual printing on paper + try { + mPrinterJob.print(mPCLPrintJob.getPrintRequestAttributeSet()); + } catch (PrinterException ex) { + // The job did not successfully complete + PriDebug.releaseln("PrinterException in PosPrintPages calling mPrinterJob.print()"); + return false; + } + // The pages printed out return true; } @@ -701,6 +720,7 @@ // Write an extra form feed here, and say the next page is going to print on the back pByteArrayOutputStream.write(sbFF); + mNumberBlankBackPages++; mDuplexModePaperSide = DUPLEX_MODE_NEXTPAGE_ONBACK; } else { @@ -713,59 +733,4 @@ } } - - /** - * Image print (instead of PCL Direct) - * @author Howard 6/1/06. Implemented mult page printing on 8/24/06 - * @param pPagesToPrintArrayList - * @param pPosPrintSetupDialogChoices - * @param pPrintingProgressBar - * @param pPrintRequestAttributeSet - * @return boolean - */ - private boolean imagePrint(ArrayList<PosTreeNode> pPagesToPrintArrayList, - PosPrintSetupDialogChoices pPosPrintSetupDialogChoices, JProgressBar pPrintingProgressBar, - PrintRequestAttributeSet pPrintRequestAttributeSet) { - // Set the pages to print so that when PrinterJob calls Printable.print(), it uses the PosTreeNode values - // that are the Objects in this ArrayList, to do Graphics draw commands from the PCL to render the image - mPosPrintBufferedImage.setPagesToPrint(pPagesToPrintArrayList); - - // Set the Print Setup choices object on the Printable Interface object - mPosPrintBufferedImage.setPosPrintSetupDialogChoices(pPosPrintSetupDialogChoices); - - // The below PosPrintBufferedImage implements the java.awt.print.Printable interface - // which has the interface required method: int print(Graphics g, PageFormat format, int pageNumber) - mPosPrintPageableInterface.setPrintable(mPosPrintBufferedImage); - - // Also pass the print ArrayList to the Pageable interface object for it to return the number of pages - // and more importantly to return the PageFormat for each page that has Letter or Legal for each page - mPosPrintPageableInterface.setPagesToPrint(pPagesToPrintArrayList); - - // Set the Print Setup choices object on the Pageable Interface object - mPosPrintPageableInterface.setPosPrintSetupDialogChoices(pPosPrintSetupDialogChoices); - - // Set the Pageable Interface object on the PrinterJob. - // Note that this Pageable Interface object has the Printable Interface object set in it from above - mPrinterJob.setPageable(mPosPrintPageableInterface); - - try { - // Set the user selected printer on the PrinterJob - mPrinterJob.setPrintService(mPrintService); - } catch (PrinterException e) { - PriDebug.releaseln("PrinterException in PosPrintPages image print, mPrinterJob.setPrintService()"); - return false; - } - - try { - // Print all the pages - mPrinterJob.print(pPrintRequestAttributeSet); - } catch (PrinterException e) { - PriDebug.releaseln("PrinterException in PosPrintPages image print, mPrinterJob.print()"); - return false; - } - - // The page printed out - return true; - } - -} +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |