如何在 JavaFX 字体中强制抗锯齿? [英] How to force anti-aliasing in JavaFX fonts?

查看:38
本文介绍了如何在 JavaFX 字体中强制抗锯齿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试我的 JavaFX 8 应用程序的 GUI 时,我注意到一些标签没有显示抗锯齿文本.经过一番谷歌搜索和挣扎后,我发现了一件非常烦人的事情正在发生.抗锯齿仅应用于字体大小大于 80 像素的标签.下面是一个比较应用了 AA 的 JavaFX 和 Swing 应用程序的示例:

示例代码:https://gist.github.com/anonymous/be60bb89181376ff12aa>

有没有办法在所有字体大小中强制使用 AA?你也有这种情况吗?我在 JavaFX Jira 上搜索了一个类似的错误,但到目前为止没有人抱怨.也许我应该为此打开一个?

一些可能有帮助的信息:

java 版本1.8.0"Java(TM) SE 运行时环境(构建 1.8.0-b132)Java HotSpot(TM) 64 位服务器 VM(构建 25.0-b70,混合模式)Windows 8.1 64 位 [版本 6.3.9600]

解决方案

默认情况下,JavaFX 8 使用 modena.css 来设置 LCD 抗锯齿,这似乎没有平滑字体某些情况下.当字体大小大于 80 px 时,AA 技术切换到灰度 AA(出于性能原因).因此,要在任何尺寸下获得平滑的边缘,应改用灰度 AA.

这可以通过 JavaFX CSS 来完成:

.text{-fx-font-smoothing-type:灰色;}

或系统参数:

-Dprism.lcdtext=false

或设置系统属性(在加载 FXML 之前):

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

感谢所有在 Jira 上回复的人!

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]

解决方案

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

This can be done either via JavaFX CSS:

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

Or system arguments:

-Dprism.lcdtext=false

Or setting system properties (before loading the FXML):

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

Thanks everyone who replied on Jira!

这篇关于如何在 JavaFX 字体中强制抗锯齿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