Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/FcFontManager.java
32287 views
/*1* Copyright (c) 2009, 2014, 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.awt;2627import sun.font.FcFontConfiguration;28import sun.font.FontConfigManager;29import sun.font.SunFontManager;3031/**32* A {@link sun.font.FontManager} that uses fontconfig to find system fonts.33*/34public class FcFontManager extends SunFontManager {3536private FontConfigManager fcManager = null;3738public synchronized FontConfigManager getFontConfigManager() {3940if (fcManager == null) {41fcManager = new FontConfigManager();42}4344return fcManager;45}4647@Override48protected FontConfiguration createFontConfiguration() {49FcFontConfiguration fcFontConfig = new FcFontConfiguration(this);50if (fcFontConfig.init()) {51return fcFontConfig;52} else {53throw new InternalError("failed to initialize fontconfig");54}55}5657@Override58public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,59boolean preferPropFonts) {60FcFontConfiguration fcFontConfig =61new FcFontConfiguration(this, preferLocaleFonts, preferPropFonts);62if (fcFontConfig.init()) {63return fcFontConfig;64} else {65throw new InternalError("failed to initialize fontconfig");66}67}6869@Override70protected String[] getDefaultPlatformFont() {71final String[] info = new String[2];72getFontConfigManager().initFontConfigFonts(false);73FontConfigManager.FcCompFont[] fontConfigFonts =74getFontConfigManager().getFontConfigFonts();75for (int i=0; i<fontConfigFonts.length; i++) {76if ("sans".equals(fontConfigFonts[i].fcFamily) &&770 == fontConfigFonts[i].style) {78info[0] = fontConfigFonts[i].firstFont.familyName;79info[1] = fontConfigFonts[i].firstFont.fontFile;80break;81}82}83/* Absolute last ditch attempt in the face of fontconfig problems.84* If we didn't match, pick the first, or just make something85* up so we don't NPE.86*/87if (info[0] == null) {88if (fontConfigFonts.length > 0 &&89fontConfigFonts[0].firstFont.fontFile != null) {90info[0] = fontConfigFonts[0].firstFont.familyName;91info[1] = fontConfigFonts[0].firstFont.fontFile;92} else {93info[0] = "Dialog";94info[1] = "/dialog.ttf";95}96}97return info;98}99100protected native String getFontPathNative(boolean noType1Fonts,101boolean isX11GE);102103protected synchronized String getFontPath(boolean noType1Fonts) {104return getFontPathNative(noType1Fonts, false);105}106107}108109110