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