8167103: Intermittent font loading failure on macOS with JFXPanel application
authorprr
Tue, 29 Nov 2016 09:54:16 -0800
changeset 42726 ffe8f242155d
parent 42725 eb5bfee6130a
child 42727 bd56c4c834bb
8167103: Intermittent font loading failure on macOS with JFXPanel application Reviewed-by: serb, psadhukhan
jdk/src/java.desktop/macosx/classes/sun/font/CFontManager.java
jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m
--- 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<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) {
--- 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);
 }