On Wed, 27 Nov 2019 17:06:13 GMT, Jose Pereda <jper...@openjdk.org> wrote:

> Running on MacOS Catalina, when doing static builds of `libjavafx_font.a` and 
> linking against this in a JavaFX app compiled with GraalVM native-image, if 
> default fonts are used, the rendered text is garbled, and a warning message 
> is printed: 
> 
> CoreText note: Client requested name ".SFUI-Regular", it will get 
> TimesNewRomanPSMT rather than the intended font. All system UI font access 
> should be through proper APIs such as CTFontCreateUIFontForLanguage() or 
> +[UIFont systemFontOfSize:]. 
> CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug. 
> 
> On Mac OS, when a map with all the regular fonts is created, we also add two 
> system fonts: [System 
> regular](https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/native-font/MacFontFinder.c#L178),
>  and [System 
> bold](https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/native-font/MacFontFinder.c#L187).
>  These will be the default fonts to be used if the project doesn't specify a 
> font.
> 
> On runtime, when a font is 
> [created](https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/java/com/sun/javafx/font/coretext/CTFontStrike.java#L90),
>  `CTFontCreateWithName` is 
> [used](https://github.com/openjdk/jfx/blob/master/modules/javafx.graphics/src/main/native-font/coretext.c#L391),
>  which according to Apple guidelines should be used only for the regular 
> fonts (those that are not system fonts). In fact the above warning doesn't 
> happen when creating any of those fonts.
> 
> Following the warning message, one of the options to create system fonts is 
> to use `CTFontCreateUIFontForLanguage`, which according to the documentation 
> in `CTFont.h`: 
>> Returns the special UI font for the given language and UI type.
> 
> and matches what we already do in `MacFontFinder` to create such fonts. (The 
> other option will require the use of UIKit.)
> 
> 
> This PR modifies `CTFontCreateWithName` in `coretext.c` to detect if the font 
> is a system font in the first place, else use the same existing mechanism.
> 
> As an aside, the constants `kCTFontSystemFontType` and 
> `kCTFontEmphasizedSystemFontType` are deprecated, and this PR uses now the 
> new ones, but in both cases their int value is the same (2 and 3, in that 
> order). As a follow-up PR, we could replace these deprecated constants.
> 
> ----------------
> 
> Commits:
>  - 693dfa78: Use CTFontCreateUIFontForLanguage for system fonts
> 
> Changes: https://git.openjdk.java.net/jfx/pull/55/files
>  Webrev: https://webrevs.openjdk.java.net/jfx/55/webrev.00
>   Issue: https://bugs.openjdk.java.net/browse/JDK-8234916
>   Stats: 9 lines in 1 file changed: 8 ins; 0 del; 1 mod
>   Patch: https://git.openjdk.java.net/jfx/pull/55.diff
>   Fetch: git fetch https://git.openjdk.java.net/jfx pull/55/head:pull/55

This seems simple enough that one reviewer should be sufficient (unless Phil 
thinks otherwise).

PR: https://git.openjdk.java.net/jfx/pull/55

Reply via email to