WebView的默认字体

WebView的默认字体

本文介绍了更改JavaFX WebView的默认字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用嵌入在JPanel中的Java FX2.2 WebView来显示网页。这种方法效果很好,除了我不喜欢的默认字体。它看起来非常大胆/圆润/消除锯齿/模糊。

I am using a Java FX2.2 WebView embedded in a JPanel for showing web pages. This works well, except for the default font that I don't like. It looks very bold/rounded/anti-aliased/blurry.

左侧是我的Chrome浏览器中FX浏览器右侧的文字。

On the left is the text from my Chrome browser, on the right of the FX Browser.

似乎它使用System Regular字体作为默认字体,Font.getDefault()返回此字体。我尝试用反射更改它,但浏览器仍然使用相同的字体。
我还查看了 WebView.setFontScale() WebView.setFontSmoothingType(),这是第一次改变大小和后者只有第二种字体平滑类型甚至比默认更差。

It seems that it is using the "System Regular" Font as a default font, this font is returned by Font.getDefault(). I have tried changing it with reflection but the browser still uses the same font.Also I looked into WebView.setFontScale() and WebView.setFontSmoothingType(), the first only changes the size and the latter only has a 2nd font smoothing type that is even worse than the default.

我看了Safari,就像FX WebView一样,基于WebKit ,这个浏览器可以选择更改默认字体(我想大多数浏览器都有此选项)。

I looked at Safari, which is, like FX WebView, based on WebKit, and this browser has the option to change the default font (I think most browsers have this option).

有没有人知道如何更改Java的默认字体FX WebView?

Does anyone know a way to change this default Font for the Java FX WebView?

编辑:在这里提出功能请求:

Made a feature request here: https://bugs.openjdk.java.net/browse/JDK-8090968

推荐答案

尝试使用(我相信),某些平台的默认字体呈现机制已经更新。您需要评估自己目标平台上是否有改进。

Try using jdk8 where (I believe), the default font rendering mechanism for some platforms has been updated. You will need to evaluate yourself whether there appears to be an improvement to your eyes on your target platforms.

另请注意,。

WebView加载HTML,因此HTML中更改字体的标准方法适用于它(不推荐使用的HTML字体标记或CSS)。

WebView loads HTML, so the standard methods of changing fonts in HTML apply to it (the deprecated HTML font tag or CSS).

关于设置WebView使用的默认字体 - 我不知道这样做的机制。您可以针对JavaFX运行时项目创建。如果您记录功能请求,则可能需要参考这表明此功能在Chrome中可用。

As to setting the default font used by WebView - I am unaware of a mechanism to do that. You can create a feature request against the JavaFX runtime project. If you log a feature request, you may want to reference the Chrome documentation which demonstrates that this feature is available in Chrome.

这篇关于更改JavaFX WebView的默认字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 02:16