8072436: Refactor X11FontManager
Factor fontconfig related code out of X11FontManager into its own superclass FcFontManager. Reviewed-by: prr, serb
This commit is contained in:
parent
aa51e477d4
commit
08af89e08e
@ -243,7 +243,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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
108
jdk/src/java.desktop/unix/classes/sun/awt/FcFontManager.java
Normal file
108
jdk/src/java.desktop/unix/classes/sun/awt/FcFontManager.java
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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<fontConfigFonts.length; i++) {
|
||||
if ("sans".equals(fontConfigFonts[i].fcFamily) &&
|
||||
0 == fontConfigFonts[i].style) {
|
||||
info[0] = fontConfigFonts[i].firstFont.familyName;
|
||||
info[1] = fontConfigFonts[i].firstFont.fontFile;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Absolute last ditch attempt in the face of fontconfig problems.
|
||||
* If we didn't match, pick the first, or just make something
|
||||
* up so we don't NPE.
|
||||
*/
|
||||
if (info[0] == null) {
|
||||
if (fontConfigFonts.length > 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);
|
||||
}
|
||||
|
||||
}
|
@ -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<fontConfigFonts.length; i++) {
|
||||
if ("sans".equals(fontConfigFonts[i].fcFamily) &&
|
||||
0 == fontConfigFonts[i].style) {
|
||||
info[0] = fontConfigFonts[i].firstFont.familyName;
|
||||
info[1] = fontConfigFonts[i].firstFont.fontFile;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Absolute last ditch attempt in the face of fontconfig problems.
|
||||
* If we didn't match, pick the first, or just make something
|
||||
* up so we don't NPE.
|
||||
*/
|
||||
if (info[0] == null) {
|
||||
if (fontConfigFonts.length > 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
|
||||
|
@ -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<String> nameSet = new HashSet<String>();
|
||||
X11FontManager fm = (X11FontManager) fontManager;
|
||||
FcFontManager fm = (FcFontManager) fontManager;
|
||||
FontConfigManager fcm = fm.getFontConfigManager();
|
||||
FcCompFont[] fcCompFonts = fcm.loadFontConfig();
|
||||
for (int i=0; i<fcCompFonts.length; i++) {
|
||||
@ -235,7 +235,7 @@ public class FcFontConfiguration extends FontConfiguration {
|
||||
@Override
|
||||
public CompositeFontDescriptor[] get2DCompositeFontInfo() {
|
||||
|
||||
X11FontManager fm = (X11FontManager) fontManager;
|
||||
FcFontManager fm = (FcFontManager) fontManager;
|
||||
FontConfigManager fcm = fm.getFontConfigManager();
|
||||
FcCompFont[] fcCompFonts = fcm.loadFontConfig();
|
||||
|
||||
@ -368,7 +368,7 @@ public class FcFontConfiguration extends FontConfiguration {
|
||||
private void writeFcInfo() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("version", fileVersion);
|
||||
X11FontManager fm = (X11FontManager) fontManager;
|
||||
FcFontManager fm = (FcFontManager) fontManager;
|
||||
FontConfigManager fcm = fm.getFontConfigManager();
|
||||
FontConfigInfo fcInfo = fcm.getFontConfigInfo();
|
||||
props.setProperty("fcversion", Integer.toString(fcInfo.fcVersion));
|
||||
@ -427,7 +427,7 @@ public class FcFontConfiguration extends FontConfiguration {
|
||||
return;
|
||||
}
|
||||
Properties props = new Properties();
|
||||
X11FontManager fm = (X11FontManager) fontManager;
|
||||
FcFontManager fm = (FcFontManager) fontManager;
|
||||
FontConfigManager fcm = fm.getFontConfigManager();
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(fcFile);
|
||||
|
@ -497,7 +497,7 @@ static char* mergePaths(char **p1, char **p2, char **p3, jboolean noType1) {
|
||||
* This also frees us from X11 APIs as JRE is required to function in
|
||||
* a "headless" mode where there is no Xserver.
|
||||
*/
|
||||
static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {
|
||||
static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1, jboolean isX11) {
|
||||
|
||||
char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL;
|
||||
|
||||
@ -519,6 +519,7 @@ static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {
|
||||
* be initialised.
|
||||
*/
|
||||
#ifndef HEADLESS
|
||||
if (isX11) { // The following only works in an x11 environment.
|
||||
#if defined(__linux__)
|
||||
/* There's no headless build on linux ... */
|
||||
if (!AWTIsHeadless()) { /* .. so need to call a function to check */
|
||||
@ -538,6 +539,7 @@ static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {
|
||||
#if defined(__linux__)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* !HEADLESS */
|
||||
path = mergePaths(fcdirs, x11dirs, knowndirs, noType1);
|
||||
if (fcdirs != NULL) {
|
||||
@ -555,13 +557,13 @@ static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) {
|
||||
return path;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_sun_awt_X11FontManager_getFontPathNative
|
||||
(JNIEnv *env, jobject thiz, jboolean noType1) {
|
||||
JNIEXPORT jstring JNICALL Java_sun_awt_FcFontManager_getFontPathNative
|
||||
(JNIEnv *env, jobject thiz, jboolean noType1, jboolean isX11) {
|
||||
jstring ret;
|
||||
static char *ptr = NULL; /* retain result across calls */
|
||||
|
||||
if (ptr == NULL) {
|
||||
ptr = getPlatformFontPathChars(env, noType1);
|
||||
ptr = getPlatformFontPathChars(env, noType1, isX11);
|
||||
}
|
||||
ret = (*env)->NewStringUTF(env, ptr);
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user