Path: blob/master/src/java.desktop/share/classes/sun/font/FontManagerFactory.java
41155 views
/*1* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.font;2627import java.awt.AWTError;28import java.awt.Font;29import java.awt.GraphicsEnvironment;30import java.awt.Toolkit;31import java.security.AccessController;32import java.security.PrivilegedAction;3334import sun.security.action.GetPropertyAction;353637/**38* Factory class used to retrieve a valid FontManager instance for the current39* platform.40*41* A default implementation is given for Linux, Solaris and Windows.42* You can alter the behaviour of the {@link #getInstance()} method by setting43* the {@code sun.font.fontmanager} property. For example:44* {@code sun.font.fontmanager=sun.awt.X11FontManager}45*/46public final class FontManagerFactory {4748/** Our singleton instance. */49private static FontManager instance = null;5051private static final String DEFAULT_CLASS;52static {53if (FontUtilities.isWindows) {54DEFAULT_CLASS = "sun.awt.Win32FontManager";55} else if (FontUtilities.isMacOSX) {56DEFAULT_CLASS = "sun.font.CFontManager";57} else {58DEFAULT_CLASS = "sun.awt.X11FontManager";59}60}6162/**63* Get a valid FontManager implementation for the current platform.64*65* @return a valid FontManager instance for the current platform66*/67@SuppressWarnings("removal")68public static synchronized FontManager getInstance() {6970if (instance != null) {71return instance;72}7374AccessController.doPrivileged(new PrivilegedAction<Object>() {7576public Object run() {77try {78String fmClassName =79System.getProperty("sun.font.fontmanager",80DEFAULT_CLASS);81ClassLoader cl = ClassLoader.getSystemClassLoader();82Class<?> fmClass = Class.forName(fmClassName, true, cl);83instance =84(FontManager) fmClass.getDeclaredConstructor().newInstance();85} catch (ReflectiveOperationException ex) {86throw new InternalError(ex);8788}89return null;90}91});9293return instance;94}95}969798