From ae55f8beb589018beca086b50c680ffac763e661 Mon Sep 17 00:00:00 2001 From: rkennke Date: Wed, 19 Aug 2015 19:44:03 +0200 Subject: [PATCH] 8133917: Refactor X11FontManager Reviewed-by: robm --- make/mapfiles/libawt/mapfile-mawt-vers | 2 +- make/mapfiles/libawt/mapfile-vers-linux | 2 +- make/mapfiles/libawt_headless/mapfile-vers | 2 +- make/mapfiles/libawt_xawt/mapfile-vers | 2 +- .../classes/sun/awt/FcFontManager.java | 108 ++++++++++++++++++ .../classes/sun/awt/X11FontManager.java | 48 +------- .../classes/sun/font/FcFontConfiguration.java | 12 +- src/solaris/native/sun/awt/fontpath.c | 10 +- 8 files changed, 126 insertions(+), 60 deletions(-) create mode 100644 src/solaris/classes/sun/awt/FcFontManager.java diff --git a/make/mapfiles/libawt/mapfile-mawt-vers b/make/mapfiles/libawt/mapfile-mawt-vers index b8ea1636c..28ad3538d 100644 --- a/make/mapfiles/libawt/mapfile-mawt-vers +++ b/make/mapfiles/libawt/mapfile-mawt-vers @@ -242,7 +242,7 @@ SUNWprivate_1.1 { getDefaultConfig; Java_sun_font_FontConfigManager_getFontConfig; Java_sun_font_FontConfigManager_getFontConfigAASettings; - Java_sun_awt_X11FontManager_getFontPathNative; + Java_sun_awt_FcFontManager_getFontPathNative; Java_sun_font_SunFontManager_populateFontFileNameMap; # CDE private entry point diff --git a/make/mapfiles/libawt/mapfile-vers-linux b/make/mapfiles/libawt/mapfile-vers-linux index 922b015c6..5624693fc 100644 --- a/make/mapfiles/libawt/mapfile-vers-linux +++ b/make/mapfiles/libawt/mapfile-vers-linux @@ -270,7 +270,7 @@ SUNWprivate_1.1 { getDefaultConfig; Java_sun_font_FontConfigManager_getFontConfig; Java_sun_font_FontConfigManager_getFontConfigAASettings; - Java_sun_awt_X11FontManager_getFontPathNative; + Java_sun_awt_FcFontManager_getFontPathNative; Java_sun_font_SunFontManager_populateFontFileNameMap; # CDE private entry point diff --git a/make/mapfiles/libawt_headless/mapfile-vers b/make/mapfiles/libawt_headless/mapfile-vers index c12d07d80..44efc298b 100644 --- a/make/mapfiles/libawt_headless/mapfile-vers +++ b/make/mapfiles/libawt_headless/mapfile-vers @@ -65,7 +65,7 @@ SUNWprivate_1.1 { Java_sun_font_FontConfigManager_getFontConfig; Java_sun_font_FontConfigManager_getFontConfigAASettings; Java_sun_font_FontConfigManager_getFontConfigVersion; - Java_sun_awt_X11FontManager_getFontPathNative; + Java_sun_awt_FcFontManager_getFontPathNative; Java_sun_awt_FontDescriptor_initIDs; Java_sun_awt_PlatformFont_initIDs; diff --git a/make/mapfiles/libawt_xawt/mapfile-vers b/make/mapfiles/libawt_xawt/mapfile-vers index 3ae8af3dd..d24a527b0 100644 --- a/make/mapfiles/libawt_xawt/mapfile-vers +++ b/make/mapfiles/libawt_xawt/mapfile-vers @@ -188,7 +188,7 @@ SUNWprivate_1.1 { Java_sun_font_FontConfigManager_getFontConfig; Java_sun_font_FontConfigManager_getFontConfigAASettings; Java_sun_font_FontConfigManager_getFontConfigVersion; - Java_sun_awt_X11FontManager_getFontPathNative; + Java_sun_awt_FcFontManager_getFontPathNative; Java_sun_awt_X11GraphicsEnvironment_initDisplay; Java_sun_awt_X11GraphicsEnvironment_initGLX; Java_sun_awt_X11GraphicsEnvironment_initXRender; diff --git a/src/solaris/classes/sun/awt/FcFontManager.java b/src/solaris/classes/sun/awt/FcFontManager.java new file mode 100644 index 000000000..0b3ef6a8f --- /dev/null +++ b/src/solaris/classes/sun/awt/FcFontManager.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2009, 2014, 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.awt; + +import sun.font.FcFontConfiguration; +import sun.font.FontConfigManager; +import sun.font.SunFontManager; + +/** + * A {@link sun.font.FontManager} that uses fontconfig to find system fonts. + */ +public class FcFontManager extends SunFontManager { + + private FontConfigManager fcManager = null; + + public synchronized FontConfigManager getFontConfigManager() { + + if (fcManager == null) { + fcManager = new FontConfigManager(); + } + + return fcManager; + } + + @Override + protected FontConfiguration createFontConfiguration() { + FcFontConfiguration fcFontConfig = new FcFontConfiguration(this); + if (fcFontConfig.init()) { + return fcFontConfig; + } else { + throw new InternalError("failed to initialize fontconfig"); + } + } + + @Override + public FontConfiguration createFontConfiguration(boolean preferLocaleFonts, + boolean preferPropFonts) { + FcFontConfiguration fcFontConfig = + new FcFontConfiguration(this, preferLocaleFonts, preferPropFonts); + if (fcFontConfig.init()) { + return fcFontConfig; + } else { + throw new InternalError("failed to initialize fontconfig"); + } + } + + @Override + protected String[] getDefaultPlatformFont() { + final String[] info = new String[2]; + getFontConfigManager().initFontConfigFonts(false); + FontConfigManager.FcCompFont[] fontConfigFonts = + getFontConfigManager().getFontConfigFonts(); + for (int i=0; i 0 && + fontConfigFonts[0].firstFont.fontFile != null) { + info[0] = fontConfigFonts[0].firstFont.familyName; + info[1] = fontConfigFonts[0].firstFont.fontFile; + } else { + info[0] = "Dialog"; + info[1] = "/dialog.ttf"; + } + } + return info; + } + + protected native String getFontPathNative(boolean noType1Fonts, + boolean isX11GE); + + protected synchronized String getFontPath(boolean noType1Fonts) { + return getFontPathNative(noType1Fonts, false); + } + +} diff --git a/src/solaris/classes/sun/awt/X11FontManager.java b/src/solaris/classes/sun/awt/X11FontManager.java index b3a91df49..0b001b323 100644 --- a/src/solaris/classes/sun/awt/X11FontManager.java +++ b/src/solaris/classes/sun/awt/X11FontManager.java @@ -54,7 +54,7 @@ import sun.util.logging.PlatformLogger; /** * The X11 implementation of {@link FontManager}. */ -public final class X11FontManager extends SunFontManager { +public final class X11FontManager extends FcFontManager { // constants identifying XLFD and font ID fields private static final int FOUNDRY_FIELD = 1; @@ -154,8 +154,6 @@ public final class X11FontManager extends SunFontManager { */ private static String[] fontdirs = null; - private FontConfigManager fcManager = null; - public static X11FontManager getInstance() { return (X11FontManager) SunFontManager.getInstance(); } @@ -784,51 +782,9 @@ public final class X11FontManager extends SunFontManager { preferLocaleFonts, preferPropFonts); } - public synchronized native String getFontPathNative(boolean noType1Fonts); - protected synchronized String getFontPath(boolean noType1Fonts) { isHeadless(); // make sure GE is inited, as its the X11 lock. - return getFontPathNative(noType1Fonts); - } - - @Override - protected String[] getDefaultPlatformFont() { - final String[] info = new String[2]; - getFontConfigManager().initFontConfigFonts(false); - FontConfigManager.FcCompFont[] fontConfigFonts = - getFontConfigManager().getFontConfigFonts(); - for (int i=0; i 0 && - fontConfigFonts[0].firstFont.fontFile != null) { - info[0] = fontConfigFonts[0].firstFont.familyName; - info[1] = fontConfigFonts[0].firstFont.fontFile; - } else { - info[0] = "Dialog"; - info[1] = "/dialog.ttf"; - } - } - return info; - } - - public synchronized FontConfigManager getFontConfigManager() { - - if (fcManager == null) { - fcManager = new FontConfigManager(); - } - - return fcManager; + return getFontPathNative(noType1Fonts, true); } @Override diff --git a/src/solaris/classes/sun/font/FcFontConfiguration.java b/src/solaris/classes/sun/font/FcFontConfiguration.java index 34d8b7cbd..ecb813de5 100644 --- a/src/solaris/classes/sun/font/FcFontConfiguration.java +++ b/src/solaris/classes/sun/font/FcFontConfiguration.java @@ -39,10 +39,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Properties; import java.util.Scanner; +import sun.awt.FcFontManager; import sun.awt.FontConfiguration; import sun.awt.FontDescriptor; import sun.awt.SunToolkit; -import sun.awt.X11FontManager; import sun.font.CompositeFontDescriptor; import sun.font.FontManager; import sun.font.FontConfigManager.FontConfigInfo; @@ -92,7 +92,7 @@ public class FcFontConfiguration extends FontConfiguration { setFontConfiguration(); readFcInfo(); - X11FontManager fm = (X11FontManager) fontManager; + FcFontManager fm = (FcFontManager) fontManager; FontConfigManager fcm = fm.getFontConfigManager(); if (fcCompFonts == null) { fcCompFonts = fcm.loadFontConfig(); @@ -194,7 +194,7 @@ public class FcFontConfiguration extends FontConfiguration { @Override public String[] getPlatformFontNames() { HashSet nameSet = new HashSet(); - X11FontManager fm = (X11FontManager) fontManager; + FcFontManager fm = (FcFontManager) fontManager; FontConfigManager fcm = fm.getFontConfigManager(); FcCompFont[] fcCompFonts = fcm.loadFontConfig(); for (int i=0; iNewStringUTF(env, ptr); return ret; -- GitLab