JavaFX对所有控件使用等宽字体

时间:2015-04-23 15:59:28

标签: javafx javafx-8 fontconfig

我在Red Hat Enterprise Linux Workstation 6.6版(圣地亚哥)上使用JavaFX 1.8u40。当我在没有附加CSS的情况下运行标准JavaFX应用程序时,所有标签,菜单等都使用等宽字体显示。

我使用的系统只提供以下TTF字体

/usr/share/fonts/liberation
/usr/share/fonts/liberation/LiberationSerif-Regular.ttf
/usr/share/fonts/liberation/LiberationMono-BoldItalic.ttf
/usr/share/fonts/liberation/fonts.dir
/usr/share/fonts/liberation/LiberationMono-Italic.ttf
/usr/share/fonts/liberation/LiberationSans-Bold.ttf
/usr/share/fonts/liberation/LiberationSerif-Bold.ttf
/usr/share/fonts/liberation/LiberationMono-Regular.ttf
/usr/share/fonts/liberation/LiberationSans-BoldItalic.ttf
/usr/share/fonts/liberation/LiberationSerif-Italic.ttf
/usr/share/fonts/liberation/LiberationSerif-BoldItalic.ttf
/usr/share/fonts/liberation/fonts.scale
/usr/share/fonts/liberation/LiberationSans-Regular.ttf
/usr/share/fonts/liberation/LiberationSans-Italic.ttf
/usr/share/fonts/liberation/LiberationMono-Bold.ttf

我已使用OpenJFX fonts guide中的-Dprism.debugfonts对其进行了调试。输出如下。

Loading FontFactory com.sun.javafx.font.freetype.FTFactory
Subpixel: enabled
Freetype2 Loaded (version 2.3.11)
LCD support Enabled
Time spent accessing fontconfig=4ms.
FC font sans:regular:roman maps to Liberation Mono in file /usr/share/fonts/liberation/LiberationMono-Regular.ttf
 0) Family=Liberation Mono, Style=Regular, Fullname=Liberation Mono, File=/usr/share/fonts/liberation/LiberationMono-Regular.ttf
 1) Family=Liberation Sans, Style=Regular, Fullname=Liberation Sans, File=/usr/share/fonts/liberation/LiberationSans-Regular.ttf
 2) Family=Liberation Serif, Style=Regular, Fullname=Liberation Serif, File=/usr/share/fonts/liberation/LiberationSerif-Regular.ttf
FC font sans:bold:roman maps to Liberation Mono Bold in file /usr/share/fonts/liberation/LiberationMono-Bold.ttf
 0) Family=Liberation Mono, Style=Bold, Fullname=Liberation Mono Bold, File=/usr/share/fonts/liberation/LiberationMono-Bold.ttf
 1) Family=Liberation Sans, Style=Bold, Fullname=Liberation Sans Bold, File=/usr/share/fonts/liberation/LiberationSans-Bold.ttf
 2) Family=Liberation Serif, Style=Regular, Fullname=Liberation Serif, File=/usr/share/fonts/liberation/LiberationSerif-Regular.ttf
FC font sans:regular:italic maps to Liberation Mono Italic in file /usr/share/fonts/liberation/LiberationMono-Italic.ttf
 0) Family=Liberation Mono, Style=Italic, Fullname=Liberation Mono Italic, File=/usr/share/fonts/liberation/LiberationMono-Italic.ttf
 1) Family=Liberation Sans, Style=Italic, Fullname=Liberation Sans Italic, File=/usr/share/fonts/liberation/LiberationSans-Italic.ttf
 2) Family=Liberation Serif, Style=Italic, Fullname=Liberation Serif Italic, File=/usr/share/fonts/liberation/LiberationSerif-Italic.ttf
FC font sans:bold:italic maps to Liberation Sans Bold Italic in file /usr/share/fonts/liberation/LiberationSans-BoldItalic.ttf
 0) Family=Liberation Sans, Style=Bold Italic, Fullname=Liberation Sans Bold Italic, File=/usr/share/fonts/liberation/LiberationSans-BoldItalic.ttf
 1) Family=Liberation Mono, Style=Bold Italic, Fullname=Liberation Mono Bold Italic, File=/usr/share/fonts/liberation/LiberationMono-BoldItalic.ttf
 2) Family=Liberation Serif, Style=Italic, Fullname=Liberation Serif Italic, File=/usr/share/fonts/liberation/LiberationSerif-Italic.ttf
FC font serif:regular:roman maps to Liberation Mono in file /usr/share/fonts/liberation/LiberationMono-Regular.ttf
 0) Family=Liberation Mono, Style=Regular, Fullname=Liberation Mono, File=/usr/share/fonts/liberation/LiberationMono-Regular.ttf
 1) Family=Liberation Sans, Style=Regular, Fullname=Liberation Sans, File=/usr/share/fonts/liberation/LiberationSans-Regular.ttf
 2) Family=Liberation Serif, Style=Regular, Fullname=Liberation Serif, File=/usr/share/fonts/liberation/LiberationSerif-Regular.ttf
FC font serif:bold:roman maps to Liberation Mono Bold in file /usr/share/fonts/liberation/LiberationMono-Bold.ttf
 0) Family=Liberation Mono, Style=Bold, Fullname=Liberation Mono Bold, File=/usr/share/fonts/liberation/LiberationMono-Bold.ttf
 1) Family=Liberation Sans, Style=Bold, Fullname=Liberation Sans Bold, File=/usr/share/fonts/liberation/LiberationSans-Bold.ttf
 2) Family=Liberation Serif, Style=Regular, Fullname=Liberation Serif, File=/usr/share/fonts/liberation/LiberationSerif-Regular.ttf
