From 9a03f735c579350af39ed83a41da34152938bb4e Mon Sep 17 00:00:00 2001 From: jgodinez Date: Fri, 15 Oct 2010 11:20:31 -0700 Subject: [PATCH] 6804454: RFE: Provide a way to control the printing dpi resolution from MSIE browser print. See also 6801859 Reviewed-by: igor, prr --- .../sun/awt/windows/WEmbeddedFrame.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java b/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java index 18489f91d..a0d29aba1 100644 --- a/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java +++ b/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java @@ -33,6 +33,7 @@ import java.util.*; import java.awt.color.*; import java.awt.image.*; import sun.awt.image.ByteInterleavedRaster; +import sun.security.action.GetPropertyAction; import java.lang.reflect.*; public class WEmbeddedFrame extends EmbeddedFrame { @@ -48,8 +49,12 @@ public class WEmbeddedFrame extends EmbeddedFrame { private int imgWid = 0; private int imgHgt = 0; + private static int pScale = 0; private static final int MAX_BAND_SIZE = (1024*30); + private static String printScale = (String) java.security.AccessController + .doPrivileged(new GetPropertyAction("sun.java2d.print.pluginscalefactor")); + public WEmbeddedFrame() { this((long)0); } @@ -114,8 +119,7 @@ public class WEmbeddedFrame extends EmbeddedFrame { * real resolution of the destination so */ if (isPrinterDC(hdc)) { - xscale = 4; - yscale = 4; + xscale = yscale = getPrintScaleFactor(); } int frameHeight = getHeight(); @@ -168,6 +172,37 @@ public class WEmbeddedFrame extends EmbeddedFrame { } } + protected static int getPrintScaleFactor() { + // check if value is already cached + if (pScale != 0) + return pScale; + if (printScale == null) { + // if no system property is specified, + // check for environment setting + printScale = (String) java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Object run() { + return System.getenv("JAVA2D_PLUGIN_PRINT_SCALE"); + } + } + ); + } + int default_printDC_scale = 4; + int scale = default_printDC_scale; + if (printScale != null) { + try { + scale = Integer.parseInt(printScale); + if (scale > 8 || scale < 1) { + scale = default_printDC_scale; + } + } catch (NumberFormatException nfe) { + } + } + pScale = scale; + return pScale; + } + + protected native boolean isPrinterDC(long hdc); protected native void printBand(long hdc, byte[] data, int offset, -- GitLab