How to force anti-aliasing in JavaFX fonts?

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

While testing the GUI of my JavaFX 8 application, I noticed that some labels are not displaying anti-aliased text. After some googling and struggling, I found out a very annoying thing that is happening. The anti-aliasing is being applied only on labels which font size is greater than 80px. Here is an example comparing JavaFX and Swing applications with AA applied:

Sample code: https://gist.github.com/anonymous/be60bb89181376ff12aa

Is there a way to force the AA in all font sizes? Does this happen to you too? I searched for a similar bug on JavaFX Jira, but nobody is complaining about that so far. Maybe I should open one for this?

Some info that may help:

java version "1.8.0" Java(TM) SE Runtime Environment (build 1.8.0-b132) Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode) Windows 8.1 64 bits [Version 6.3.9600] 

回答1:

By default, JavaFX 8 uses modena.css to set the LCD anti aliasing, which doesn't seem to smooth fonts in some cases. When the font size is greater than 80, the AA technique changes to grey scale AA (for performance concerns). So, to achieve smooth edges at any size, grey scale AA should be used instead.

This can be done by CSS:

.text{     -fx-font-smoothing-type: gray; } 

Or through system arguments:

-Dprism.lcdtext=false 

Or setting system properties:

System.setProperty("prism.lcdtext", "false"); 

Thanks everybody who replied on Jira!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!