# HG changeset patch # User prr # Date 1480442056 28800 # Node ID ffe8f242155de60c6747e578f74fe8d693f8af10 # Parent eb5bfee6130a181d906410223b4877d709643274 8167103: Intermittent font loading failure on macOS with JFXPanel application Reviewed-by: serb, psadhukhan diff -r eb5bfee6130a -r ffe8f242155d jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java --- a/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java Mon Nov 28 14:36:46 2016 +0300 +++ b/jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java Tue Nov 29 09:54:16 2016 -0800 @@ -141,12 +141,24 @@ } } - 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) () -> { + 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) { diff -r eb5bfee6130a -r ffe8f242155d jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m --- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m Mon Nov 28 14:36:46 2016 +0300 +++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m Tue Nov 29 09:54:16 2016 -0800 @@ -404,19 +404,14 @@ { 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); }