FC font serif:regular:italic maps to Liberation Mono Italic in file /usr/share/fonts/liberation/LiberationMono-Italic.ttf
 0) Family=Liberation Mono, Style=Italic, Fullname=Liberation Mono Italic, File=/usr/share/fonts/liberation/LiberationMono-Italic.ttf
 1) Family=Liberation Sans, Style=Italic, Fullname=Liberation Sans Italic, File=/usr/share/fonts/liberation/LiberationSans-Italic.ttf
 2) Family=Liberation Serif, Style=Italic, Fullname=Liberation Serif Italic, File=/usr/share/fonts/liberation/LiberationSerif-Italic.ttf
FC font serif:bold:italic maps to Liberation Sans Bold Italic in file /usr/share/fonts/liberation/LiberationSans-BoldItalic.ttf
 0) Family=Liberation Sans, Style=Bold Italic, Fullname=Liberation Sans Bold Italic, File=/usr/share/fonts/liberation/LiberationSans-BoldItalic.ttf
 1) Family=Liberation Mono, Style=Bold Italic, Fullname=Liberation Mono Bold Italic, File=/usr/share/fonts/liberation/LiberationMono-BoldItalic.ttf
 2) Family=Liberation Serif, Style=Italic, Fullname=Liberation Serif Italic, File=/usr/share/fonts/liberation/LiberationSerif-Italic.ttf
FC font monospace:regular:roman maps to Liberation Mono in file /usr/share/fonts/liberation/LiberationMono-Regular.ttf
 0) Family=Liberation Mono, Style=Regular, Fullname=Liberation Mono, File=/usr/share/fonts/liberation/LiberationMono-Regular.ttf
 1) Family=Liberation Sans, Style=Regular, Fullname=Liberation Sans, File=/usr/share/fonts/liberation/LiberationSans-Regular.ttf
 2) Family=Liberation Serif, Style=Regular, Fullname=Liberation Serif, File=/usr/share/fonts/liberation/LiberationSerif-Regular.ttf
FC font monospace:bold:roman maps to Liberation Mono Bold in file /usr/share/fonts/liberation/LiberationMono-Bold.ttf
 0) Family=Liberation Mono, Style=Bold, Fullname=Liberation Mono Bold, File=/usr/share/fonts/liberation/LiberationMono-Bold.ttf
 1) Family=Liberation Sans, Style=Bold, Fullname=Liberation Sans Bold, File=/usr/share/fonts/liberation/LiberationSans-Bold.ttf
 2) Family=Liberation Serif, Style=Regular, Fullname=Liberation Serif, File=/usr/share/fonts/liberation/LiberationSerif-Regular.ttf
FC font monospace:regular:italic maps to Liberation Mono Italic in file /usr/share/fonts/liberation/LiberationMono-Italic.ttf
 0) Family=Liberation Mono, Style=Italic, Fullname=Liberation Mono Italic, File=/usr/share/fonts/liberation/LiberationMono-Italic.ttf
 1) Family=Liberation Sans, Style=Italic, Fullname=Liberation Sans Italic, File=/usr/share/fonts/liberation/LiberationSans-Italic.ttf
 2) Family=Liberation Serif, Style=Italic, Fullname=Liberation Serif Italic, File=/usr/share/fonts/liberation/LiberationSerif-Italic.ttf
FC font monospace:bold:italic maps to Liberation Sans Bold Italic in file /usr/share/fonts/liberation/LiberationSans-BoldItalic.ttf
 0) Family=Liberation Sans, Style=Bold Italic, Fullname=Liberation Sans Bold Italic, File=/usr/share/fonts/liberation/LiberationSans-BoldItalic.ttf
 1) Family=Liberation Mono, Style=Bold Italic, Fullname=Liberation Mono Bold Italic, File=/usr/share/fonts/liberation/LiberationMono-BoldItalic.ttf
 2) Family=Liberation Serif, Style=Italic, Fullname=Liberation Serif Italic, File=/usr/share/fonts/liberation/LiberationSerif-Italic.ttf
FC name=sans style=0 uses Liberation Mono in file: /usr/share/fonts/liberation/LiberationMono-Regular.ttf

我发现使用-Dprism.useFontConfig = false会导致JavaFX默认使用Lucida字体内置,但是我需要使用/ usr / share / fonts中的Liberation文件

问题

  • 我应该如何解释prism.debugfonts输出? 0,1,2行是什么意思?我无法在线找到任何相关文档。
  • 为什么JavaFX使用等宽字体来实现逻辑sans字体?
  • 如何让JavaFX使用Liberation Sans而不是mono?理想情况下无需修改JDK安装......
  • 这是JavaFX问题还是fontconfig问题?

更新

1 个答案:

答案 0 :(得分:0)

问题似乎出现在/etc/fonts/conf.d/中的fontconfig规则中,而不是JavaFX中。我还没有找到解决方法,但使用fc-match会产生相同的结果

fc-match sans:regular:roman 
"LiberationMono-Regular.ttf": "Liberation Mono" "Regular"

我在另一个论坛上发现了类似的问题:Font issue, monospace used for serif and sans-serif families,但没有解决方案。

添加字体配置文件,例如/etc/fonts/conf.d/88-liberation-hack.conf将解决问题

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

<alias>
  <family>sans-serif</family>
  <prefer><family>Liberation Sans</family></prefer>
</alias>

<alias>
  <family>serif</family>
  <prefer><family>Liberation Serif</family></prefer>
</alias>


<alias>
  <family>monospace</family>
  <prefer><family>Liberation Mono</family></prefer>
</alias>

</fontconfig>