8167103: Intermittent font loading failure on macOS with JFXPanel application

Reviewed-by: serb, psadhukhan
This commit is contained in:
Phil Race 2016-11-29 09:54:16 -08:00
parent 547092cf8d
commit 1ac940c263
2 changed files with 23 additions and 16 deletions

View File

@ -141,12 +141,24 @@ public final class CFontManager extends SunFontManager {
}
}
protected void registerFontsInDir(String dirName, boolean useJavaRasterizer, int fontRank, boolean defer, boolean resolveSymLinks) {
loadNativeDirFonts(dirName);
protected void registerFontsInDir(final String dirName, boolean useJavaRasterizer,
int fontRank, boolean defer, boolean resolveSymLinks) {
String[] files = AccessController.doPrivileged((PrivilegedAction<String[]>) () -> {
return new File(dirName).list(getTrueTypeFilter());
});
if (files == null) {
return;
} else {
for (String f : files) {
loadNativeDirFonts(dirName+File.separator+f);
}
}
super.registerFontsInDir(dirName, useJavaRasterizer, fontRank, defer, resolveSymLinks);
}
private native void loadNativeDirFonts(String dirName);
private native void loadNativeDirFonts(String fontPath);
private native void loadNativeFonts();
void registerFont(String fontName, String fontFamilyName) {

View File

@ -404,19 +404,14 @@ Java_sun_font_CFontManager_loadNativeDirFonts
{
JNF_COCOA_ENTER(env);
NSString *nsFilePath = JNFJavaToNSString(env, filename);
FSRef iFile;
OSStatus status = CreateFSRef(&iFile, nsFilePath);
if (status == noErr) {
ATSFontContainerRef oContainer;
status = ATSFontActivateFromFileReference(&iFile, kATSFontContextLocal,
kATSFontFormatUnspecified,
NULL, kNilOptions,
&oContainer);
}
NSString *path = JNFJavaToNSString(env, filename);
NSURL *url = [NSURL fileURLWithPath:(NSString *)path];
bool res = CTFontManagerRegisterFontsForURL((CFURLRef)url, kCTFontManagerScopeProcess, nil);
#ifdef DEBUG
NSLog(@"path is : %@", (NSString*)path);
NSLog(@"url is : %@", (NSString*)url);
printf("res is %d\n", res);
#endif
JNF_COCOA_EXIT(env);
}