在 JavaFX 中加载 .ttf 字体在 Windows 上是像素化的

Luk*_*kas 5 css java fonts javafx

我正在尝试在我的 JavaFx 应用程序中加载 .ttf 字体。这是我的项目结构:

main
- java
- - Application.java
- resources
- - fonts
- - - static
- - - - Raleway-Thin.ttf
- - - - Ralewy-Regular.ttf
- - - - ...
- - - Raleway-VairableFont_wght.ttf
- - main.css
Run Code Online (Sandbox Code Playgroud)

在 Linux 上,加载静态字体时一切正常start(Stage stage)

main
- java
- - Application.java
- resources
- - fonts
- - - static
- - - - Raleway-Thin.ttf
- - - - Ralewy-Regular.ttf
- - - - ...
- - - Raleway-VairableFont_wght.ttf
- - main.css
Run Code Online (Sandbox Code Playgroud)

main.css并像这样引用它们:

Font.loadFont(getClass.getResourceAsStream("fonts/static/Raleway-Thin.ttf"), 12);
... //Here I load all types I need
Run Code Online (Sandbox Code Playgroud)

在 Windows 上,字体看起来很糟糕:

Windows 示例

它确实加载了字体,确实是Raleway Bold,但看起来很丑。

我已尝试以下操作,如有必要,我很乐意更详细地阐述所有内容:

  • 加载 VariableFont_wgth 与Font.loadFonts(...). 这将是最好的方法,但只有Raleway Thin在执行此操作时才会加载。我想我需要一个.ttc文件来执行此操作。此外,它仍然是像素化的。

  • 我尝试使用 css 标签@font-face。这并没有解决像素化文本的问题。

  • 我试图更改 的第二个参数sizeFont.loadFont()即使在阅读了文档之后,我也不太明白它的目的。

什么可能导致此问题以及如何解决?我不能依赖用户在系统上安装了该字体。