< prev index next >

src/java.desktop/share/classes/sun/java2d/SunGraphicsEnvironment.java

Print this page

        

@@ -64,10 +64,12 @@
 import sun.font.Font2D;
 import sun.font.FontManager;
 import sun.font.FontManagerFactory;
 import sun.font.FontManagerForSGE;
 import sun.font.NativeFont;
+import java.security.AccessController;
+import sun.security.action.GetPropertyAction;
 
 /**
  * This is an implementation of a GraphicsEnvironment object for the
  * default local GraphicsEnvironment.
  *

@@ -78,10 +80,19 @@
     implements DisplayChangedListener {
 
     public static boolean isOpenSolaris;
     private static Font defaultFont;
 
+    private static final boolean uiScaleEnabled;
+    private static final double debugScale;
+
+    static {
+        uiScaleEnabled = "true".equals(AccessController.doPrivileged(
+                new GetPropertyAction("sun.java2d.uiScale.enabled", "true")));
+        debugScale = uiScaleEnabled ? getScaleFactor("sun.java2d.uiScale") : -1;
+    }
+
     public SunGraphicsEnvironment() {
         java.security.AccessController.doPrivileged(
                                     new java.security.PrivilegedAction<Object>() {
             public Object run() {
                 String osName = System.getProperty("os.name");

@@ -339,6 +350,45 @@
      * @return true if flip strategy should be used, false otherwise
      */
     public boolean isFlipStrategyPreferred(ComponentPeer peer) {
         return false;
     }
+
+    public static boolean isUIScaleEnabled() {
+        return uiScaleEnabled;
+    }
+
+    public static double getDebugScale() {
+        return debugScale;
+    }
+
+    public static double getScaleFactor(String propertyName) {
+
+        String scaleFactor = AccessController.doPrivileged(
+                new GetPropertyAction(propertyName, "-1"));
+
+        if (scaleFactor == null || scaleFactor.equals("-1")) {
+            return -1;
+        }
+
+        try {
+
+            if (scaleFactor.endsWith("dpi")) {
+                scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3);
+                double scale = Double.parseDouble(scaleFactor);
+                return scale <= 0 ? -1 : scale / 96;
+            }
+
+            if (scaleFactor.endsWith("%")) {
+                scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
+                double scale = Double.parseDouble(scaleFactor);
+                return scale <= 0 ? -1 : scale / 100;
+            }
+
+            double scale = Double.parseDouble(scaleFactor);
+            return (scale <= 0) ? -1 : scale;
+
+        } catch (NumberFormatException ignoread) {
+        }
+        return -1;
+    }
 }
< prev index next >