<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi,</div><div><br></div><div>We recently noticed a problem: For fonts with localized names, <font face="monospace">Font.font(String)</font> can only find the font based on the localized name in the current locale.</div><div><br></div><div>For example, the Chinese version of Windows comes with a font called "YouYuan", and its Chinese name is "幼圆".</div><div>When the system language is Chinese, JavaFX has the following behaviors:</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div dir="ltr"><div><font face="monospace">jshell> Font.font("YouYuan")<br>$2 ==> Font[name=System Regular, family=System, style=Regular, size=13.333333015441895]<br><br>jshell> Font.font("幼圆")<br>$3 ==> Font[name=YouYuan, family=YouYuan, style=Regular, size=13.333333015441895]<br><br>jshell> $3.getFamily()<br>$4 ==> "YouYuan"</font></div></div></blockquote><br>
<div>As you can see, we cannot find the font based on the English name, we can only use the Chinese name.</div><div>But <font face="monospace">Font::getName()</font> returns the English name, so we can't get the Chinese name from the <font face="monospace">Font</font>.</div><div>This makes it impossible to generate a style sheet based on a <font face="monospace">Font</font><font face="arial, sans-serif"> object, </font>because </div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div dir="ltr"><div><font face="monospace">"-fx-font-family: \"%s\";".formatted(font.getFamily())</font></div></div></blockquote><div dir="ltr"><div>will not work with these fonts.</div><div><br></div><div>The only workaround I can think of is to generate a mapping table from English names to Chinese names like this:</div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div dir="ltr"><div><font face="monospace"><br></font></div><div><font face="monospace">Font.getFamilies().stream().collect(Collectors.toMap(it -> Font.font(it).getFamily(), Function.identity()))</font></div></div></blockquote><div dir="ltr"><div><br></div><div>But this seems like a lot of overhead :( </div><div><br></div><div>So, I want JavaFX to provide the following features:</div><div><ol><li>Regardless of the current system language, <font face="monospace">Font.font(String)</font> should be able to find the font by its English name;</li><li>Provide a new method <font face="monospace">Font::getLocalizedFamily()</font> to get the localized name of the font.</li></ol></div><div>Glavo</div></div>
</div>