Hi,

We recently noticed a problem: For fonts with localized names,
Font.font(String) can only find the font based on the localized name in the
current locale.

For example, the Chinese version of Windows comes with a font called
"YouYuan", and its Chinese name is "幼圆".
When the system language is Chinese, JavaFX has the following behaviors:

jshell> Font.font("YouYuan")
$2 ==> Font[name=System Regular, family=System, style=Regular,
size=13.333333015441895]

jshell> Font.font("幼圆")
$3 ==> Font[name=YouYuan, family=YouYuan, style=Regular,
size=13.333333015441895]

jshell> $3.getFamily()
$4 ==> "YouYuan"


As you can see, we cannot find the font based on the English name, we can
only use the Chinese name.
But Font::getName() returns the English name, so we can't get the Chinese
name from the Font.
This makes it impossible to generate a style sheet based on a Font object,
because

"-fx-font-family: \"%s\";".formatted(font.getFamily())

will not work with these fonts.

The only workaround I can think of is to generate a mapping table from
English names to Chinese names like this:


Font.getFamilies().stream().collect(Collectors.toMap(it ->
Font.font(it).getFamily(), Function.identity()))


But this seems like a lot of overhead :(

So, I want JavaFX to provide the following features:

   1. Regardless of the current system language, Font.font(String) should
   be able to find the font by its English name;
   2. Provide a new method Font::getLocalizedFamily() to get the localized
   name of the font.

Glavo

Reply via email to