JBR-6604 supported case when fonts directory is missing

This commit is contained in:
Dmitrii Morskii
2024-01-26 09:43:23 +00:00
parent 2a504dfd37
commit a1b7633997
3 changed files with 20 additions and 52 deletions

View File

@@ -265,6 +265,13 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
*/
private static int maxSoftRefCnt = 10;
protected boolean JREFontsDirExists(String path) {
@SuppressWarnings("removal")
boolean dirExist = AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
new File(path).isDirectory());
return dirExist;
}
private void initJREFontMap() {
/* Key is familyname+style value as an int.
@@ -278,10 +285,12 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
* are rarely used. Consider removing the other mappings if there's
* no evidence they are useful in practice.
*/
@SuppressWarnings("removal")
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () ->
new File(jreFontDirName).list(getTrueTypeFilter()));
Collections.addAll(jreBundledFontFiles, files);
if (JREFontsDirExists(jreFontDirName)) {
@SuppressWarnings("removal")
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () ->
new File(jreFontDirName).list(getTrueTypeFilter()));
Collections.addAll(jreBundledFontFiles, files);
}
jreFamilyMap.put("Roboto-Light", "Roboto Light");
jreFamilyMap.put("Roboto-Thin", "Roboto Thin");
@@ -319,14 +328,6 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
});
}
/**
* If the module image layout changes the location of JDK fonts,
* this will be updated to reflect that.
*/
public static final String getJDKFontDir() {
return jreFontDirName;
}
public TrueTypeFont getEUDCFont() {
// Overridden in Windows.
return null;
@@ -804,6 +805,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
}
protected synchronized void registerDeferredJREFonts(String jreDir) {
if (!JREFontsDirExists(jreDir)) {
return;
}
for (FontRegistrationInfo info : deferredFontFiles.values()) {
if (info.fontFilePath != null &&
info.fontFilePath.startsWith(jreDir)) {

View File

@@ -1,39 +0,0 @@
/*
* Copyright (c) 2016, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.font.lookup;
import sun.font.SunFontManager;
/**
* Implementation-class accessed by other JDK modules to
* locate the JDK-provided fonts.
*/
public final class JDKFontLookup {
public static final String getJDKFontDir() {
return SunFontManager.getJDKFontDir();
}
}

View File

@@ -272,7 +272,9 @@ public final class Win32FontManager extends SunFontManager {
*/
static String fontsForPrinting = null;
protected void registerJREFontsWithPlatform(String pathName) {
fontsForPrinting = pathName;
if (JREFontsDirExists(pathName)) {
fontsForPrinting = pathName;
}
}
@SuppressWarnings("removal")