Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Swing-looking font rendering in JavaFX?

Tags:

fonts

javafx

This are screen captures of the same text in JavaFX (lcd and gray font smoothing) and Swing (default) on Windows 7 (Java JDK 8u45):

Both JavaFX and Swing fonts are the same (family: Segoe UI, style: Regular, size: 12).

JavaFX 8 (lcd)enter image description here JavaFX 8 (lcd)

JavaFX 8 (gray)enter image description here JavaFX 8 (gray)

Swingenter image description here Swing

Differences are not big, but are noticable.

Note: I don't want to include Swing components in JavaFX.

like image 351
krsi Avatar asked May 25 '15 05:05

krsi


1 Answers

tl;dr: It's not possible to get the Swing font rendering it via any combination of available JavaFX font knobs. It seems that your only option is to dig into JavaFX sources, fix it and/or bring it to JavaFX mailing list.


Difference on Linux is so big, that it's practically unusable for any kind of GUI where you read text for longer time. I did fair comparison with Swing and reported it twice[1][2]:

  • [1] https://bugs.openjdk.java.net/browse/JDK-8131923
  • [2] https://bugs.openjdk.java.net/browse/JDK-8139662

It's somewhat better on Windows, but as you say, in fair comparison with Swing, the difference is noticable: https://i.imgur.com/I7wLuYJ.png

Quoting Phillip from second bug report:

The main (only?) reason for the difference is that FX by design and across all platforms (including Windows) renders text unhinted, so as to preserve the shapes.

Note that his comments about unfair comparison are false for both bug reports. In the second report there's the test case I made where I specifically used same colors, fonts and sizes, and made the results for all possible combinations of available knobs.


I did the tests on Fedora 23 with freetype-freeworld from rpmfusion:

Xft.autohint:   0
Xft.antialias:  1
Xft.hinting:    1
Xft.hintstyle:  hintfull
Xft.rgba:   rgb
Xft.lcdfilter:  lcddefault
like image 154
woky Avatar answered Oct 31 '22 22:10

woky