Path: blob/master/src/java.desktop/unix/classes/sun/awt/FcFontManager.java
41152 views
/*1* Copyright (c) 2015, 2020, 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();75if (fontConfigFonts != null) {76for (int i=0; i<fontConfigFonts.length; i++) {77if ("sans".equals(fontConfigFonts[i].fcFamily) &&780 == fontConfigFonts[i].style) {79info[0] = fontConfigFonts[i].firstFont.fullName;80info[1] = fontConfigFonts[i].firstFont.fontFile;81break;82}83}84}85/* Absolute last ditch attempt in the face of fontconfig problems.86* If we didn't match, pick the first, or just make something87* up so we don't NPE.88*/89if (info[0] == null) {90if (fontConfigFonts != null && fontConfigFonts.length > 0 &&91fontConfigFonts[0].firstFont.fontFile != null &&92fontConfigFonts[0].firstFont.fullName != null) {93info[0] = fontConfigFonts[0].firstFont.fullName;94info[1] = fontConfigFonts[0].firstFont.fontFile;95} else {96info[0] = "Dialog";97info[1] = "/dialog.ttf";98}99}100return info;101}102103native String getFontPathNative(boolean noType1Fonts, boolean isX11GE);104105protected synchronized String getFontPath(boolean noType1Fonts) {106return getFontPathNative(noType1Fonts, false);107}108109}110111112