From: <doc...@us...> - 2007-06-15 01:37:32
|
Revision: 88 http://openpcl.svn.sourceforge.net/openpcl/?rev=88&view=rev Author: documentsystems Date: 2007-06-14 18:32:36 -0700 (Thu, 14 Jun 2007) Log Message: ----------- Howard Hoagland. Converted the full color BufferedImage bitmap of the printed image to a 2 color black and white only BufferedImage before drawing on the Graphics2D in Java Printing. This makes the printing go faster because the print image in the print queue is 1.28MB per print page instead of 10MB per print page. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-06-14 22:46:28 UTC (rev 87) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-06-15 01:32:36 UTC (rev 88) @@ -1,6 +1,7 @@ package com.openpcl.viewer.printing; import java.awt.Color; +import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; @@ -17,6 +18,7 @@ import javax.swing.JOptionPane; import javax.swing.JProgressBar; +import com.openpcl.pclrenderimage.render.PriPageSettings; import com.openpcl.viewer.panels.PosView; import com.openpcl.viewer.tree.PosTreeNode; @@ -24,19 +26,28 @@ private static final long serialVersionUID = 1L; private PosView mPosView = null; private BufferedImage mPrintThisBufferedImage = null; + private BufferedImage mBufferedImageToPrintOn = null; + private Graphics2D mGraphics2DToPrintOn = null; + private Frame mParentFrame = null; + private PosTreeNode mPrintThisTreeNode = null; private AffineTransform mOrigAffineTransform = null; private AffineTransform mScaleAffineTransform = null; private ArrayList<PosTreeNode> mPagesToPrintArrayList = null; private PosPrintSetupDialogChoices mPosPrintSetupDialogChoices = null; private JProgressBar mPrintingProgressBar = null; - private static final String mProgressBarBaseString = "Generating page: "; + private static final String sProgressBarBaseString = "Generating page: "; + private static final String sCantAllocate = "Can't allocate memory for temporary image used for printing."; private double mPrintScale = 72.0d / 300.0d; // making width and height using 72 / 300 scale public PosPrintBufferedImage(PosView pPosView) { super(); mPosView = pPosView; + mParentFrame = mPosView.getOpenPCLViewer().getAppFrame(); mScaleAffineTransform = AffineTransform.getScaleInstance(mPrintScale, mPrintScale); + mBufferedImageToPrintOn = createNewBufferedImageToPrintOn(); + // Graphics2D for printing (is 2 color black and white with no rendering hints like anti-aliasing + if (mBufferedImageToPrintOn != null) { mGraphics2DToPrintOn = mBufferedImageToPrintOn.createGraphics(); } } public void setPagesToPrint(ArrayList<PosTreeNode> pPagesToPrintArrayList) { @@ -90,9 +101,12 @@ // methods specified in the interface IPluginHooksOpenPCL mPrintThisBufferedImage = mPosView.getOpenPCLViewer().renderImageForPrintingFromTreeNode(mPrintThisTreeNode); - // Draw the screen image on the printer Graphics2D using the scale down transform - g2D.drawImage(mPrintThisBufferedImage, 0, 0, Color.WHITE, this); + // Convert to 2 color black and white so the print image file sent to the printer is 1.3MB per print page instead of 10MB + mGraphics2DToPrintOn.drawImage(mPrintThisBufferedImage, 0, 0, this); + // Draw the image on the printer Graphics2D using the scale down transform + g2D.drawImage(mBufferedImageToPrintOn, 0, 0, this); + // Revert back to the passed in AffineTransform because the JDK doc for printing says put back the // passed in Graphics object's settings back if you modified it in this print() interface call g2D.transform(mOrigAffineTransform); @@ -100,7 +114,7 @@ // Update the progress bar at each page if (mPrintingProgressBar != null) { mPrintingProgressBar.setValue(pPageNumber + 1); - mPrintingProgressBar.setString(mProgressBarBaseString + (pPageNumber + 1) + " of " + mPagesToPrintArrayList.size()); + mPrintingProgressBar.setString(sProgressBarBaseString + (pPageNumber + 1) + " of " + mPagesToPrintArrayList.size()); } return Printable.PAGE_EXISTS; @@ -138,4 +152,43 @@ } } + /** + * Create a new BufferredImage all ready to print on + * @return BufferedImage + */ + protected BufferedImage createNewBufferedImageToPrintOn() { + BufferedImage tToPrintOnBufferedImage = null; + try { + tToPrintOnBufferedImage = new BufferedImage( + PriPageSettings.sNumPixels85Inches, // make the BufferedImage be 8.5 inches by 14 inches + PriPageSettings.sNumPixels14Inches, + BufferedImage.TYPE_BYTE_BINARY); // 2 color only image is black and white (not full color) for printing not on screen + } catch (OutOfMemoryError e1) { + tToPrintOnBufferedImage = null; + JOptionPane.showMessageDialog(mParentFrame, "Out of heap space memory. " + sCantAllocate , "Heap space memory", + JOptionPane.ERROR_MESSAGE); + + } catch (Error e2) { + tToPrintOnBufferedImage = null; + JOptionPane.showMessageDialog(mParentFrame, "Error. " + sCantAllocate , "Error", + JOptionPane.ERROR_MESSAGE); + + } catch (Exception e3) { + tToPrintOnBufferedImage = null; + JOptionPane.showMessageDialog(mParentFrame, "Exception. " + sCantAllocate , "Exception", + JOptionPane.ERROR_MESSAGE); + } + return tToPrintOnBufferedImage; + } + + /** Blank out the BufferedImage on the screen of the current selected view. */ + public void blankOutBufferedImageToPrintOn() { + if (mBufferedImageToPrintOn != null && mGraphics2DToPrintOn != null) { + mGraphics2DToPrintOn.setPaint(Color.WHITE); + // The blank out is done by drawing a white rectangle on the whole image + mGraphics2DToPrintOn.fillRect(0, 0, mBufferedImageToPrintOn.getWidth(), mBufferedImageToPrintOn.getHeight()); + // Make the initial color for drawing text and rectangles and pixels be in black. Can be set to another color like blue later + mGraphics2DToPrintOn.setPaint(Color.BLACK); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-07-16 22:12:43
|
Revision: 107 http://openpcl.svn.sourceforge.net/openpcl/?rev=107&view=rev Author: documentsystems Date: 2007-07-16 14:39:24 -0700 (Mon, 16 Jul 2007) Log Message: ----------- Howard Hoagland. Made the call to setRenderingHints(g2D) be conditional. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-07-16 21:38:20 UTC (rev 106) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-07-16 21:39:24 UTC (rev 107) @@ -41,6 +41,7 @@ private static final String sCantAllocate = "Can't allocate memory for temporary image used for printing."; private double mPrintScale = 72.0d / 300.0d; // making width and height using 72 / 300 scale private double mShrinkLegalToLetterScale = mPrintScale * (11.0d / 14.0d); // shrink in both directions height 14" to 11" + private boolean mShouldSetRendingHints = false; // Printing looks the same on paper if rending hints are set or not public PosPrintBufferedImage(PosView pPosView) { super(); @@ -89,7 +90,7 @@ // Cast passed in Graphics to Graphics2D Graphics2D g2D = (Graphics2D)pGraphics; // Set rendering hints - setRenderingHints(g2D); + if (mShouldSetRendingHints) { setRenderingHints(g2D); } // Set background color white g2D.setBackground(Color.WHITE); // Make drawing text and rectangles and pixels be in black This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <doc...@us...> - 2007-08-17 19:11:08
|
Revision: 147 http://openpcl.svn.sourceforge.net/openpcl/?rev=147&view=rev Author: documentsystems Date: 2007-08-17 12:11:04 -0700 (Fri, 17 Aug 2007) Log Message: ----------- Howard Hoagland. Added code to center the page image horizontally when the user clicked on "Print all on Letter (shrinks Legal)" for the Legal pages to look centered after they've been shrunk to fit on Letter paper. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-08-17 19:08:07 UTC (rev 146) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-08-17 19:11:04 UTC (rev 147) @@ -29,7 +29,6 @@ private BufferedImage mBufferedImageToPrintOn = null; private Graphics2D mGraphics2DToPrintOn = null; private Frame mParentFrame = null; - private PosTreeNode mPrintThisTreeNode = null; private AffineTransform mOrigAffineTransform = null; private AffineTransform mScaleAffineTransform = null; @@ -40,7 +39,14 @@ private static final String sProgressBarBaseString = "Generating page: "; private static final String sCantAllocate = "Can't allocate memory for temporary image used for printing."; private double mPrintScale = 72.0d / 300.0d; // making width and height using 72 / 300 scale - private double mShrinkLegalToLetterScale = mPrintScale * (11.0d / 14.0d); // shrink in both directions height 14" to 11" + private double mPageWidthPixels = 8.5 * 300; + private double mShrinkLegalToLetterRatio = (11.0d / 14.0d); // shrink in both directions height 14" to 11" + private double mShrinkLegalToLetterScale = mPrintScale * mShrinkLegalToLetterRatio; + private double mShrinkLegalToLetterMargins = 0.27 * 300; + + private double mXOffsetForCenteringShrinkLegalOnLetter = + ((mPageWidthPixels - (mPageWidthPixels * mShrinkLegalToLetterRatio)) / 2) + mShrinkLegalToLetterMargins; + private boolean mShouldSetRendingHints = false; // Printing looks the same on paper if rending hints are set or not public PosPrintBufferedImage(PosView pPosView) { @@ -67,14 +73,12 @@ mPrintingProgressBar = pPrintingProgressBar; } - public int print(Graphics pGraphics, PageFormat pPageFormat, int pPageNumber) throws PrinterException { // return if there's no current pages to print if (mPagesToPrintArrayList == null || mPagesToPrintArrayList.size() < 1) { return Printable.NO_SUCH_PAGE; } // return if the passed in page number is less than 0 or greater than the number of current pages to print if (pPageNumber < 0 || pPageNumber >= mPagesToPrintArrayList.size()) { return Printable.NO_SUCH_PAGE; } // Get the tree node user object for this print page by indexing into the print ArrayList to get the passed in page number - try { mPrintThisTreeNode = mPagesToPrintArrayList.get(pPageNumber); } catch (IndexOutOfBoundsException e) { @@ -102,6 +106,7 @@ ( !(mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(mPrintThisTreeNode)) )) { // The user has clicked the "Print all on Letter paper (shrinks Legal)" radio button so shrink Legal to fit on Letter g2D.transform(mShrinkLegalToLetterAffineTransform); + g2D.translate(mXOffsetForCenteringShrinkLegalOnLetter, 0.0d); } else { // Set the 72/300 = .24 AffineTransform on the current Graphics2D, to scale smaller to fit exactly on the printed page @@ -203,4 +208,71 @@ mGraphics2DToPrintOn.setPaint(Color.BLACK); } } + + // Below is debugging code that is commented out. + +// import java.awt.GraphicsConfiguration; +// import java.awt.PrintGraphics; +// import java.awt.PrintJob; +// import java.awt.Rectangle; +// import java.awt.image.ColorModel; +// import java.awt.print.PrinterJob; +// import javax.print.DocPrintJob; +// import javax.print.PrintService; +// import javax.print.attribute.Attribute; +// import javax.print.attribute.PrintJobAttributeSet; +// import javax.print.attribute.PrintServiceAttributeSet; +// import javax.print.attribute.standard.PrinterResolution; +// import sun.awt.windows.WPrinterJob; +// import sun.print.Win32PrintService; + +// private PrinterJob mPrinterJob = null; +// private DocPrintJob mDocPrintJob = null; + +// public void setPrinterJob(PrinterJob pPrinterJob) { +// mPrinterJob = pPrinterJob; +// mDocPrintJob = pPrinterJob.getPrintService().createPrintJob(); +// } + + //GraphicsConfiguration tGc = g2D.getDeviceConfiguration(); +//ColorModel tColorModel = tGc.getColorModel(); + +// Rectangle tClipBoundsRect = g2D.getClipBounds(); +// System.out.println("Printing Graphics2D clip ( cx, cy, cw ch) = (" + +// tClipBoundsRect.x + ", " + tClipBoundsRect.y + ", " + tClipBoundsRect.width + ", " + tClipBoundsRect.height + ")"); +// +// System.out.println("PageFormat is (w, h, imX, imY, imW, imH) is (" + +// pPageFormat.getWidth() + ", " + pPageFormat.getHeight() + ", " + +// pPageFormat.getImageableX() + ", " + pPageFormat.getImageableY() + ", " + +// pPageFormat.getImageableWidth() + ", " + pPageFormat.getImageableHeight() + ")" +// ); + +//PrintJob tPj = null; +//if (pGraphics instanceof PrintGraphics) { +// tPj = ((PrintGraphics) pGraphics).getPrintJob(); +//} + +//PrintJob tPrintJob = getToolkit().getPrintJob(mPosView.getOpenPCLViewer().getAppFrame(), "Print Test", null); + +// PrintService tPs = mPrinterJob.getPrintService(); +// DocPrintJob tDpj = tPs.createPrintJob(); +// PrintJobAttributeSet tPjas = tDpj.getAttributes(); +// Attribute tAtt = tPjas.get(PrinterResolution.class); +// if (tAtt instanceof PrinterResolution) { +// PrinterResolution tPrinterResolution = (PrinterResolution) tAtt; +// System.out.println("Printer resolution is set at: " + tPrinterResolution.getCrossFeedResolution(PrinterResolution.DPI) + +// ", " + tPrinterResolution.getFeedResolution(PrinterResolution.DPI) + ")" ); +// } + +// if (mPrinterJob instanceof WPrinterJob) { +// WPrinterJob tWpj = (WPrinterJob) mPrinterJob; +// tWpj.setResolutionDPI(600, 600); +// } + +// PrintService tPs = mPrinterJob.getPrintService(); +// if (tPs instanceof Win32PrintService) { +// Win32PrintService tW32Ps = (Win32PrintService) tPs; +// PrintServiceAttributeSet tPsas = tW32Ps.getAttributes(); +// System.out.println(tPsas); +// } } 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:27:35
|
Revision: 163 http://openpcl.svn.sourceforge.net/openpcl/?rev=163&view=rev Author: documentsystems Date: 2007-08-28 19:26:53 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Howard Hoagland. 1. Get the dpi that the print driver of the selected printer picked (examples 300 or 600 or 1200 dpi). 2. Added comment line for centering Legal image on Letter paper. 3. For Legal image on Legal paper (not forcing paper change), bumped the image to the right slightly so that the vertical lines on the left edge of the image won't be chopped off on the left. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-08-29 02:20:53 UTC (rev 162) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintBufferedImage.java 2007-08-29 02:26:53 UTC (rev 163) @@ -38,16 +38,15 @@ private JProgressBar mPrintingProgressBar = null; private static final String sProgressBarBaseString = "Generating page: "; private static final String sCantAllocate = "Can't allocate memory for temporary image used for printing."; + private boolean mShouldSetRendingHints = false; // Printing looks the same on paper if rending hints are set or not private double mPrintScale = 72.0d / 300.0d; // making width and height using 72 / 300 scale private double mPageWidthPixels = 8.5 * 300; private double mShrinkLegalToLetterRatio = (11.0d / 14.0d); // shrink in both directions height 14" to 11" private double mShrinkLegalToLetterScale = mPrintScale * mShrinkLegalToLetterRatio; - private double mShrinkLegalToLetterMargins = 0.27 * 300; - + private double mShrinkLegalToLetterMargins = 0.27d * 300.0d; private double mXOffsetForCenteringShrinkLegalOnLetter = ((mPageWidthPixels - (mPageWidthPixels * mShrinkLegalToLetterRatio)) / 2) + mShrinkLegalToLetterMargins; - private boolean mShouldSetRendingHints = false; // Printing looks the same on paper if rending hints are set or not public PosPrintBufferedImage(PosView pPosView) { super(); @@ -101,16 +100,24 @@ g2D.setPaint(Color.BLACK); // Save the passed in AffineTransform (to put it back before returning) mOrigAffineTransform = g2D.getTransform(); + // The below is the resolution that the selected printer's print driver set, + // and will be 4.1667 on a 300dpi printer, or 8.333 on a 600dpi printer. + // The below 2 lines would help debugging any future problems if different printer resolutions print too small or too big. + // long tDpiSetByPrintDriver = Math.round( mOrigAffineTransform.getScaleX() * 72); + // System.out.println("The print driver selected dpi is " + tDpiSetByPrintDriver ); if (mPosPrintSetupDialogChoices.isPaperSizePrintAllOnLetterShrinksLegal() && ( !(mPosView.getOpenPCLViewer().isTreeNodePageLetterSize(mPrintThisTreeNode)) )) { // The user has clicked the "Print all on Letter paper (shrinks Legal)" radio button so shrink Legal to fit on Letter g2D.transform(mShrinkLegalToLetterAffineTransform); + // Center the Legal image on the Letter page size buy bumping to the right half the available horizontal space g2D.translate(mXOffsetForCenteringShrinkLegalOnLetter, 0.0d); } else { // Set the 72/300 = .24 AffineTransform on the current Graphics2D, to scale smaller to fit exactly on the printed page g2D.transform(mScaleAffineTransform); + // So that the vertical lines at the very left edge aren't chopped off, need to bump the whole image 4 pixels to the right + g2D.translate(4.0d, 0.0d); } // Make the BufferedImage from the tree node. @@ -222,18 +229,32 @@ // import javax.print.attribute.Attribute; // import javax.print.attribute.PrintJobAttributeSet; // import javax.print.attribute.PrintServiceAttributeSet; +// import javax.print.attribute.standard.PrinterMakeAndModel; +// import javax.print.attribute.standard.PrinterName; // import javax.print.attribute.standard.PrinterResolution; // import sun.awt.windows.WPrinterJob; // import sun.print.Win32PrintService; // private PrinterJob mPrinterJob = null; // private DocPrintJob mDocPrintJob = null; +// private PrintService mPrintService = null; // public void setPrinterJob(PrinterJob pPrinterJob) { // mPrinterJob = pPrinterJob; // mDocPrintJob = pPrinterJob.getPrintService().createPrintJob(); // } +// public void setPrintService(PrintService pPrintService) { +// mPrintService = pPrintService; +// } + +// PrintServiceAttributeSet tPas = mPrintService.getAttributes(); +// Attribute tPname = tPas.get(PrinterName.class); // works Ok. It returns the PrinterName that the user can change. +// Attribute tPmm = tPas.get(PrinterMakeAndModel.class); // returns null but shouldn't http://bugs.sun.com/view_bug.do?bug_id=4673400 +// System.out.println("Number of print service attributes: " + tPas.size()); +// System.out.println("Printer name: " + tPname ); +// System.out.println("PrinterMakeAndModel: " + tPmm); + //GraphicsConfiguration tGc = g2D.getDeviceConfiguration(); //ColorModel tColorModel = tGc.getColorModel(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |