8089573: [macosx] Incorrect char to glyph mapping printing on OSX 10.10
authorprr
Mon, 17 Oct 2016 13:54:05 -0700
changeset 41801 a40106ada604
parent 41800 9a377fe70092
child 41802 89f634379c0c
8089573: [macosx] Incorrect char to glyph mapping printing on OSX 10.10 Reviewed-by: serb, vadim
jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m
--- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m	Mon Oct 17 19:59:42 2016 +0300
+++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m	Mon Oct 17 13:54:05 2016 -0700
@@ -193,6 +193,44 @@
     return [sFontFamilyTable objectForKey:fontname];
 }
 
+static void addFont(CTFontUIFontType uiType, 
+                    NSMutableArray *allFonts,
+                    NSMutableDictionary* fontFamilyTable) {
+
+        CTFontRef font = CTFontCreateUIFontForLanguage(uiType, 0.0, NULL);
+        if (font == NULL) {
+            return;
+        }
+        CTFontDescriptorRef desc = CTFontCopyFontDescriptor(font);
+        if (desc == NULL) {
+            CFRelease(font);
+            return;
+        }
+        CFStringRef family = CTFontDescriptorCopyAttribute(desc, kCTFontFamilyNameAttribute);
+        if (family == NULL) {
+            CFRelease(desc);
+            CFRelease(font);
+            return;
+        }
+        CFStringRef name = CTFontDescriptorCopyAttribute(desc, kCTFontNameAttribute);
+        if (name == NULL) {
+            CFRelease(family);
+            CFRelease(desc);
+            CFRelease(font);
+            return;
+        }
+        [allFonts addObject:name];
+        [fontFamilyTable setObject:family forKey:name];
+#ifdef DEBUG
+        NSLog(@"name is : %@", (NSString*)name);
+        NSLog(@"family is : %@", (NSString*)family);
+#endif
+        CFRelease(family);
+        CFRelease(name);
+        CFRelease(desc);
+        CFRelease(font);
+}
+ 
 static NSArray*
 GetFilteredFonts()
 {
@@ -227,6 +265,16 @@
             }
         }
 
+        /*
+         * JavaFX registers these fonts and so JDK needs to do so as well.
+         * If this isn't done we will have mis-matched rendering, since
+         * although these may include fonts that are enumerated normally
+         * they also demonstrably includes fonts that are not.
+         */
+        addFont(kCTFontUIFontSystem, allFonts, fontFamilyTable);
+        addFont(kCTFontUIFontEmphasizedSystem, allFonts, fontFamilyTable);
+        addFont(kCTFontUIFontUserFixedPitch, allFonts, fontFamilyTable);
+
         sFilteredFonts = allFonts;
         sFontFamilyTable = fontFamilyTable;
     }