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