6804454: RFE: Provide a way to control the printing dpi resolution from MSIE browser print. See also 6801859
authorjgodinez
Fri, 15 Oct 2010 11:20:31 -0700
changeset 6817 891cb6583a06
parent 6816 6c2a27114265
child 6818 feb638afc792
6804454: RFE: Provide a way to control the printing dpi resolution from MSIE browser print. See also 6801859 Reviewed-by: igor, prr
jdk/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java
--- a/jdk/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java	Fri Oct 15 12:02:06 2010 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WEmbeddedFrame.java	Fri Oct 15 11:20:31 2010 -0700
@@ -33,6 +33,7 @@
 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 @@
     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 @@
          * real resolution of the destination so
          */
         if (isPrinterDC(hdc)) {
-            xscale = 4;
-            yscale = 4;
+            xscale = yscale = getPrintScaleFactor();
         }
 
         int frameHeight = getHeight();
@@ -168,6 +172,37 @@
         }
     }
 
+    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,