JBR-5804: refactoring of freetypeScaler and moving fontconfig's logic in separate file

(cherry picked from commit 4700386a2e)
This commit is contained in:
Dmitrii Morskii
2023-05-18 16:12:34 +02:00
committed by jbrbot
parent 5a9d8b2140
commit fd3c371bca
7 changed files with 1336 additions and 1249 deletions

View File

@@ -0,0 +1,835 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. 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.
*/
#if defined(__linux__)
#include <string.h>
#endif /* __linux__ */
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include "fontconfigmanager.h"
#include <jni.h>
#include <jni_util.h>
#include <jvm_md.h>
#include <sizecalc.h>
#ifndef HEADLESS
#include <awt.h>
#else
/* locks ought to be included from awt.h */
#define AWT_LOCK()
#define AWT_UNLOCK()
#endif /* !HEADLESS */
#define FONTCONFIG_DLL_VERSIONED VERSIONED_JNI_LIB_NAME("fontconfig", "1")
#define FONTCONFIG_DLL JNI_LIB_NAME("fontconfig")
#if defined( __linux__)
/* All the known interesting locations we have discovered on
* various flavors of Linux
*/
static char *fullLinuxFontPath[] = {
"/usr/X11R6/lib/X11/fonts/TrueType", /* RH 7.1+ */
"/usr/X11R6/lib/X11/fonts/truetype", /* SuSE */
"/usr/X11R6/lib/X11/fonts/tt",
"/usr/X11R6/lib/X11/fonts/TTF",
"/usr/X11R6/lib/X11/fonts/OTF", /* RH 9.0 (but empty!) */
"/usr/share/fonts/ja/TrueType", /* RH 7.2+ */
"/usr/share/fonts/truetype",
"/usr/share/fonts/ko/TrueType", /* RH 9.0 */
"/usr/share/fonts/zh_CN/TrueType", /* RH 9.0 */
"/usr/share/fonts/zh_TW/TrueType", /* RH 9.0 */
"/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType", /* Debian */
"/usr/X11R6/lib/X11/fonts/Type1",
"/usr/share/fonts/default/Type1", /* RH 9.0 */
NULL, /* terminates the list */
};
#elif defined(_AIX)
static char *fullAixFontPath[] = {
"/usr/lpp/X11/lib/X11/fonts/Type1", /* from X11.fnt.iso_T1 */
"/usr/lpp/X11/lib/X11/fonts/TrueType", /* from X11.fnt.ucs.ttf */
NULL, /* terminates the list */
};
#endif
#include <dlfcn.h>
#include <fontconfig/fontconfig.h>
typedef FcConfig* (*FcInitLoadConfigFuncType)();
typedef FcPattern* (*FcPatternBuildFuncType)(FcPattern *orig, ...);
typedef FcObjectSet* (*FcObjectSetFuncType)(const char *first, ...);
typedef FcFontSet* (*FcFontListFuncType)(FcConfig *config, FcPattern *p, FcObjectSet *os);
typedef FcResult (*FcPatternGetBoolFuncType)(const FcPattern *p, const char *object, int n, FcBool *b);
typedef FcResult (*FcPatternGetIntegerFuncType)(const FcPattern *p, const char *object, int n, int *i);
typedef FcResult (*FcPatternGetStringFuncType)(const FcPattern *p, const char *object, int n, FcChar8 ** s);
typedef FcChar8* (*FcStrDirnameFuncType)(const FcChar8 *file);
typedef void (*FcPatternDestroyFuncType)(FcPattern *p);
typedef void (*FcObjectSetDestroyFuncType)(FcObjectSet *os);
typedef void (*FcFontSetDestroyFuncType)(FcFontSet *s);
typedef FcPattern* (*FcNameParseFuncType)(const FcChar8 *name);
typedef FcBool (*FcPatternAddStringFuncType)(FcPattern *p, const char *object, const FcChar8 *s);
typedef FcBool (*FcPatternAddDoubleFuncType)(FcPattern *p, const char *object, double v);
typedef void (*FcDefaultSubstituteFuncType)(FcPattern *p);
typedef FcBool (*FcConfigSubstituteFuncType)(FcConfig *config, FcPattern *p, FcMatchKind kind);
typedef FcPattern* (*FcFontMatchFuncType)(FcConfig *config, FcPattern *p, FcResult *result);
typedef FcFontSet* (*FcFontSetCreateFuncType)();
typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font);
typedef FcResult (*FcPatternGetCharSetFuncType)(FcPattern *p, const char *object, int n, FcCharSet **c);
typedef FcFontSet* (*FcFontSortFuncType)(FcConfig *config, FcPattern *p, FcBool trim, FcCharSet **csp, FcResult *result);
typedef FcCharSet* (*FcCharSetUnionFuncType)(const FcCharSet *a, const FcCharSet *b);
typedef FcCharSet* (*FcCharSetDestroyFuncType)(FcCharSet *fcs);
typedef FcChar32 (*FcCharSetSubtractCountFuncType)(const FcCharSet *a, const FcCharSet *b);
typedef int (*FcGetVersionFuncType)();
typedef FcStrList* (*FcConfigGetCacheDirsFuncType)(FcConfig *config);
typedef FcChar8* (*FcStrListNextFuncType)(FcStrList *list);
typedef FcChar8* (*FcStrListDoneFuncType)(FcStrList *list);
typedef FcChar8* (*FcPatternFormatFuncType)(FcPattern *pat, const FcChar8 *format);
typedef void (*FcStrFreeFuncType)(FcChar8 *str);
static FcInitLoadConfigFuncType fcInitLoadConfig;
static FcPatternBuildFuncType fcPatternBuild;
static FcObjectSetFuncType fcObjectSetBuild;
static FcFontListFuncType fcFontList;
static FcStrDirnameFuncType fcStrDirname;
static FcObjectSetDestroyFuncType fcObjectSetDestroy;
static FcPatternGetBoolFuncType fcPatternGetBool;
static FcPatternGetIntegerFuncType fcPatternGetInteger;
static FcNameParseFuncType fcNameParse;
static FcPatternAddStringFuncType fcPatternAddString;
static FcPatternAddDoubleFuncType fcPatternAddDouble;
static FcConfigSubstituteFuncType fcConfigSubstitute;
static FcDefaultSubstituteFuncType fcDefaultSubstitute;
static FcFontMatchFuncType fcFontMatch;
static FcPatternGetStringFuncType fcPatternGetString;
static FcPatternDestroyFuncType fcPatternDestroy;
static FcPatternGetCharSetFuncType fcPatternGetCharSet;
static FcFontSortFuncType fcFontSort;
static FcFontSetDestroyFuncType fcFontSetDestroy;
static FcCharSetUnionFuncType fcCharSetUnion;
static FcCharSetDestroyFuncType fcCharSetDestroy;
static FcCharSetSubtractCountFuncType fcCharSetSubtractCount;
static FcGetVersionFuncType fcGetVersion;
static FcConfigGetCacheDirsFuncType fcConfigGetCacheDirs;
static FcStrListNextFuncType fcStrListNext;
static FcStrListDoneFuncType fcStrListDone;
static FcPatternFormatFuncType fcPatternFormat;
static FcStrFreeFuncType fcStrFree;
static void *libfontconfig = NULL;
static void closeFontConfig() {
if (libfontconfig != NULL) {
dlclose(libfontconfig);
libfontconfig = NULL;
}
}
void openFontConfig() {
char *homeEnv;
static char *homeEnvStr = "HOME="; /* must be static */
/* Private workaround to not use fontconfig library.
* May be useful during testing/debugging
*/
char *useFC = getenv("USE_J2D_FONTCONFIG");
if (useFC != NULL && !strcmp(useFC, "no")) {
return;
}
#if defined(_AIX)
/* On AIX, fontconfig is not a standard package supported by IBM.
* instead it has to be installed from the "AIX Toolbox for Linux Applications"
* site http://www-03.ibm.com/systems/power/software/aix/linux/toolbox/alpha.html
* and will be installed under /opt/freeware/lib/libfontconfig.a.
* Notice that the archive contains the real 32- and 64-bit shared libraries.
* We first try to load 'libfontconfig.so' from the default library path in the
* case the user has installed a private version of the library and if that
* doesn't succeed, we try the version from /opt/freeware/lib/libfontconfig.a
*/
libfontconfig = dlopen("libfontconfig.so", RTLD_LOCAL|RTLD_LAZY);
if (libfontconfig == NULL) {
libfontconfig = dlopen("/opt/freeware/lib/libfontconfig.a(libfontconfig.so.1)", RTLD_MEMBER|RTLD_LOCAL|RTLD_LAZY);
if (libfontconfig == NULL) {
return;
}
}
#else
/* 64 bit sparc should pick up the right version from the lib path.
* New features may be added to libfontconfig, this is expected to
* be compatible with old features, but we may need to start
* distinguishing the library version, to know whether to expect
* certain symbols - and functionality - to be available.
* Also add explicit search for .so.1 in case .so symlink doesn't exist.
*/
libfontconfig = dlopen(FONTCONFIG_DLL_VERSIONED, RTLD_LOCAL|RTLD_LAZY);
if (libfontconfig == NULL) {
libfontconfig = dlopen(FONTCONFIG_DLL, RTLD_LOCAL|RTLD_LAZY);
if (libfontconfig == NULL) {
return;
}
}
#endif
/* Version 1.0 of libfontconfig crashes if HOME isn't defined in
* the environment. This should generally never happen, but we can't
* control it, and can't control the version of fontconfig, so iff
* its not defined we set it to an empty value which is sufficient
* to prevent a crash. I considered unsetting it before exit, but
* it doesn't appear to work on Solaris, so I will leave it set.
*/
homeEnv = getenv("HOME");
if (homeEnv == NULL) {
putenv(homeEnvStr);
}
fcPatternBuild = (FcPatternBuildFuncType)dlsym(libfontconfig, "FcPatternBuild");
fcObjectSetBuild = (FcObjectSetFuncType)dlsym(libfontconfig, "FcObjectSetBuild");
fcFontList = (FcFontListFuncType)dlsym(libfontconfig, "FcFontList");
fcStrDirname = (FcStrDirnameFuncType)dlsym(libfontconfig, "FcStrDirname");
fcObjectSetDestroy = (FcObjectSetDestroyFuncType)dlsym(libfontconfig, "FcObjectSetDestroy");
fcPatternGetBool = (FcPatternGetBoolFuncType) dlsym(libfontconfig, "FcPatternGetBool");
fcPatternGetInteger = (FcPatternGetIntegerFuncType)dlsym(libfontconfig, "FcPatternGetInteger");
fcNameParse = (FcNameParseFuncType)dlsym(libfontconfig, "FcNameParse");
fcPatternAddString = (FcPatternAddStringFuncType)dlsym(libfontconfig, "FcPatternAddString");
fcPatternAddDouble = (FcPatternAddDoubleFuncType)dlsym(libfontconfig, "FcPatternAddDouble");
fcConfigSubstitute = (FcConfigSubstituteFuncType)dlsym(libfontconfig, "FcConfigSubstitute");
fcDefaultSubstitute = (FcDefaultSubstituteFuncType)dlsym(libfontconfig, "FcDefaultSubstitute");
fcFontMatch = (FcFontMatchFuncType)dlsym(libfontconfig, "FcFontMatch");
fcPatternGetString = (FcPatternGetStringFuncType)dlsym(libfontconfig, "FcPatternGetString");
fcPatternDestroy = (FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy");
fcPatternGetCharSet = (FcPatternGetCharSetFuncType)dlsym(libfontconfig, "FcPatternGetCharSet");
fcFontSort = (FcFontSortFuncType)dlsym(libfontconfig, "FcFontSort");
fcFontSetDestroy = (FcFontSetDestroyFuncType)dlsym(libfontconfig, "FcFontSetDestroy");
fcCharSetUnion = (FcCharSetUnionFuncType)dlsym(libfontconfig, "FcCharSetUnion");
fcCharSetDestroy = (FcCharSetDestroyFuncType)dlsym(libfontconfig, "FcCharSetDestroy");
fcCharSetSubtractCount = (FcCharSetSubtractCountFuncType)dlsym(libfontconfig, "FcCharSetSubtractCount");
fcGetVersion = (FcGetVersionFuncType)dlsym(libfontconfig, "FcGetVersion");
fcConfigGetCacheDirs = (FcConfigGetCacheDirsFuncType)dlsym(libfontconfig, "FcConfigGetCacheDirs");
fcStrListNext = (FcStrListNextFuncType)dlsym(libfontconfig, "FcStrListNext");
fcStrListDone = (FcStrListDoneFuncType)dlsym(libfontconfig, "FcStrListDone");
fcPatternFormat = (FcPatternFormatFuncType)dlsym(libfontconfig, "FcPatternFormat");
fcStrFree = (FcStrFreeFuncType)dlsym(libfontconfig, "FcStrFree");
if (fcPatternBuild == NULL || fcObjectSetBuild == NULL || fcFontList == NULL || fcStrDirname == NULL ||
fcObjectSetDestroy == NULL || fcPatternGetBool == NULL || fcPatternGetInteger == NULL || fcNameParse == NULL ||
fcPatternAddString == NULL || fcConfigSubstitute == NULL || fcDefaultSubstitute == NULL || fcFontMatch == NULL ||
fcPatternGetString == NULL || fcPatternDestroy == NULL || fcPatternGetCharSet == NULL || fcFontSort == NULL ||
fcFontSetDestroy == NULL || fcCharSetUnion == NULL || fcCharSetDestroy == NULL || fcCharSetSubtractCount == NULL ||
fcGetVersion == NULL || fcConfigGetCacheDirs == NULL || fcStrListNext == NULL || fcStrListDone == NULL ||
fcPatternAddDouble == NULL || fcPatternFormat == NULL || fcStrFree == NULL) {
closeFontConfig();
}
}
JNIEXPORT void JNICALL
JNI_OnUnload(JavaVM *vm, void *reserved) {
closeFontConfig();
}
JNIEXPORT char **getFontConfigLocations() {
char **fontdirs;
int numdirs = 0;
FcPattern *pattern;
FcObjectSet *objset;
FcFontSet *fontSet;
int i, f, found;
/* Make calls into the fontconfig library to build a search for
* outline fonts, and to get the set of full file paths from the matches.
* This set is returned from the call to fcFontList(..)
* We allocate an array of char* pointers sufficient to hold all
* the matches + 1 extra which ensures there will be a NULL after all
* valid entries.
* We call fcStrDirname strip the file name from the path, and
* check if we have yet seen this directory. If not we add a pointer to
* it into our array of char*. Note that fcStrDirname returns newly
* allocated storage so we can use this in the return char** value.
* Finally we clean up, freeing allocated resources, and return the
* array of unique directories.
*/
pattern = (*fcPatternBuild)(NULL, FC_OUTLINE, FcTypeBool, FcTrue, NULL);
objset = (*fcObjectSetBuild)(FC_FILE, NULL);
fontSet = (*fcFontList)(NULL, pattern, objset);
if (fontSet == NULL) {
/* fcFontList() may return NULL if fonts are not installed. */
fontdirs = NULL;
} else {
fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
if (fontdirs == NULL) {
(*fcFontSetDestroy)(fontSet);
goto cleanup;
}
for (f=0; f < fontSet->nfont; f++) {
FcChar8 *file;
FcChar8 *dir;
if ((*fcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) == FcResultMatch) {
dir = (*fcStrDirname)(file);
found = 0;
for (i=0;i<numdirs; i++) {
if (strcmp(fontdirs[i], (char*)dir) == 0) {
found = 1;
break;
}
}
if (!found) {
fontdirs[numdirs++] = (char*)dir;
} else {
free((char*)dir);
}
}
}
/* Free fontset if one was returned */
(*fcFontSetDestroy)(fontSet);
}
cleanup:
/* Free memory and close the ".so" */
(*fcObjectSetDestroy)(objset);
(*fcPatternDestroy)(pattern);
return fontdirs;
}
/* These are copied from sun.awt.SunHints.
* Consider initialising them as ints using JNI for more robustness.
*/
#define TEXT_AA_OFF 1
#define TEXT_AA_ON 2
#define TEXT_AA_LCD_HRGB 4
#define TEXT_AA_LCD_HBGR 5
#define TEXT_AA_LCD_VRGB 6
#define TEXT_AA_LCD_VBGR 7
static void setRenderingFontHintsField(FcPattern* matchPattern, const char* property, int* value) {
if (FcResultMatch != (*fcPatternGetBool)(matchPattern, property, 0, value)) {
*value = -1;
}
}
JNIEXPORT int setupRenderingFontHints
(const char* fcName, const char* locale, double size, RenderingFontHints *renderingFontHints) {
FcPattern *pattern, *matchPattern;
FcResult result;
if (fcName == NULL) {
return -1;
}
pattern = (*fcNameParse)((FcChar8 *)fcName);
if (locale != NULL) {
(*fcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale);
}
if (size != 0) {
(*fcPatternAddDouble)(pattern, FC_SIZE, size);
}
(*fcConfigSubstitute)(NULL, pattern, FcMatchPattern);
(*fcDefaultSubstitute)(pattern);
matchPattern = (*fcFontMatch)(NULL, pattern, &result);
/* Perhaps should call FcFontRenderPrepare() here as some pattern
* elements might change as a result of that call, but I'm not seeing
* any difference in testing.
*/
if (matchPattern) {
// Extract values from result
setRenderingFontHintsField(matchPattern, FC_HINTING, &renderingFontHints->fcHinting);
setRenderingFontHintsField(matchPattern, FC_HINT_STYLE, &renderingFontHints->fcHintStyle);
setRenderingFontHintsField(matchPattern, FC_ANTIALIAS, &renderingFontHints->fcAntialias);
setRenderingFontHintsField(matchPattern, FC_AUTOHINT, &renderingFontHints->fcAutohint);
setRenderingFontHintsField(matchPattern, FC_LCD_FILTER, &renderingFontHints->fcRGBA);
setRenderingFontHintsField(matchPattern, FC_RGBA, &renderingFontHints->fcLCDFilter);
(*fcPatternDestroy)(matchPattern);
}
(*fcPatternDestroy)(pattern);
return 0;
}
JNIEXPORT jint JNICALL
Java_sun_font_FontConfigManager_getFontConfigVersion
(JNIEnv *env, jclass obj) {
return (*fcGetVersion)();
}
JNIEXPORT void JNICALL
Java_sun_font_FontConfigManager_setupFontConfigFonts
(JNIEnv *env, jclass obj, jstring localeStr, jobject fcInfoObj,
jobjectArray fcCompFontArray, jboolean includeFallbacks) {
int i, arrlen;
jobject fcCompFontObj;
jstring fcNameStr, jstr;
const char *locale, *fcName;
FcPattern *pattern;
FcResult result;
jfieldID fcNameID, fcFirstFontID, fcAllFontsID, fcVersionID, fcCacheDirsID;
jfieldID familyNameID, styleNameID, fullNameID, fontFileID;
jmethodID fcFontCons;
char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS");
jclass fcInfoClass;
jclass fcCompFontClass;
jclass fcFontClass;
CHECK_NULL(fcInfoObj);
CHECK_NULL(fcCompFontArray);
fcInfoClass = (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo");
CHECK_NULL(fcInfoClass);
fcCompFontClass = (*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont");
CHECK_NULL(fcCompFontClass);
fcFontClass = (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont");
CHECK_NULL(fcFontClass);
CHECK_NULL(fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I"));
CHECK_NULL(fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs", "[Ljava/lang/String;"));
CHECK_NULL(fcNameID = (*env)->GetFieldID(env, fcCompFontClass, "fcName", "Ljava/lang/String;"));
CHECK_NULL(fcFirstFontID = (*env)->GetFieldID(env, fcCompFontClass, "firstFont", "Lsun/font/FontConfigManager$FontConfigFont;"));
CHECK_NULL(fcAllFontsID = (*env)->GetFieldID(env, fcCompFontClass, "allFonts", "[Lsun/font/FontConfigManager$FontConfigFont;"));
CHECK_NULL(fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V"));
CHECK_NULL(familyNameID = (*env)->GetFieldID(env, fcFontClass, "familyName", "Ljava/lang/String;"));
CHECK_NULL(styleNameID = (*env)->GetFieldID(env, fcFontClass, "styleStr", "Ljava/lang/String;"));
CHECK_NULL(fullNameID = (*env)->GetFieldID(env, fcFontClass, "fullName", "Ljava/lang/String;"));
CHECK_NULL(fontFileID = (*env)->GetFieldID(env, fcFontClass, "fontFile", "Ljava/lang/String;"));
(*env)->SetIntField(env, fcInfoObj, fcVersionID, (*fcGetVersion)());
/* Optionally get the cache dir locations. This isn't
* available until v 2.4.x, but this is OK since on those later versions
* we can check the time stamps on the cache dirs to see if we
* are out of date. There are a couple of assumptions here. First
* that the time stamp on the directory changes when the contents are
* updated. Secondly that the locations don't change. The latter is
* most likely if a new version of fontconfig is installed, but we also
* invalidate the cache if we detect that. Arguably even that is "rare",
* and most likely is tied to an OS upgrade which gets a new file anyway.
*/
if (fcStrListNext != NULL && fcStrListDone != NULL &&
fcConfigGetCacheDirs != NULL) {
FcStrList* cacheDirs;
FcChar8* cacheDir;
int cnt = 0;
jobject cacheDirArray = (*env)->GetObjectField(env, fcInfoObj, fcCacheDirsID);
int max = (*env)->GetArrayLength(env, cacheDirArray);
cacheDirs = (*fcConfigGetCacheDirs)(NULL);
if (cacheDirs != NULL) {
while ((cnt < max) && (cacheDir = (*fcStrListNext)(cacheDirs))) {
jstr = (*env)->NewStringUTF(env, (const char*)cacheDir);
if (IS_NULL(jstr)) {
(*fcStrListDone)(cacheDirs);
return;
}
(*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr);
(*env)->DeleteLocalRef(env, jstr);
}
(*fcStrListDone)(cacheDirs);
}
}
locale = (*env)->GetStringUTFChars(env, localeStr, 0);
if (locale == NULL) {
(*env)->ExceptionClear(env);
JNU_ThrowOutOfMemoryError(env, "Could not create locale");
return;
}
arrlen = (*env)->GetArrayLength(env, fcCompFontArray);
for (i=0; i<arrlen; i++) {
FcFontSet* fontset;
int fn, j, fontCount, nfonts;
unsigned int minGlyphs;
FcChar8 **family, **styleStr, **fullname, **file;
jarray fcFontArr = NULL;
FcCharSet *unionCharset = NULL;
FcCharSet *prevUnionCharset = NULL;
fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i);
fcNameStr =
(jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID));
fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0);
if (fcName == NULL) {
(*env)->DeleteLocalRef(env, fcCompFontObj);
(*env)->DeleteLocalRef(env, fcNameStr);
continue;
}
pattern = (*fcNameParse)((FcChar8 *)fcName);
(*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
(*env)->DeleteLocalRef(env, fcNameStr);
if (pattern == NULL) {
if (locale) {
(*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
}
return;
}
/* locale may not usually be necessary as fontconfig appears to apply
* this anyway based on the user's environment. However we want
* to use the value of the JDK startup locale so this should take
* care of it.
*/
if (locale != NULL) {
(*fcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale);
}
(*fcConfigSubstitute)(NULL, pattern, FcMatchPattern);
(*fcDefaultSubstitute)(pattern);
fontset = (*fcFontSort)(NULL, pattern, FcTrue, NULL, &result);
if (fontset == NULL) {
(*fcPatternDestroy)(pattern);
if (locale) {
(*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
}
return;
}
/* fontconfig returned us "nfonts". If we are just getting the
* first font, we set nfont to zero. Otherwise we use "nfonts".
* Next create separate C arrays of length nfonts for family file etc.
* Inspect the returned fonts and the ones we like (adds enough glyphs)
* are added to the arrays and we increment 'fontCount'.
*/
nfonts = fontset->nfont;
family = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
styleStr = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
fullname = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
file = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
if (family == NULL || styleStr == NULL ||
fullname == NULL || file == NULL) {
if (family != NULL) {
free(family);
}
if (styleStr != NULL) {
free(styleStr);
}
if (fullname != NULL) {
free(fullname);
}
if (file != NULL) {
free(file);
}
(*fcPatternDestroy)(pattern);
(*fcFontSetDestroy)(fontset);
if (locale) {
(*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
}
return;
}
fontCount = 0;
minGlyphs = 20;
if (debugMinGlyphsStr != NULL) {
int val = minGlyphs;
sscanf(debugMinGlyphsStr, "%5d", &val);
if (val >= 0 && val <= 65536) {
minGlyphs = val;
}
}
for (j=0; j<nfonts; j++) {
FcPattern *fontPattern = fontset->fonts[j];
FcChar8 *fontformat;
FcCharSet *charset = NULL;
fontformat = NULL;
(*fcPatternGetString)(fontPattern, FC_FONTFORMAT, 0, &fontformat);
/* We only want TrueType fonts but some Linuxes still depend
* on Type 1 fonts for some Locale support, so we'll allow
* them there.
*/
if (fontformat != NULL
&& (strcmp((char*)fontformat, "TrueType") != 0)
#if defined(__linux__) || defined(_AIX)
&& (strcmp((char*)fontformat, "Type 1") != 0)
&& (strcmp((char*)fontformat, "CFF") != 0)
#endif
) {
continue;
}
result = (*fcPatternGetCharSet)(fontPattern, FC_CHARSET, 0, &charset);
if (result != FcResultMatch) {
free(family);
free(fullname);
free(styleStr);
free(file);
(*fcPatternDestroy)(pattern);
(*fcFontSetDestroy)(fontset);
if (prevUnionCharset != NULL) {
(*fcCharSetDestroy)(prevUnionCharset);
}
if (locale) {
(*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
}
return;
}
/* We don't want 20 or 30 fonts, so once we hit 10 fonts,
* then require that they really be adding value. Too many
* adversely affects load time for minimal value-add.
* This is still likely far more than we've had in the past.
*/
if (j==10) {
minGlyphs = 50;
}
if (unionCharset == NULL) {
unionCharset = charset;
} else {
if ((*fcCharSetSubtractCount)(charset, unionCharset)
> minGlyphs) {
unionCharset = (* fcCharSetUnion)(unionCharset, charset);
if (prevUnionCharset != NULL) {
(*fcCharSetDestroy)(prevUnionCharset);
}
prevUnionCharset = unionCharset;
} else {
continue;
}
}
fontCount++; // found a font we will use.
(*fcPatternGetString)(fontPattern, FC_FILE, 0, &file[j]);
(*fcPatternGetString)(fontPattern, FC_FAMILY, 0, &family[j]);
(*fcPatternGetString)(fontPattern, FC_STYLE, 0, &styleStr[j]);
(*fcPatternGetString)(fontPattern, FC_FULLNAME, 0, &fullname[j]);
if (!includeFallbacks) {
break;
}
if (fontCount == 254) {
break; // CompositeFont will only use up to 254 slots from here.
}
}
// Release last instance of CharSet union
if (prevUnionCharset != NULL) {
(*fcCharSetDestroy)(prevUnionCharset);
}
/* Once we get here 'fontCount' is the number of returned fonts
* we actually want to use, so we create 'fcFontArr' of that length.
* The non-null entries of "family[]" etc are those fonts.
* Then loop again over all nfonts adding just those non-null ones
* to 'fcFontArr'. If its null (we didn't want the font)
* then we don't enter the main body.
* So we should never get more than 'fontCount' entries.
*/
if (includeFallbacks) {
fcFontArr =
(*env)->NewObjectArray(env, fontCount, fcFontClass, NULL);
if (IS_NULL(fcFontArr)) {
free(family);
free(fullname);
free(styleStr);
free(file);
(*fcPatternDestroy)(pattern);
(*fcFontSetDestroy)(fontset);
if (locale) {
(*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
}
return;
}
(*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr);
}
fn=0;
for (j=0;j<nfonts;j++) {
if (family[j] != NULL) {
jobject fcFont = (*env)->NewObject(env, fcFontClass, fcFontCons);
if (IS_NULL(fcFont)) break;
jstr = (*env)->NewStringUTF(env, (const char*)family[j]);
if (IS_NULL(jstr)) break;
(*env)->SetObjectField(env, fcFont, familyNameID, jstr);
(*env)->DeleteLocalRef(env, jstr);
if (file[j] != NULL) {
jstr = (*env)->NewStringUTF(env, (const char*)file[j]);
if (IS_NULL(jstr)) break;
(*env)->SetObjectField(env, fcFont, fontFileID, jstr);
(*env)->DeleteLocalRef(env, jstr);
}
if (styleStr[j] != NULL) {
jstr = (*env)->NewStringUTF(env, (const char*)styleStr[j]);
if (IS_NULL(jstr)) break;
(*env)->SetObjectField(env, fcFont, styleNameID, jstr);
(*env)->DeleteLocalRef(env, jstr);
}
if (fullname[j] != NULL) {
jstr = (*env)->NewStringUTF(env, (const char*)fullname[j]);
if (IS_NULL(jstr)) break;
(*env)->SetObjectField(env, fcFont, fullNameID, jstr);
(*env)->DeleteLocalRef(env, jstr);
}
if (fn==0) {
(*env)->SetObjectField(env, fcCompFontObj,
fcFirstFontID, fcFont);
}
if (includeFallbacks) {
(*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont);
} else {
(*env)->DeleteLocalRef(env, fcFont);
break;
}
(*env)->DeleteLocalRef(env, fcFont);
}
}
if (includeFallbacks) {
(*env)->DeleteLocalRef(env, fcFontArr);
}
(*env)->DeleteLocalRef(env, fcCompFontObj);
(*fcFontSetDestroy)(fontset);
(*fcPatternDestroy)(pattern);
free(family);
free(styleStr);
free(fullname);
free(file);
}
/* release resources and close the ".so" */
if (locale) {
(*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
}
}
JNIEXPORT jint JNICALL
Java_sun_font_FontConfigManager_getFontConfigAASettings
(JNIEnv *env, jclass obj, jstring fcNameStr, jstring localeStr) {
int rgba = 0;
const char *locale=NULL, *fcName=NULL;
if (fcNameStr == NULL || localeStr == NULL) {
return -1;
}
fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0);
locale = (*env)->GetStringUTFChars(env, localeStr, 0);
int status = 0;
RenderingFontHints renderingFontHints;
if (fcName && locale) {
status = setupRenderingFontHints(fcName, locale, 0, &renderingFontHints);
} else {
status = -1;
}
if (locale) {
(*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
}
if (fcName) {
(*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
}
if (status) {
return status;
}
if (renderingFontHints.fcAntialias == FcFalse) {
return TEXT_AA_OFF;
} else if (renderingFontHints.fcRGBA <= FC_RGBA_UNKNOWN || renderingFontHints.fcRGBA >= FC_RGBA_NONE) {
return TEXT_AA_ON;
} else {
switch (renderingFontHints.fcRGBA) {
case FC_RGBA_RGB : return TEXT_AA_LCD_HRGB;
case FC_RGBA_BGR : return TEXT_AA_LCD_HBGR;
case FC_RGBA_VRGB : return TEXT_AA_LCD_VRGB;
case FC_RGBA_VBGR : return TEXT_AA_LCD_VBGR;
default : return TEXT_AA_LCD_HRGB; // should not get here.
}
}
}
JNIEXPORT jstring JNICALL
Java_sun_font_FontConfigManager_getFontProperty
(JNIEnv *env, jclass obj, jstring query, jstring property) {
const char *queryPtr = NULL;
const char *propertyPtr = NULL;
FcChar8 *fontFamily = NULL;
FcChar8 *fontPath = NULL;
jstring res = NULL;
queryPtr = (*env)->GetStringUTFChars(env, query, 0);
propertyPtr = (*env)->GetStringUTFChars(env, property, 0);
if (queryPtr == NULL || propertyPtr == NULL) {
goto cleanup;
}
FcPattern *pattern = (*fcNameParse)((FcChar8 *) queryPtr);
if (pattern == NULL) {
goto cleanup;
}
(*fcConfigSubstitute)(NULL, pattern, FcMatchScan);
(*fcDefaultSubstitute)(pattern);
FcResult fcResult;
FcPattern *match = (*fcFontMatch)(0, pattern, &fcResult);
if (match == NULL || fcResult != FcResultMatch) {
goto cleanup;
}
fontFamily = (*fcPatternFormat)(match, (FcChar8*) "%{family}");
if (fontFamily == NULL) {
goto cleanup;
}
// result of foundFontName could be set of families, so we left only first family
char *commaPos = strchr((char *) fontFamily, ',');
if (commaPos != NULL) {
*commaPos = '\0';
}
if (strstr(queryPtr, (char *) fontFamily) == NULL) {
goto cleanup;
}
fontPath = (*fcPatternFormat)(match, (FcChar8*) propertyPtr);
if (fontPath == NULL) {
goto cleanup;
}
res = (*env)->NewStringUTF(env, (char *) fontPath);
cleanup:
if (fontPath) {
(*fcStrFree)(fontPath);
}
if (fontFamily) {
(*fcStrFree)(fontFamily);
}
if (propertyPtr) {
(*env)->ReleaseStringUTFChars(env, property, (const char*)propertyPtr);
}
if (queryPtr) {
(*env)->ReleaseStringUTFChars(env, query, (const char*)queryPtr);
}
return res;
}

File diff suppressed because it is too large Load Diff

View File

@@ -68,12 +68,8 @@
#endif
#ifndef DISABLE_FONTCONFIG
/* Use bundled fontconfig.h for now */
#include "fontconfig.h"
#endif
#ifndef FC_LCD_FILTER
#define FC_LCD_FILTER "lcdfilter"
#include "fontconfigmanager.h"
#include <fontconfig/fontconfig.h>
#endif
#ifndef FC_LCD_NONE
@@ -101,16 +97,8 @@
#define FT26Dot6ToIntRound(x) (((int)(x + (1 << 5))) >> 6)
#define FT26Dot6ToIntCeil(x) (((int)(x - 1 + (1 << 6))) >> 6)
#define IntToFT26Dot6(x) (((FT_Fixed)(x)) << 6)
#define DEFAULT_DPI 72
#define MAX_DPI 1024
#define ADJUST_FONT_SIZE(X, DPI) (((X)*DEFAULT_DPI + ((DPI)>>1))/(DPI))
#define FLOOR_DIV(X, Y) ((X) >= 0 ? (X) / (Y) : ((X) - (Y) + 1) / (Y))
#ifndef DISABLE_FONTCONFIG
#define FONTCONFIG_DLL JNI_LIB_NAME("fontconfig")
#define FONTCONFIG_DLL_VERSIONED VERSIONED_JNI_LIB_NAME("fontconfig", "1")
#endif
#ifndef FALSE
#define FALSE 0
#endif
@@ -216,78 +204,14 @@ static jmethodID invalidateScalerMID;
static jboolean debugFonts; // Stores the value of FontUtilities.debugFonts()
static jmethodID getDefaultToolkitMID;
static jclass tkClass;
static jmethodID getScreenResolutionMID;
static jfieldID platNameFID;
static jfieldID familyNameFID;
#ifndef DISABLE_FONTCONFIG
typedef FcBool (*FcPatternAddPtrType) (FcPattern *p, const char *object, FcValue value, FcBool append);
typedef FcBool (*FcPatternAddBoolPtrType) (FcPattern *p, const char *object, FcBool b);
typedef FcBool (*FcPatternAddDoublePtrType) (FcPattern *p, const char *object, double d);
typedef FcBool (*FcConfigSubstitutePtrType) (FcConfig *config, FcPattern *p, FcMatchKind kind);
typedef void (*FcDefaultSubstitutePtrType) (FcPattern *pattern);
typedef FcPattern* (*FcPatternCreatePtrType) ();
typedef FcPattern* (*FcFontMatchPtrType) (FcConfig *config, FcPattern *p, FcResult *result);
typedef void (*FcPatternDestroyPtrType) (FcPattern *p);
typedef FcResult (*FcPatternGetBoolPtrType) (const FcPattern *p, const char *object, int n, FcBool *b);
typedef FcResult (*FcPatternGetIntegerPtrType) (const FcPattern *p, const char *object, int n, int *i);
typedef FT_Error (*FtLibrarySetLcdFilterPtrType) (FT_Library library, FT_LcdFilter filter);
typedef FcBool (*FcConfigParseAndLoadPtrType) (FcConfig *config, const FcChar8 *file, FcBool complain);
typedef FcBool (*FcConfigSetCurrentPtrType) (FcConfig *config);
typedef FcConfig * (*FcInitLoadConfigAndFontsPtrType)();
typedef int (*FcGetVersionPtrType)();
#endif
static void *libFontConfig = NULL;
static jboolean logFC = JNI_FALSE;
static jboolean logFFS = JNI_FALSE;
#ifndef DISABLE_FONTCONFIG
static FcPatternAddPtrType FcPatternAddPtr;
static FcPatternAddBoolPtrType FcPatternAddBoolPtr;
static FcPatternAddDoublePtrType FcPatternAddDoublePtr;
static FcConfigSubstitutePtrType FcConfigSubstitutePtr;
static FcDefaultSubstitutePtrType FcDefaultSubstitutePtr;
static FcPatternCreatePtrType FcPatternCreatePtr;
static FcFontMatchPtrType FcFontMatchPtr;
static FcPatternDestroyPtrType FcPatternDestroyPtr;
static FcPatternGetBoolPtrType FcPatternGetBoolPtr;
static FcPatternGetIntegerPtrType FcPatternGetIntegerPtr;
static FcConfigParseAndLoadPtrType FcConfigParseAndLoadPtr;
static FcConfigSetCurrentPtrType FcConfigSetCurrentPtr;
static FcInitLoadConfigAndFontsPtrType FcInitLoadConfigAndFontsPtr;
static FcGetVersionPtrType FcGetVersionPtr;
#endif
static FT_UnitVector subpixelGlyphResolution;
static void* openFontConfig() {
void* libfontconfig = NULL;
#ifndef DISABLE_FONTCONFIG
char *fcLogEnabled = getenv("OPENJDK_FFS_LOG_FC");
if (fcLogEnabled != NULL && !strcmp(fcLogEnabled, "yes")) {
logFC = JNI_TRUE;
}
char *useFC = getenv("OPENJDK_FFS_USE_FC");
if (useFC != NULL && !strcmp(useFC, "no")) {
if (logFC) fprintf(stderr, "FC_LOG: fontconfig disabled in freetypescaler\n");
return NULL;
}
libfontconfig = dlopen(FONTCONFIG_DLL_VERSIONED, RTLD_LOCAL | RTLD_LAZY);
if (libfontconfig == NULL) {
libfontconfig = dlopen(FONTCONFIG_DLL, RTLD_LOCAL | RTLD_LAZY);
if (libfontconfig == NULL) {
if (logFC) fprintf(stderr, "FC_LOG: cannot open %s\n", FONTCONFIG_DLL);
return NULL;
}
}
#endif
return libfontconfig;
}
JNIEXPORT void JNICALL
Java_sun_font_FreetypeFontScaler_initIDs(
JNIEnv *env, jobject scaler, jclass FFSClass, jclass TKClass,
@@ -316,57 +240,13 @@ Java_sun_font_FreetypeFontScaler_initIDs(
getDefaultToolkitMID =
(*env)->GetStaticMethodID(env, TKClass, "getDefaultToolkit",
"()Ljava/awt/Toolkit;");
getScreenResolutionMID =
(*env)->GetMethodID(env, TKClass, "getScreenResolution", "()I");
tkClass = (*env)->NewGlobalRef(env, TKClass);
platNameFID = (*env)->GetFieldID(env, PFClass, "platName", "Ljava/lang/String;");
familyNameFID = (*env)->GetFieldID(env, PFClass, "familyName", "Ljava/lang/String;");
libFontConfig = openFontConfig();
#ifndef DISABLE_FONTCONFIG
if (libFontConfig) {
FcConfig* fcConfig;
FcBool result;
FcPatternAddPtr = (FcPatternAddPtrType) dlsym(libFontConfig, "FcPatternAdd");
FcPatternAddBoolPtr = (FcPatternAddBoolPtrType) dlsym(libFontConfig, "FcPatternAddBool");
FcPatternAddDoublePtr = (FcPatternAddDoublePtrType) dlsym(libFontConfig, "FcPatternAddDouble");
FcConfigSubstitutePtr = (FcConfigSubstitutePtrType) dlsym(libFontConfig, "FcConfigSubstitute");
FcDefaultSubstitutePtr = (FcDefaultSubstitutePtrType) dlsym(libFontConfig, "FcDefaultSubstitute");
FcPatternCreatePtr = (FcPatternCreatePtrType) dlsym(libFontConfig, "FcPatternCreate");
FcFontMatchPtr = (FcFontMatchPtrType) dlsym(libFontConfig, "FcFontMatch");
FcPatternDestroyPtr = (FcPatternDestroyPtrType) dlsym(libFontConfig, "FcPatternDestroy");
FcPatternGetBoolPtr = (FcPatternGetBoolPtrType) dlsym(libFontConfig, "FcPatternGetBool");
FcPatternGetIntegerPtr = (FcPatternGetIntegerPtrType) dlsym(libFontConfig, "FcPatternGetInteger");
FcConfigParseAndLoadPtr = (FcConfigParseAndLoadPtrType) dlsym(libFontConfig, "FcConfigParseAndLoad");
FcConfigSetCurrentPtr = (FcConfigSetCurrentPtrType) dlsym(libFontConfig, "FcConfigSetCurrent");
FcInitLoadConfigAndFontsPtr = (FcInitLoadConfigAndFontsPtrType) dlsym(libFontConfig, "FcInitLoadConfigAndFonts");
FcGetVersionPtr = (FcGetVersionPtrType) dlsym(libFontConfig, "FcGetVersion");
if (logFC) fprintf(stderr, "FC_LOG: fontconfig version %d \n", (*FcGetVersionPtr)());
fcConfig = (*FcInitLoadConfigAndFontsPtr)();
if (fcConfig != NULL && fontConf != NULL) {
result = (*FcConfigParseAndLoadPtr)(fcConfig, (const FcChar8 *) fontConf, FcFalse);
if (logFC) fprintf(stderr, "FC_LOG: FcConfigParseAndLoad %d \n", result);
result = (*FcConfigSetCurrentPtr)(fcConfig);
if (logFC) fprintf(stderr, "FC_LOG: FcConfigSetCurrent %d \n", result);
}
else {
if (logFC) {
if (fontConf) {
fprintf(stderr, "FC_LOG: FcInitLoadConfigAndFonts failed\n");
}
else {
fprintf(stderr, "FC_LOG: FcInitLoadConfigAndFonts disabled\n");
}
}
}
}
#endif
if (fontConf) {
(*env)->ReleaseStringUTFChars(env, jreFontConfName, fontConf);
}
}
typedef FT_Error (*FtLibrarySetLcdFilterPtrType) (FT_Library library, FT_LcdFilter filter);
static FT_Error FT_Library_SetLcdFilter_Proxy(FT_Library library, FT_LcdFilter filter) {
#ifndef DISABLE_FONTCONFIG
static FtLibrarySetLcdFilterPtrType FtLibrarySetLcdFilterPtr = NULL;
@@ -389,46 +269,6 @@ static FT_Error FT_Library_SetLcdFilter_Proxy(FT_Library library, FT_LcdFilter
#endif
}
static int getScreenResolution(JNIEnv *env) {
/*
* Actual screen dpi is necessary only for fontconfig requests
*/
#ifndef DISABLE_FONTCONFIG
jthrowable exc;
jclass tk = (*env)->CallStaticObjectMethod(
env, tkClass, getDefaultToolkitMID);
exc = (*env)->ExceptionOccurred(env);
if (exc) {
(*env)->ExceptionClear(env);
return DEFAULT_DPI;
}
int dpi = (*env)->CallIntMethod(env, tk, getScreenResolutionMID);
/* Test if there is no exception here (can get java.awt.HeadlessException)
* Fallback to default DPI otherwise
*/
exc = (*env)->ExceptionOccurred(env);
if (exc) {
(*env)->ExceptionClear(env);
return DEFAULT_DPI;
}
/* Some configurations report invalid dpi settings */
if (dpi > MAX_DPI) {
if (logFFS) {
fprintf(stderr, "FFS_LOG: Invalid dpi reported (%d) replaced with default (%d)\n", dpi, DEFAULT_DPI);
}
return DEFAULT_DPI;
}
if (logFFS) {
fprintf(stderr, "FFS_LOG: Screen Resolution (%d) dpi\n", dpi);
}
return dpi;
#else
return DEFAULT_DPI;
#endif
}
static void freeNativeResources(JNIEnv *env, FTScalerInfo* scalerInfo) {
if (scalerInfo == NULL)
@@ -957,25 +797,32 @@ static void setDefaultScalerSettings(FTScalerContext *context) {
context->renderFlags = FT_LOAD_TARGET_MODE(context->loadFlags);
}
#ifndef DISABLE_FONTCONFIG
static FcBool getRenderingSettingsField(int *target, int value) {
*target = value;
return (value != -1) ? FcTrue : FcFalse;
}
#endif
static int setupFTContext(JNIEnv *env, jobject font2D, FTScalerInfo *scalerInfo, FTScalerContext *context,
FT_Bool configureFont) {
FT_Matrix matrix;
int errCode = 0;
scalerInfo->env = env;
scalerInfo->font2D = font2D;
const char *cfontFamilyName = NULL;
const char *cfontPath = NULL;
jstring jfontFamilyName = NULL;
jstring jfontPath = NULL;
if (context != NULL) {
context->colorFont = FT_HAS_COLOR(scalerInfo->face) || !FT_IS_SCALABLE(scalerInfo->face);
setupTransform(&matrix, context);
FT_Set_Transform(scalerInfo->face, &matrix, NULL);
FT_UInt dpi = (FT_UInt) getScreenResolution(env);
if (FT_IS_SCALABLE(scalerInfo->face)) { // Standard scalable face
context->fixedSizeIndex = -1;
errCode = FT_Set_Char_Size(scalerInfo->face, 0,
ADJUST_FONT_SIZE(context->ptsz, dpi),
dpi, dpi);
} else { // Non-scalable face (that should only be bitmap faces)
const int ptsz = context->ptsz;
// Best size is smallest, but not smaller than requested
@@ -992,35 +839,30 @@ static int setupFTContext(JNIEnv *env, jobject font2D, FTScalerInfo *scalerInfo,
}
}
context->fixedSizeIndex = bestSizeIndex;
errCode = FT_Set_Char_Size(scalerInfo->face, 0,
ADJUST_FONT_SIZE(bestSize, dpi),
dpi, dpi);
}
errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72);
if (errCode) return errCode;
errCode = FT_Activate_Size(scalerInfo->face->size);
if (errCode) return errCode;
if (configureFont) {
context->renderFlags = FT_RENDER_MODE_NORMAL;
context->lcdFilter = FT_LCD_FILTER_NONE;
context->loadFlags = FT_LOAD_DEFAULT;
if (libFontConfig == NULL) {
setDefaultScalerSettings(context);
return 0;
}
#ifndef DISABLE_FONTCONFIG
jstring jfontFamilyName = (*env)->GetObjectField(env, font2D, familyNameFID);
const char *cfontFamilyName = (*env)->GetStringUTFChars(env, jfontFamilyName, NULL);
jfontFamilyName = (*env)->GetObjectField(env, font2D, familyNameFID);
cfontFamilyName = (*env)->GetStringUTFChars(env, jfontFamilyName, NULL);
jfontPath = (*env)->GetObjectField(env, font2D, platNameFID);
cfontPath = (*env)->GetStringUTFChars(env, jfontPath, NULL);
if (logFC) {
jstring jfontPath = (*env)->GetObjectField(env, font2D, platNameFID);
char *cfontPath = (char*)(*env)->GetStringUTFChars(env, jfontPath, NULL);
fprintf(stderr, "FC_LOG: %s %s ", cfontFamilyName, cfontPath);
(*env)->ReleaseStringUTFChars(env, jfontPath, cfontPath);
}
double fcSize = FT26Dot6ToDouble(ADJUST_FONT_SIZE(context->ptsz, dpi));
double fcSize = FT26Dot6ToDouble(context->ptsz);
if (logFC) fprintf(stderr, " size=%f", fcSize);
// Find cached value
@@ -1034,55 +876,33 @@ static int setupFTContext(JNIEnv *env, jobject font2D, FTScalerInfo *scalerInfo,
}
if (cachedMatch.fcSize == 0) {
cachedMatch.fcSize = fcSize;
clock_t begin = logFC ? clock() : 0;
// Setup query
FcPattern *fcPattern = 0;
fcPattern = (*FcPatternCreatePtr)();
FcValue fcValue;
fcValue.type = FcTypeString;
fcValue.u.s = (const FcChar8 *) cfontFamilyName;
(*FcPatternAddPtr)(fcPattern, FC_FAMILY, fcValue, FcTrue);
(*FcPatternAddBoolPtr)(fcPattern, FC_SCALABLE, FcTrue);
(*FcPatternAddDoublePtr)(fcPattern, FC_SIZE, fcSize);
(*FcConfigSubstitutePtr)(0, fcPattern, FcMatchPattern);
(*FcDefaultSubstitutePtr)(fcPattern);
FcResult matchResult = FcResultNoMatch;
// Match on pattern
FcPattern *resultPattern = 0;
resultPattern = (*FcFontMatchPtr)(0, fcPattern, &matchResult);
if (logFC) {
clock_t end = clock();
double time_spent = (double)(end - begin) * 1000.0 / CLOCKS_PER_SEC;
fprintf(stderr, " in %f ms", time_spent);
}
if (matchResult != FcResultMatch) {
(*FcPatternDestroyPtr)(fcPattern);
if (logFC) fprintf(stderr, " - NOT FOUND\n");
RenderingFontHints renderingFontHints;
int status = setupRenderingFontHints(cfontFamilyName, NULL, fcSize, &renderingFontHints);
if (status != 0) {
if (cfontPath) {
(*env)->ReleaseStringUTFChars(env, jfontPath, cfontPath);
}
if (cfontFamilyName) {
(*env)->ReleaseStringUTFChars(env, jfontFamilyName, cfontFamilyName);
}
setDefaultScalerSettings(context);
return 0;
}
(*FcPatternDestroyPtr)(fcPattern);
FcPattern *pattern = resultPattern;
// Extract values from result
cachedMatch.fcHintingSet = (*FcPatternGetBoolPtr)(pattern, FC_HINTING, 0, &cachedMatch.fcHinting) == FcResultMatch;
cachedMatch.fcSize = fcSize;
cachedMatch.fcHintingSet =
getRenderingSettingsField(&cachedMatch.fcHinting, renderingFontHints.fcHinting);
cachedMatch.fcHintStyleSet =
(*FcPatternGetIntegerPtr)(pattern, FC_HINT_STYLE, 0, &cachedMatch.fcHintStyle) == FcResultMatch;
cachedMatch.fcAntialiasSet = (*FcPatternGetBoolPtr)(pattern, FC_ANTIALIAS, 0, &cachedMatch.fcAntialias) == FcResultMatch;
cachedMatch.fcAutohintSet = (*FcPatternGetBoolPtr)(pattern, FC_AUTOHINT, 0, &cachedMatch.fcAutohint) == FcResultMatch;
getRenderingSettingsField(&cachedMatch.fcHintStyle, renderingFontHints.fcHintStyle);
cachedMatch.fcAntialiasSet =
getRenderingSettingsField(&cachedMatch.fcAntialias, renderingFontHints.fcAntialias);
cachedMatch.fcAutohintSet =
getRenderingSettingsField(&cachedMatch.fcAutohint, renderingFontHints.fcAutohint);
cachedMatch.fcLCDFilterSet =
(*FcPatternGetIntegerPtr)(pattern, FC_LCD_FILTER, 0, &cachedMatch.fcLCDFilter) == FcResultMatch;
cachedMatch.fcRGBASet = (*FcPatternGetIntegerPtr)(pattern, FC_RGBA, 0, &cachedMatch.fcRGBA) == FcResultMatch;
(*FcPatternDestroyPtr)(pattern);
getRenderingSettingsField(&cachedMatch.fcRGBA, renderingFontHints.fcRGBA);
cachedMatch.fcRGBASet =
getRenderingSettingsField(&cachedMatch.fcLCDFilter, renderingFontHints.fcLCDFilter);
if (NUM_CACHED_VALUES > 0) {
int nextCacheIdx = scalerInfo->nextCacheIdx;
@@ -1234,8 +1054,14 @@ static int setupFTContext(JNIEnv *env, jobject font2D, FTScalerInfo *scalerInfo,
}
}
(*env)->ReleaseStringUTFChars(env, jfontFamilyName, cfontFamilyName);
if (logFC) fprintf(stderr, "\n");
if (cfontPath) {
(*env)->ReleaseStringUTFChars(env, jfontPath, cfontPath);
}
if (cfontFamilyName) {
(*env)->ReleaseStringUTFChars(env, jfontFamilyName, cfontFamilyName);
}
#endif
}
@@ -2751,13 +2577,4 @@ Java_sun_font_FreetypeFontScaler_getGlyphPointNative(
return (*env)->NewObject(env, sunFontIDs.pt2DFloatClass,
sunFontIDs.pt2DFloatCtr, x, y);
}
JNIEXPORT void JNICALL
JNI_OnUnload(JavaVM *vm, void *reserved) {
if (libFontConfig != NULL) {
#ifndef DISABLE_FONTCONFIG
dlclose(libFontConfig);
#endif
}
}
}

View File

@@ -128,7 +128,7 @@ public class FontConfigManager {
if (FontUtilities.isWindows) {
return null;
} else {
int hint = getFontConfigAASettings(getFCLocaleStr(), fcFamily);
int hint = getFontConfigAASettings(fcFamily);
if (hint < 0) {
return null;
} else {
@@ -188,7 +188,7 @@ public class FontConfigManager {
fontArr[i].jdkName = FontUtilities.mapFcName(fontArr[i].fcFamily);
fontArr[i].style = i % 4; // depends on array order.
}
getFontConfig(getFCLocaleStr(), fcInfo, fontArr, includeFallbacks);
setupFontConfigFonts(getFCLocaleStr(), fcInfo, fontArr, includeFallbacks);
FontConfigFont anyFont = null;
/* If don't find anything (eg no libfontconfig), then just return */
for (int i = 0; i< fontArr.length; i++) {
@@ -432,10 +432,12 @@ public class FontConfigManager {
return fontConfigFonts;
}
public static native String getFontProperty(String name, String pattern);
/* Return an array of FcCompFont structs describing the primary
* font located for each of fontconfig/GTK/Pango's logical font names.
*/
private static native void getFontConfig(String locale,
private static native void setupFontConfigFonts(String locale,
FontConfigInfo fcInfo,
FcCompFont[] fonts,
boolean includeFallbacks);
@@ -454,7 +456,9 @@ public class FontConfigManager {
return fcInfo;
}
private static native int getFontConfigAASettings(String locale, String fcFamily);
private static native int getFontConfigAASettings(String fcFamily, String locale);
public static native String getFontProperty(String name, String pattern);
private static int getFontConfigAASettings(String fcFamily) {
return getFontConfigAASettings(fcFamily, getFCLocaleStr());
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, JetBrains s.r.o.. 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.
*/
#ifndef JETBRAINSRUNTIME_FONTCONFIGMANAGER_H
#define JETBRAINSRUNTIME_FONTCONFIGMANAGER_H
typedef struct RenderingFontHints {
int fcHinting;
int fcHintStyle;
int fcAntialias;
int fcAutohint;
int fcRGBA;
int fcLCDFilter;
} RenderingFontHints;
void openFontConfig();
char **getFontConfigLocations();
int setupRenderingFontHints(const char* fcName, const char* locale, double size, RenderingFontHints *renderingFontHints);
#endif //JETBRAINSRUNTIME_FONTCONFIGMANAGER_H

View File

@@ -32,6 +32,14 @@
#include <jvm.h>
#include "gdefs.h"
#if defined(_WIN32) || defined(MACOSX)
#define DISABLE_FONTCONFIG
#endif
#ifndef DISABLE_FONTCONFIG
#include "fontconfigmanager.h"
#endif
#include <sys/param.h>
#include <sys/utsname.h>
@@ -158,5 +166,8 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
JNIEXPORT jint JNICALL
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
{
#ifndef DISABLE_FONTCONFIG
openFontConfig();
#endif
return AWT_OnLoad(vm, reserved);
}

View File

@@ -0,0 +1,386 @@
/*
* Copyright (c) 1998, 2022, 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.
*/
#if defined(__linux__)
#include <string.h>
#endif /* __linux__ */
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include "fontconfigmanager.h"
#include <jni.h>
#include <jni_util.h>
#include <jvm_md.h>
#include <sizecalc.h>
#ifndef HEADLESS
#include <X11/Xlib.h>
#include <awt.h>
#else
/* locks ought to be included from awt.h */
#define AWT_LOCK()
#define AWT_UNLOCK()
#endif /* !HEADLESS */
#if defined(__linux__) && !defined(MAP_FAILED)
#define MAP_FAILED ((caddr_t)-1)
#endif
#ifndef HEADLESS
extern Display *awt_display;
#endif /* !HEADLESS */
#define FONTCONFIG_DLL_VERSIONED VERSIONED_JNI_LIB_NAME("fontconfig", "1")
#define FONTCONFIG_DLL JNI_LIB_NAME("fontconfig")
#define MAXFDIRS 512 /* Max number of directories that contain fonts */
#if defined( __linux__)
/* All the known interesting locations we have discovered on
* various flavors of Linux
*/
static char *fullLinuxFontPath[] = {
"/usr/X11R6/lib/X11/fonts/TrueType", /* RH 7.1+ */
"/usr/X11R6/lib/X11/fonts/truetype", /* SuSE */
"/usr/X11R6/lib/X11/fonts/tt",
"/usr/X11R6/lib/X11/fonts/TTF",
"/usr/X11R6/lib/X11/fonts/OTF", /* RH 9.0 (but empty!) */
"/usr/share/fonts/ja/TrueType", /* RH 7.2+ */
"/usr/share/fonts/truetype",
"/usr/share/fonts/ko/TrueType", /* RH 9.0 */
"/usr/share/fonts/zh_CN/TrueType", /* RH 9.0 */
"/usr/share/fonts/zh_TW/TrueType", /* RH 9.0 */
"/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType", /* Debian */
"/usr/X11R6/lib/X11/fonts/Type1",
"/usr/share/fonts/default/Type1", /* RH 9.0 */
NULL, /* terminates the list */
};
#elif defined(_AIX)
static char *fullAixFontPath[] = {
"/usr/lpp/X11/lib/X11/fonts/Type1", /* from X11.fnt.iso_T1 */
"/usr/lpp/X11/lib/X11/fonts/TrueType", /* from X11.fnt.ucs.ttf */
NULL, /* terminates the list */
};
#endif
typedef struct {
const char *name[MAXFDIRS];
int num;
} fDirRecord, *fDirRecordPtr;
#ifndef HEADLESS
/*
* Returns True if display is local, False of it's remote.
*/
jboolean isDisplayLocal(JNIEnv *env) {
static jboolean isLocal = False;
static jboolean isLocalSet = False;
jboolean ret;
if (! isLocalSet) {
jclass geCls = (*env)->FindClass(env, "java/awt/GraphicsEnvironment");
CHECK_NULL_RETURN(geCls, JNI_FALSE);
jmethodID getLocalGE = (*env)->GetStaticMethodID(env, geCls,
"getLocalGraphicsEnvironment",
"()Ljava/awt/GraphicsEnvironment;");
CHECK_NULL_RETURN(getLocalGE, JNI_FALSE);
jobject ge = (*env)->CallStaticObjectMethod(env, geCls, getLocalGE);
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
jclass sgeCls = (*env)->FindClass(env,
"sun/java2d/SunGraphicsEnvironment");
CHECK_NULL_RETURN(sgeCls, JNI_FALSE);
if ((*env)->IsInstanceOf(env, ge, sgeCls)) {
jmethodID isDisplayLocal = (*env)->GetMethodID(env, sgeCls,
"isDisplayLocal",
"()Z");
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
isLocal = (*env)->CallBooleanMethod(env, ge, isDisplayLocal);
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
} else {
isLocal = True;
}
isLocalSet = True;
}
return isLocal;
}
static char **getX11FontPath ()
{
char **x11Path, **fontdirs;
int i, pos, slen, nPaths, numDirs;
x11Path = XGetFontPath (awt_display, &nPaths);
/* This isn't ever going to be perfect: the font path may contain
* much we aren't interested in, but the cost should be moderate
* Exclude all directories that contain the strings "Speedo","/F3/",
* "75dpi", "100dpi", "misc" or "bitmap", or don't begin with a "/",
* the last of which should exclude font servers.
* Also exclude the user specific ".gnome*" directories which
* aren't going to contain the system fonts we need.
* Hopefully we are left only with Type1 and TrueType directories.
* It doesn't matter much if there are extraneous directories, it'll just
* cost us a little wasted effort upstream.
*/
fontdirs = (char**)calloc(nPaths+1, sizeof(char*));
if (fontdirs == NULL) {
return NULL;
}
pos = 0;
for (i=0; i < nPaths; i++) {
if (x11Path[i][0] != '/') {
continue;
}
if (strstr(x11Path[i], "/75dpi") != NULL) {
continue;
}
if (strstr(x11Path[i], "/100dpi") != NULL) {
continue;
}
if (strstr(x11Path[i], "/misc") != NULL) {
continue;
}
if (strstr(x11Path[i], "/Speedo") != NULL) {
continue;
}
if (strstr(x11Path[i], ".gnome") != NULL) {
continue;
}
fontdirs[pos] = strdup(x11Path[i]);
slen = strlen(fontdirs[pos]);
if (slen > 0 && fontdirs[pos][slen-1] == '/') {
fontdirs[pos][slen-1] = '\0'; /* null out trailing "/" */
}
pos++;
}
XFreeFontPath(x11Path);
if (pos == 0) {
free(fontdirs);
fontdirs = NULL;
}
return fontdirs;
}
#endif /* !HEADLESS */
#if defined(__linux__)
/* from awt_LoadLibrary.c */
JNIEXPORT jboolean JNICALL AWTIsHeadless();
#endif
/* This eliminates duplicates, at a non-linear but acceptable cost
* since the lists are expected to be reasonably short, and then
* deletes references to non-existent directories, and returns
* a single path consisting of unique font directories.
*/
static char* mergePaths(char **p1, char **p2, char **p3, jboolean noType1) {
int len1=0, len2=0, len3=0, totalLen=0, numDirs=0,
currLen, i, j, found, pathLen=0;
char **ptr, **fontdirs;
char *fontPath = NULL;
if (p1 != NULL) {
ptr = p1;
while (*ptr++ != NULL) len1++;
}
if (p2 != NULL) {
ptr = p2;
while (*ptr++ != NULL) len2++;
}
if (p3 != NULL) {
ptr = p3;
while (*ptr++ != NULL) len3++;
}
totalLen = len1+len2+len3;
fontdirs = (char**)calloc(totalLen, sizeof(char*));
if (fontdirs == NULL) {
return NULL;
}
for (i=0; i < len1; i++) {
if (noType1 && strstr(p1[i], "Type1") != NULL) {
continue;
}
fontdirs[numDirs++] = p1[i];
}
currLen = numDirs; /* only compare against previous path dirs */
for (i=0; i < len2; i++) {
if (noType1 && strstr(p2[i], "Type1") != NULL) {
continue;
}
found = 0;
for (j=0; j < currLen; j++) {
if (strcmp(fontdirs[j], p2[i]) == 0) {
found = 1;
break;
}
}
if (!found) {
fontdirs[numDirs++] = p2[i];
}
}
currLen = numDirs; /* only compare against previous path dirs */
for (i=0; i < len3; i++) {
if (noType1 && strstr(p3[i], "Type1") != NULL) {
continue;
}
found = 0;
for (j=0; j < currLen; j++) {
if (strcmp(fontdirs[j], p3[i]) == 0) {
found = 1;
break;
}
}
if (!found) {
fontdirs[numDirs++] = p3[i];
}
}
/* Now fontdirs contains unique dirs and numDirs records how many.
* What we don't know is if they all exist. On reflection I think
* this isn't an issue, so for now I will return all these locations,
* converted to one string */
for (i=0; i<numDirs; i++) {
pathLen += (strlen(fontdirs[i]) + 1);
}
if (pathLen > 0 && (fontPath = malloc(pathLen))) {
*fontPath = '\0';
for (i = 0; i<numDirs; i++) {
if (i != 0) {
strcat(fontPath, ":");
}
strcat(fontPath, fontdirs[i]);
}
}
free (fontdirs);
return fontPath;
}
/*
* The goal of this function is to find all "system" fonts which
* are needed by the JRE to display text in supported locales etc, and
* to support APIs which allow users to enumerate all system fonts and use
* them from their Java applications.
* The preferred mechanism is now using the new "fontconfig" library
* This exists on newer versions of Linux and Solaris (S10 and above)
* The library is dynamically located. The results are merged with
* a set of "known" locations and with the X11 font path, if running in
* a local X11 environment.
* The hardwired paths are built into the JDK binary so as new font locations
* are created on a host platform for them to be located by the JRE they will
* need to be added ito the host's font configuration database, typically
* /etc/fonts/local.conf, and to ensure that directory contains a fonts.dir
* NB: Fontconfig also depends heavily for performance on the host O/S
* maintaining up to date caches.
* This is consistent with the requirements of the desktop environments
* on these OSes.
* 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, jboolean isX11) {
char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL;
/* As of 1.5 we try to use fontconfig on both Solaris and Linux.
* If its not available NULL is returned.
*/
fcdirs = getFontConfigLocations();
#if defined(__linux__)
knowndirs = fullLinuxFontPath;
#elif defined(_AIX)
knowndirs = fullAixFontPath;
#endif
/* REMIND: this code requires to be executed when the GraphicsEnvironment
* is already initialised. That is always true, but if it were not so,
* this code could throw an exception and the fontpath would fail to
* 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 */
#endif
/* Using the X11 font path to locate font files is now a fallback
* useful only if fontconfig failed, or is incomplete. So we could
* remove this code completely and the consequences should be rare
* and non-fatal. If this happens, then the calling Java code can
* be modified to no longer require that the AWT lock (the X11GE)
* be initialised prior to calling this code.
*/
AWT_LOCK();
if (isDisplayLocal(env)) {
x11dirs = getX11FontPath();
}
AWT_UNLOCK();
#if defined(__linux__)
}
#endif
}
#endif /* !HEADLESS */
path = mergePaths(fcdirs, x11dirs, knowndirs, noType1);
if (fcdirs != NULL) {
char **p = fcdirs;
while (*p != NULL) free(*p++);
free(fcdirs);
}
if (x11dirs != NULL) {
char **p = x11dirs;
while (*p != NULL) free(*p++);
free(x11dirs);
}
return path;
}
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, isX11);
}
ret = (*env)->NewStringUTF(env, ptr);
return ret;
}