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

Print this page

        

*** 195,207 **** public static String jreLibDirName; public static String jreFontDirName; private static HashSet<String> missingFontFiles = null; private String defaultFontName; private String defaultFontFileName; ! protected HashSet registeredFontFiles = new HashSet(); ! private ArrayList badFonts; /* fontPath is the location of all fonts on the system, excluding the * JRE's own font directory but including any path specified using the * sun.java2d.fontpath property. Together with that property, it is * initialised by the getPlatformFontPath() method * This call must be followed by a call to registerFontDirs(fontPath) --- 195,207 ---- public static String jreLibDirName; public static String jreFontDirName; private static HashSet<String> missingFontFiles = null; private String defaultFontName; private String defaultFontFileName; ! protected HashSet<String> registeredFontFiles = new HashSet<>(); ! private ArrayList<String> badFonts; /* fontPath is the location of all fonts on the system, excluding the * JRE's own font directory but including any path specified using the * sun.java2d.fontpath property. Together with that property, it is * initialised by the getPlatformFontPath() method * This call must be followed by a call to registerFontDirs(fontPath)
*** 330,340 **** } static { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { FontManagerNativeLibrary.load(); // JNI throws an exception if a class/method/field is not found, --- 330,340 ---- } static { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { FontManagerNativeLibrary.load(); // JNI throws an exception if a class/method/field is not found,
*** 371,389 **** @SuppressWarnings("unchecked") protected SunFontManager() { initJREFontMap(); java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { File badFontFile = new File(jreFontDirName + File.separator + "badfonts.txt"); if (badFontFile.exists()) { FileInputStream fis = null; try { ! badFonts = new ArrayList(); fis = new FileInputStream(badFontFile); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr); while (true) { String name = br.readLine(); --- 371,389 ---- @SuppressWarnings("unchecked") protected SunFontManager() { initJREFontMap(); java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { File badFontFile = new File(jreFontDirName + File.separator + "badfonts.txt"); if (badFontFile.exists()) { FileInputStream fis = null; try { ! badFonts = new ArrayList<>(); fis = new FileInputStream(badFontFile); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr); while (true) { String name = br.readLine();
*** 1225,1237 **** * know all fonts have already been loaded, just accept any * match at this point. If this fails we are in real trouble * and I don't know how to recover from there being absolutely * no fonts anywhere on the system. */ ! Iterator i = physicalFonts.values().iterator(); if (i.hasNext()) { ! defaultPhysicalFont = (PhysicalFont)i.next(); } else { throw new Error("Probable fatal error:No fonts found."); } } } --- 1225,1237 ---- * know all fonts have already been loaded, just accept any * match at this point. If this fails we are in real trouble * and I don't know how to recover from there being absolutely * no fonts anywhere on the system. */ ! Iterator<PhysicalFont> i = physicalFonts.values().iterator(); if (i.hasNext()) { ! defaultPhysicalFont = i.next(); } else { throw new Error("Probable fatal error:No fonts found."); } } }
*** 1301,1311 **** if (noType1) { filter = ttFilter; } else { filter = new TTorT1Filter(); } ! return (String[])AccessController.doPrivileged(new PrivilegedAction() { public Object run() { if (pathDirs.length == 1) { File dir = new File(pathDirs[0]); String[] files = dir.list(filter); if (files == null) { --- 1301,1311 ---- if (noType1) { filter = ttFilter; } else { filter = new TTorT1Filter(); } ! return (String[])AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { if (pathDirs.length == 1) { File dir = new File(pathDirs[0]); String[] files = dir.list(filter); if (files == null) {
*** 1417,1426 **** --- 1417,1427 ---- * CJK locales are TTC fonts and not all fonts in a TTC may have * localised names. Eg MSGOTHIC.TTC contains 3 fonts and one of * them "MS UI Gothic" has no JA name whereas the other two do. * So not every font in these files is unmapped or new. */ + @SuppressWarnings("unchecked") HashMap<String,String> ffmapCopy = (HashMap<String,String>)(fontToFileMap.clone()); for (String key : fontToFamilyNameMap.keySet()) { ffmapCopy.remove(key); }
*** 1468,1478 **** int sz = unmappedFontNames.size(); for (int i=0; i<sz; i++) { String name = unmappedFontNames.get(i); String familyName = fontToFamilyNameMap.get(name); if (familyName != null) { ! ArrayList family = familyToFontListMap.get(familyName); if (family != null) { if (family.size() <= 1) { familyToFontListMap.remove(familyName); } } --- 1469,1479 ---- int sz = unmappedFontNames.size(); for (int i=0; i<sz; i++) { String name = unmappedFontNames.get(i); String familyName = fontToFamilyNameMap.get(name); if (familyName != null) { ! ArrayList<String> family = familyToFontListMap.get(familyName); if (family != null) { if (family.size() <= 1) { familyToFontListMap.remove(familyName); } }
*** 1894,1904 **** * set, and on windows, the fonts in the system font directory that * are in the fontToFileMap are just basenames. We don't want to try * to register those again, but we do want to register other registry * installed fonts. */ ! protected void registerOtherFontFiles(HashSet registeredFontFiles) { if (getFullNameToFileMap().size() == 0) { return; } for (String file : fontToFileMap.values()) { registerFontFile(file); --- 1895,1905 ---- * set, and on windows, the fonts in the system font directory that * are in the fontToFileMap are just basenames. We don't want to try * to register those again, but we do want to register other registry * installed fonts. */ ! protected void registerOtherFontFiles(HashSet<String> registeredFontFiles) { if (getFullNameToFileMap().size() == 0) { return; } for (String file : fontToFileMap.values()) { registerFontFile(file);
*** 2078,2087 **** --- 2079,2089 ---- * 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);
*** 2302,2315 **** if (fontsAreRegistered) { familyTable = createdByFamilyName; nameTable = createdByFullName; } else { AppContext appContext = AppContext.getAppContext(); ! familyTable = ! (Hashtable<String,FontFamily>)appContext.get(regFamilyKey); ! nameTable = ! (Hashtable<String,Font2D>)appContext.get(regFullNameKey); } family = familyTable.get(lowerCaseName); if (family != null) { font = family.getFontWithExactStyleMatch(style); --- 2304,2320 ---- 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; } family = familyTable.get(lowerCaseName); if (family != null) { font = family.getFontWithExactStyleMatch(style);
*** 2465,2475 **** throw new FontFormatException("Unrecognised Font Format"); } } catch (FontFormatException e) { if (isCopy) { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { if (_tracker != null) { _tracker.subBytes((int)fFile.length()); } fFile.delete(); --- 2470,2480 ---- throw new FontFormatException("Unrecognised Font Format"); } } catch (FontFormatException e) { if (isCopy) { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { if (_tracker != null) { _tracker.subBytes((int)fFile.length()); } fFile.delete();
*** 2490,2500 **** if (fileCloser == null) { final Runnable fileCloserRunnable = new Runnable() { public void run() { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { for (int i=0;i<CHANNELPOOLSIZE;i++) { if (fontFileCache[i] != null) { try { --- 2495,2505 ---- if (fileCloser == null) { final Runnable fileCloserRunnable = new Runnable() { public void run() { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { for (int i=0;i<CHANNELPOOLSIZE;i++) { if (fontFileCache[i] != null) { try {
*** 2519,2529 **** }); } }; java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { /* The thread must be a member of a thread group * which will not get GCed before VM exit. * Make its parent the top-level thread group. */ --- 2524,2534 ---- }); } }; java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { /* The thread must be a member of a thread group * which will not get GCed before VM exit. * Make its parent the top-level thread group. */
*** 2625,2643 **** oldFont.handle.font2D = newFont; physicalFonts.remove(oldFont.fullName); fullNameToFont.remove(oldFont.fullName.toLowerCase(Locale.ENGLISH)); FontFamily.remove(oldFont); if (localeFullNamesToFont != null) { ! Map.Entry[] mapEntries = localeFullNamesToFont.entrySet(). ! toArray(new Map.Entry[0]); /* Should I be replacing these, or just I just remove * the names from the map? */ for (int i=0; i<mapEntries.length;i++) { if (mapEntries[i].getValue() == oldFont) { try { ! mapEntries[i].setValue(newFont); } catch (Exception e) { /* some maps don't support this operation. * In this case just give up and remove the entry. */ localeFullNamesToFont.remove(mapEntries[i].getKey()); --- 2630,2650 ---- oldFont.handle.font2D = newFont; physicalFonts.remove(oldFont.fullName); fullNameToFont.remove(oldFont.fullName.toLowerCase(Locale.ENGLISH)); FontFamily.remove(oldFont); if (localeFullNamesToFont != null) { ! Map.Entry<?, ?>[] mapEntries = localeFullNamesToFont.entrySet(). ! toArray(new Map.Entry<?, ?>[0]); /* Should I be replacing these, or just I just remove * the names from the map? */ for (int i=0; i<mapEntries.length;i++) { if (mapEntries[i].getValue() == oldFont) { try { ! @SuppressWarnings("unchecked") ! Map.Entry<String, PhysicalFont> tmp = (Map.Entry<String, PhysicalFont>)mapEntries[i]; ! tmp.setValue(newFont); } catch (Exception e) { /* some maps don't support this operation. * In this case just give up and remove the entry. */ localeFullNamesToFont.remove(mapEntries[i].getKey());
*** 2862,2872 **** } private static boolean maybeMultiAppContext() { Boolean appletSM = (Boolean) java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { SecurityManager sm = System.getSecurityManager(); return new Boolean (sm instanceof sun.applet.AppletSecurity); } --- 2869,2879 ---- } private static boolean maybeMultiAppContext() { Boolean appletSM = (Boolean) java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { SecurityManager sm = System.getSecurityManager(); return new Boolean (sm instanceof sun.applet.AppletSecurity); }
*** 3053,3066 **** familyTable = createdByFamilyName; fullNameTable = createdByFullName; fontsAreRegistered = true; } else { AppContext appContext = AppContext.getAppContext(); ! familyTable = ! (Hashtable<String,FontFamily>)appContext.get(regFamilyKey); ! fullNameTable = ! (Hashtable<String,Font2D>)appContext.get(regFullNameKey); if (familyTable == null) { familyTable = new Hashtable<String,FontFamily>(); fullNameTable = new Hashtable<String,Font2D>(); appContext.put(regFamilyKey, familyTable); appContext.put(regFullNameKey, fullNameTable); --- 3060,3076 ---- familyTable = createdByFamilyName; 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);
*** 3112,3123 **** Hashtable<String,FontFamily> familyTable; if (fontsAreRegistered) { familyTable = createdByFamilyName; } else if (fontsAreRegisteredPerAppContext) { AppContext appContext = AppContext.getAppContext(); ! familyTable = ! (Hashtable<String,FontFamily>)appContext.get(regFamilyKey); } else { return null; } Locale l = getSystemStartupLocale(); --- 3122,3134 ---- 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();
*** 3140,3151 **** Hashtable<String,Font2D> nameTable; if (fontsAreRegistered) { nameTable = createdByFullName; } else if (fontsAreRegisteredPerAppContext) { AppContext appContext = AppContext.getAppContext(); ! nameTable = ! (Hashtable<String,Font2D>)appContext.get(regFullNameKey); } else { return null; } Locale l = getSystemStartupLocale(); --- 3151,3163 ---- 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();
*** 3303,3313 **** .info("SunGraphicsEnvironment.loadFonts() called"); } initialiseDeferredFonts(); java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { if (fontPath == null) { fontPath = getPlatformFontPath(noType1Font); registerFontDirs(fontPath); } --- 3315,3325 ---- .info("SunGraphicsEnvironment.loadFonts() called"); } initialiseDeferredFonts(); java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { if (fontPath == null) { fontPath = getPlatformFontPath(noType1Font); registerFontDirs(fontPath); }
*** 3438,3448 **** if (FontUtilities.debugFonts()) { Thread.dumpStack(); FontUtilities.getLogger().info("loadAllFontFiles() called"); } java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { if (fontPath == null) { fontPath = getPlatformFontPath(noType1Font); } if (fontPath != null) { --- 3450,3460 ---- if (FontUtilities.debugFonts()) { Thread.dumpStack(); FontUtilities.getLogger().info("loadAllFontFiles() called"); } java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { if (fontPath == null) { fontPath = getPlatformFontPath(noType1Font); } if (fontPath != null) {
*** 3680,3690 **** * Returns all fonts installed in this environment. */ public Font[] getAllInstalledFonts() { if (allFonts == null) { loadFonts(); ! TreeMap fontMapNames = new TreeMap(); /* warning: the number of composite fonts could change dynamically * if applications are allowed to create them. "allfonts" could * then be stale. */ Font2D[] allfonts = getRegisteredFonts(); --- 3692,3702 ---- * Returns all fonts installed in this environment. */ public Font[] getAllInstalledFonts() { if (allFonts == null) { loadFonts(); ! TreeMap<String, Font2D> fontMapNames = new TreeMap<>(); /* warning: the number of composite fonts could change dynamically * if applications are allowed to create them. "allfonts" could * then be stale. */ Font2D[] allfonts = getRegisteredFonts();
*** 3713,3723 **** } } Font[] fonts = new Font[fontNames.length]; for (int i=0; i < fontNames.length; i++) { fonts[i] = new Font(fontNames[i], Font.PLAIN, 1); ! Font2D f2d = (Font2D)fontMapNames.get(fontNames[i]); if (f2d != null) { FontAccess.getFontAccess().setFont2D(fonts[i], f2d.handle); } } allFonts = fonts; --- 3725,3735 ---- } } Font[] fonts = new Font[fontNames.length]; for (int i=0; i < fontNames.length; i++) { fonts[i] = new Font(fontNames[i], Font.PLAIN, 1); ! Font2D f2d = fontMapNames.get(fontNames[i]); if (f2d != null) { FontAccess.getFontAccess().setFont2D(fonts[i], f2d.handle); } } allFonts = fonts;
*** 3796,3806 **** // Provides an aperture to add native font family names to the map protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) { } public void register1dot0Fonts() { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { String type1Dir = "/usr/openwin/lib/X11/fonts/Type1"; registerFontsInDir(type1Dir, true, Font2D.TYPE1_RANK, false, false); return null; --- 3808,3818 ---- // Provides an aperture to add native font family names to the map protected void addNativeFontFamilyNames(TreeMap<String, String> familyNames, Locale requestedLocale) { } public void register1dot0Fonts() { java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { String type1Dir = "/usr/openwin/lib/X11/fonts/Type1"; registerFontsInDir(type1Dir, true, Font2D.TYPE1_RANK, false, false); return null;
*** 3838,3848 **** private static Locale systemLocale = null; private static Locale getSystemStartupLocale() { if (systemLocale == null) { systemLocale = (Locale) java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction() { public Object run() { /* On windows the system locale may be different than the * user locale. This is an unsupported configuration, but * in that case we want to return a dummy locale that will * never cause a match in the usage of this API. This is --- 3850,3860 ---- private static Locale systemLocale = null; private static Locale getSystemStartupLocale() { if (systemLocale == null) { systemLocale = (Locale) java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Object>() { public Object run() { /* On windows the system locale may be different than the * user locale. This is an unsupported configuration, but * in that case we want to return a dummy locale that will * never cause a match in the usage of this API. This is