< prev index next >

src/java.desktop/share/classes/sun/font/SunFontManager.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -48,11 +48,11 @@
 import java.util.TreeMap;
 import java.util.Vector;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.swing.plaf.FontUIResource;
-import sun.awt.AppContext;
+
 import sun.awt.FontConfiguration;
 import sun.awt.SunToolkit;
 import sun.awt.util.ThreadGroupUtils;
 import sun.java2d.FontSupport;
 import sun.util.logging.PlatformLogger;

@@ -254,15 +254,10 @@
 
     public FilenameFilter getType1Filter() {
         return t1Filter;
     }
 
-    @Override
-    public boolean usingPerAppContextComposites() {
-        return _usingPerAppContextComposites;
-    }
-
     static {
 
         java.security.AccessController.doPrivileged(
                                     new java.security.PrivilegedAction<Object>() {
 

@@ -1934,31 +1929,18 @@
      * may be able to emulate the required style.
      */
     public Font2D findFont2D(String name, int style, int fallback) {
         String lowerCaseName = name.toLowerCase(Locale.ENGLISH);
         String mapName = lowerCaseName + dotStyleStr(style);
-        Font2D font;
 
         /* If preferLocaleFonts() or preferProportionalFonts() has been
          * called we may be using an alternate set of composite fonts in this
          * app context. The presence of a pre-built name map indicates whether
          * this is so, and gives access to the alternate composite for the
          * name.
          */
-        if (_usingPerAppContextComposites) {
-            @SuppressWarnings("unchecked")
-            ConcurrentHashMap<String, Font2D> altNameCache =
-                (ConcurrentHashMap<String, Font2D>)
-                AppContext.getAppContext().get(CompositeFont.class);
-            if (altNameCache != null) {
-                font = altNameCache.get(mapName);
-            } else {
-                font = null;
-            }
-        } else {
-            font = fontNameCache.get(mapName);
-        }
+        Font2D font = fontNameCache.get(mapName);
         if (font != null) {
             return font;
         }
 
         if (FontUtilities.isLogging()) {

@@ -2159,29 +2141,13 @@
          * We do not add these fonts to fontNameCache for the
          * app context case which eliminates the overhead of a per context
          * cache for these.
          */
 
-        if (fontsAreRegistered || fontsAreRegisteredPerAppContext) {
-            Hashtable<String, FontFamily> familyTable = null;
-            Hashtable<String, Font2D> nameTable;
-
             if (fontsAreRegistered) {
-                familyTable = createdByFamilyName;
-                nameTable = createdByFullName;
-            } else {
-                AppContext appContext = AppContext.getAppContext();
-                @SuppressWarnings("unchecked")
-                Hashtable<String,FontFamily> tmp1 =
-                    (Hashtable<String,FontFamily>)appContext.get(regFamilyKey);
-                familyTable = tmp1;
-
-                @SuppressWarnings("unchecked")
-                Hashtable<String, Font2D> tmp2 =
-                    (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
-                nameTable = tmp2;
-            }
+            Hashtable<String, FontFamily> familyTable = createdByFamilyName;
+            Hashtable<String, Font2D> nameTable = createdByFullName;
 
             family = familyTable.get(lowerCaseName);
             if (family != null) {
                 font = family.getFontWithExactStyleMatch(style);
                 if (font == null) {

@@ -2682,13 +2648,10 @@
      * return an AppContext specific list.
      *
      * Calling the methods below is "heavyweight" but it is expected that
      * these methods will be called very rarely.
      *
-     * If _usingPerAppContextComposites is true, we are in "applet"
-     * (eg browser) environment and at least one context has selected
-     * an alternate composite font behaviour.
      * If _usingAlternateComposites is true, we are not in an "applet"
      * environment and the (single) application has selected
      * an alternate composite font behaviour.
      *
      * - Printing: The implementation delegates logical fonts to an AWT

@@ -2696,25 +2659,17 @@
      * We can detect that alternate fonts are in use and back-off to 2D, but
      * that uses outlines. Much of this can be fixed with additional work
      * but that may have to wait. The results should be correct, just not
      * optimal.
      */
-    private static final Object altJAFontKey       = new Object();
-    private static final Object localeFontKey       = new Object();
-    private static final Object proportionalFontKey = new Object();
-    private boolean _usingPerAppContextComposites = false;
     private boolean _usingAlternateComposites = false;
 
-    /* These values are used only if we are running as a standalone
-     * application, as determined by maybeMultiAppContext();
-     */
     private static boolean gAltJAFont = false;
     private boolean gLocalePref = false;
     private boolean gPropPref = false;
 
-    /* This method doesn't check if alternates are selected in this app
-     * context. Its used by the FontMetrics caching code which in such
+    /* Its used by the FontMetrics caching code which in such
      * a case cannot retrieve a cached metrics solely on the basis of
      * the Font.equals() method since it needs to also check if the Font2D
      * is the same.
      * We also use non-standard composites for Swing native L&F fonts on
      * Windows. In that case the policy is that the metrics reported are

@@ -2722,30 +2677,12 @@
      * visible java.awt.Font. So in that case the metrics cache which tests
      * the Font does what we want. In the near future when we expand the GTK
      * logical font definitions we may need to revisit this if GTK reports
      * combined metrics instead. For now though this test can be simple.
      */
-    public boolean maybeUsingAlternateCompositeFonts() {
-       return _usingAlternateComposites || _usingPerAppContextComposites;
-    }
-
     public boolean usingAlternateCompositeFonts() {
-        return (_usingAlternateComposites ||
-                (_usingPerAppContextComposites &&
-                AppContext.getAppContext().get(CompositeFont.class) != null));
-    }
-
-    private static boolean maybeMultiAppContext() {
-        Boolean appletSM = (Boolean)
-            java.security.AccessController.doPrivileged(
-                new java.security.PrivilegedAction<Object>() {
-                        public Object run() {
-                            SecurityManager sm = System.getSecurityManager();
-                            return sm instanceof sun.awt.AWTSecurityManager;
-                        }
-                    });
-        return appletSM.booleanValue();
+        return _usingAlternateComposites;
     }
 
     /* Modifies the behaviour of a subsequent call to preferLocaleFonts()
      * to use Mincho instead of Gothic for dialoginput in JA locales
      * on windows. Not needed on other platforms.

@@ -2756,59 +2693,31 @@
                 .info("Entered useAlternateFontforJALocales().");
         }
         if (!FontUtilities.isWindows) {
             return;
         }
-
-        if (!maybeMultiAppContext()) {
             gAltJAFont = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            appContext.put(altJAFontKey, altJAFontKey);
-        }
     }
 
     public boolean usingAlternateFontforJALocales() {
-        if (!maybeMultiAppContext()) {
             return gAltJAFont;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            return appContext.get(altJAFontKey) == altJAFontKey;
-        }
     }
 
     public synchronized void preferLocaleFonts() {
         if (FontUtilities.isLogging()) {
             FontUtilities.getLogger().info("Entered preferLocaleFonts().");
         }
         /* Test if re-ordering will have any effect */
         if (!FontConfiguration.willReorderForStartupLocale()) {
             return;
         }
-
-        if (!maybeMultiAppContext()) {
             if (gLocalePref == true) {
                 return;
             }
             gLocalePref = true;
             createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
             _usingAlternateComposites = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            if (appContext.get(localeFontKey) == localeFontKey) {
-                return;
-            }
-            appContext.put(localeFontKey, localeFontKey);
-            boolean acPropPref =
-                appContext.get(proportionalFontKey) == proportionalFontKey;
-            ConcurrentHashMap<String, Font2D>
-                altNameCache = new ConcurrentHashMap<String, Font2D> ();
-            /* If there is an existing hashtable, we can drop it. */
-            appContext.put(CompositeFont.class, altNameCache);
-            _usingPerAppContextComposites = true;
-            createCompositeFonts(altNameCache, true, acPropPref);
-        }
     }
 
     public synchronized void preferProportionalFonts() {
         if (FontUtilities.isLogging()) {
             FontUtilities.getLogger()

@@ -2818,33 +2727,16 @@
          * to take any action.
          */
         if (!FontConfiguration.hasMonoToPropMap()) {
             return;
         }
-
-        if (!maybeMultiAppContext()) {
             if (gPropPref == true) {
                 return;
             }
             gPropPref = true;
             createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
             _usingAlternateComposites = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            if (appContext.get(proportionalFontKey) == proportionalFontKey) {
-                return;
-            }
-            appContext.put(proportionalFontKey, proportionalFontKey);
-            boolean acLocalePref =
-                appContext.get(localeFontKey) == localeFontKey;
-            ConcurrentHashMap<String, Font2D>
-                altNameCache = new ConcurrentHashMap<String, Font2D> ();
-            /* If there is an existing hashtable, we can drop it. */
-            appContext.put(CompositeFont.class, altNameCache);
-            _usingPerAppContextComposites = true;
-            createCompositeFonts(altNameCache, acLocalePref, true);
-        }
     }
 
     private static HashSet<String> installedNames = null;
     private static HashSet<String> getInstalledNames() {
         if (installedNames == null) {

@@ -2863,28 +2755,25 @@
            installedNames = names;
         }
         return installedNames;
     }
 
-    /* Keys are used to lookup per-AppContext Hashtables */
-    private static final Object regFamilyKey  = new Object();
-    private static final Object regFullNameKey = new Object();
+    private static final Object regFamilyLock  = new Object();
     private Hashtable<String,FontFamily> createdByFamilyName;
     private Hashtable<String,Font2D>     createdByFullName;
     private boolean fontsAreRegistered = false;
-    private boolean fontsAreRegisteredPerAppContext = false;
 
     public boolean registerFont(Font font) {
         /* This method should not be called with "null".
          * It is the caller's responsibility to ensure that.
          */
         if (font == null) {
             return false;
         }
 
         /* Initialise these objects only once we start to use this API */
-        synchronized (regFamilyKey) {
+        synchronized (regFamilyLock) {
             if (createdByFamilyName == null) {
                 createdByFamilyName = new Hashtable<String,FontFamily>();
                 createdByFullName = new Hashtable<String,Font2D>();
             }
         }

@@ -2917,35 +2806,14 @@
         if (names.contains(familyName) || names.contains(fullName)) {
             return false;
         }
 
         /* Checks passed, now register the font */
-        Hashtable<String,FontFamily> familyTable;
-        Hashtable<String,Font2D> fullNameTable;
-        if (!maybeMultiAppContext()) {
-            familyTable = createdByFamilyName;
-            fullNameTable = createdByFullName;
+        Hashtable<String, FontFamily> familyTable = createdByFamilyName;
+        Hashtable<String, Font2D> fullNameTable = createdByFullName;
             fontsAreRegistered = true;
-        } else {
-            AppContext appContext = AppContext.getAppContext();
-            @SuppressWarnings("unchecked")
-            Hashtable<String,FontFamily> tmp1 =
-                (Hashtable<String,FontFamily>)appContext.get(regFamilyKey);
-            familyTable = tmp1;
-            @SuppressWarnings("unchecked")
-            Hashtable<String,Font2D> tmp2 =
-                (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
-            fullNameTable = tmp2;
-
-            if (familyTable == null) {
-                familyTable = new Hashtable<String,FontFamily>();
-                fullNameTable = new Hashtable<String,Font2D>();
-                appContext.put(regFamilyKey, familyTable);
-                appContext.put(regFullNameKey, fullNameTable);
-            }
-            fontsAreRegisteredPerAppContext = true;
-        }
+
         /* Create the FontFamily and add font to the tables */
         Font2D font2D = FontUtilities.getFont2D(font);
         int style = font2D.getStyle();
         FontFamily family = familyTable.get(familyName);
         if (family == null) {

@@ -2987,16 +2855,10 @@
     public TreeMap<String, String> getCreatedFontFamilyNames() {
 
         Hashtable<String,FontFamily> familyTable;
         if (fontsAreRegistered) {
             familyTable = createdByFamilyName;
-        } else if (fontsAreRegisteredPerAppContext) {
-            AppContext appContext = AppContext.getAppContext();
-            @SuppressWarnings("unchecked")
-            Hashtable<String,FontFamily> tmp =
-                (Hashtable<String,FontFamily>)appContext.get(regFamilyKey);
-            familyTable = tmp;
         } else {
             return null;
         }
 
         Locale l = getSystemStartupLocale();

@@ -3017,16 +2879,10 @@
     public Font[] getCreatedFonts() {
 
         Hashtable<String,Font2D> nameTable;
         if (fontsAreRegistered) {
             nameTable = createdByFullName;
-        } else if (fontsAreRegisteredPerAppContext) {
-            AppContext appContext = AppContext.getAppContext();
-            @SuppressWarnings("unchecked")
-            Hashtable<String,Font2D> tmp =
-                (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
-            nameTable = tmp;
         } else {
             return null;
         }
 
         Locale l = getSystemStartupLocale();
< prev index next >