* match the paper and then we shift the BufferedImage
* so that it covers the area on the page where the
* caller's Image will be drawn.
*/
Graphics2D g = deepImage.createGraphics();
ProxyGraphics2D proxy = new ProxyGraphics2D(g, wPrinterJob);
proxy.setColor(Color.white);
proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
proxy.translate(-region.getX(), -region.getY());
/* Calculate the resolution of the source image.
*/
float sourceResX = (float)(wPrinterJob.getXRes() / scaleX);
float sourceResY = (float)(wPrinterJob.getYRes() / scaleY);
/* The application expects to see user space at 72 dpi.
* so change user space from image source resolution to
* 72 dpi.
*/
proxy.scale(sourceResX / DEFAULT_USER_RES,
sourceResY / DEFAULT_USER_RES);
proxy.translate(
-wPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
/ wPrinterJob.getXRes() * DEFAULT_USER_RES,
-wPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
/ wPrinterJob.getYRes() * DEFAULT_USER_RES);
/* NB User space now has to be at 72 dpi for this calc to be correct */
proxy.transform(new AffineTransform(getPageFormat().getMatrix()));
proxy.setPaint(Color.black);
painter.print(proxy, pageFormat, pageIndex);
g.dispose();