8273581: Change the mechanism by which JDK loads the platform-specific FontManager class
Reviewed-by: prr, psadhukhan, azvegint, aivanov, serb
This commit is contained in:
parent
6a573b888d
commit
961dcffc86
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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;
|
||||
|
||||
final class PlatformFontInfo {
|
||||
|
||||
/**
|
||||
* The method is only to be called via the
|
||||
* {@code FontManagerFactory.getInstance()} factory method.
|
||||
*/
|
||||
static FontManager createFontManager() {
|
||||
return new CFontManager();
|
||||
}
|
||||
}
|
@ -25,72 +25,33 @@
|
||||
|
||||
package sun.font;
|
||||
|
||||
import java.awt.AWTError;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Toolkit;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
|
||||
/**
|
||||
* Factory class used to retrieve a valid FontManager instance for the current
|
||||
* platform.
|
||||
*
|
||||
* A default implementation is given for Linux, Solaris and Windows.
|
||||
* You can alter the behaviour of the {@link #getInstance()} method by setting
|
||||
* the {@code sun.font.fontmanager} property. For example:
|
||||
* {@code sun.font.fontmanager=sun.awt.X11FontManager}
|
||||
* A default implementation is given for Linux, Mac OS and Windows.
|
||||
*/
|
||||
public final class FontManagerFactory {
|
||||
|
||||
/** Our singleton instance. */
|
||||
private static FontManager instance = null;
|
||||
|
||||
private static final String DEFAULT_CLASS;
|
||||
static {
|
||||
if (FontUtilities.isWindows) {
|
||||
DEFAULT_CLASS = "sun.awt.Win32FontManager";
|
||||
} else if (FontUtilities.isMacOSX) {
|
||||
DEFAULT_CLASS = "sun.font.CFontManager";
|
||||
} else {
|
||||
DEFAULT_CLASS = "sun.awt.X11FontManager";
|
||||
}
|
||||
}
|
||||
private static volatile FontManager instance;
|
||||
|
||||
/**
|
||||
* Get a valid FontManager implementation for the current platform.
|
||||
*
|
||||
* @return a valid FontManager instance for the current platform
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
public static synchronized FontManager getInstance() {
|
||||
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
|
||||
public Object run() {
|
||||
try {
|
||||
String fmClassName =
|
||||
System.getProperty("sun.font.fontmanager",
|
||||
DEFAULT_CLASS);
|
||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||
Class<?> fmClass = Class.forName(fmClassName, true, cl);
|
||||
instance =
|
||||
(FontManager) fmClass.getDeclaredConstructor().newInstance();
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new InternalError(ex);
|
||||
public static FontManager getInstance() {
|
||||
|
||||
FontManager result = instance;
|
||||
if (result == null) {
|
||||
synchronized (FontManagerFactory.class) {
|
||||
result = instance;
|
||||
if (result == null) {
|
||||
instance = result = PlatformFontInfo.createFontManager();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
return instance;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
39
src/java.desktop/unix/classes/sun/font/PlatformFontInfo.java
Normal file
39
src/java.desktop/unix/classes/sun/font/PlatformFontInfo.java
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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;
|
||||
|
||||
import sun.awt.X11FontManager;
|
||||
|
||||
final class PlatformFontInfo {
|
||||
|
||||
/**
|
||||
* The method is only to be called via the
|
||||
* {@code FontManagerFactory.getInstance()} factory method.
|
||||
*/
|
||||
static FontManager createFontManager() {
|
||||
return new X11FontManager();
|
||||
}
|
||||
}
|
@ -109,8 +109,6 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
|
||||
struct utsname name;
|
||||
JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2);
|
||||
void *v;
|
||||
jstring fmanager = NULL;
|
||||
jstring fmProp = NULL;
|
||||
|
||||
if (awtHandle != NULL) {
|
||||
/* Avoid several loading attempts */
|
||||
@ -126,29 +124,15 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
|
||||
p = strrchr(buf, '/');
|
||||
#endif
|
||||
/*
|
||||
* The code below is responsible for:
|
||||
* 1. Loading appropriate awt library, i.e. libawt_xawt or libawt_headless
|
||||
* 2. Set the "sun.font.fontmanager" system property.
|
||||
* The code below is responsible for
|
||||
* loading appropriate awt library, i.e. libawt_xawt or libawt_headless
|
||||
*/
|
||||
|
||||
fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager");
|
||||
CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager property");
|
||||
|
||||
#ifdef MACOSX
|
||||
fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager");
|
||||
tk = LWAWT_PATH;
|
||||
#else
|
||||
fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager");
|
||||
tk = XAWT_PATH;
|
||||
#endif
|
||||
CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager name");
|
||||
|
||||
if (fmanager && fmProp) {
|
||||
JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty",
|
||||
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
|
||||
fmProp, fmanager);
|
||||
CHECK_EXCEPTION_FATAL(env, "Could not allocate set properties");
|
||||
}
|
||||
|
||||
#ifndef MACOSX
|
||||
if (AWTIsHeadless()) {
|
||||
@ -161,14 +145,6 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
|
||||
strncpy(p, tk, MAXPATHLEN-len-1);
|
||||
#endif
|
||||
|
||||
if (fmProp) {
|
||||
(*env)->DeleteLocalRef(env, fmProp);
|
||||
}
|
||||
if (fmanager) {
|
||||
(*env)->DeleteLocalRef(env, fmanager);
|
||||
}
|
||||
|
||||
|
||||
#ifndef STATIC_BUILD
|
||||
jstring jbuf = JNU_NewStringPlatform(env, buf);
|
||||
CHECK_EXCEPTION_FATAL(env, "Could not allocate library name");
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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;
|
||||
|
||||
import sun.awt.Win32FontManager;
|
||||
|
||||
final class PlatformFontInfo {
|
||||
|
||||
/**
|
||||
* The method is only to be called via the
|
||||
* {@code FontManagerFactory.getInstance()} factory method.
|
||||
*/
|
||||
static FontManager createFontManager() {
|
||||
return new Win32FontManager();
|
||||
}
|
||||
}
|
46
test/jdk/sun/awt/font/CheckFontManagerSystemProperty.java
Normal file
46
test/jdk/sun/awt/font/CheckFontManagerSystemProperty.java
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8273581
|
||||
* @summary verify the "sun.font.fontmanager" system property is not set
|
||||
* @run main/othervm -Djava.awt.headless=true CheckFontManagerSystemProperty
|
||||
*/
|
||||
|
||||
public class CheckFontManagerSystemProperty {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// force AWT library loading
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
if (toolkit == null) {
|
||||
throw new RuntimeException("Toolkit not found!");
|
||||
}
|
||||
String tkProp = System.getProperty("sun.font.fontmanager");
|
||||
if (tkProp != null) {
|
||||
throw new RuntimeException("tkProp = " + tkProp);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user