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. |