changeset 16311:d82266274ca8

8167103: Intermittent font loading failure on macOS with JFXPanel application Reviewed-by: serb, psadhukhan
author prr
date Tue, 29 Nov 2016 09:54:16 -0800
parents 2e5f7c4c78e5
children 6662db46979c
files src/java.desktop/macosx/classes/sun/font/CFontManager.java src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m
diffstat 2 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/classes/sun/font/CFontManager.java	Mon Nov 28 14:36:46 2016 +0300
+++ b/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/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m	Mon Nov 28 14:36:46 2016 +0300
+++ b/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);
 }