java font设置字间距,JavaFX字体渲染中的字符间距(字距调整)错误(在Linux中)...

I've started developing an application in JavaFX and I've run in an issue, I could find very little helpful information about: The spacing of between characters in Linux is very uneven. I'm not talking about the width of different characters but of the spaces between the characters.

It's visible in normal text, but the following example illustrates the effect better than normal text. Take a look at the first row. The space between the first two characters is smaller than between the second and third. This also happens between the sixth and seventh character and several others:

91wRh.png

Swing does not have this problem and JavaFX doesn't have this problem in Windows or it is barely visible on that OS. Neither does it appear to be a major issue on Mac. For comparison, here is a sample output on a Mac Retina MacBook Pro, mid-2014, running OS X 10.12.6 and Java 9.0.4:

lyv1S.png

Does anyone know if this is a bug in JavaFX's font rendering engine? If so, is there a workaround?

I'm really starting to wonder if I should change the framework as in my opinion such bad font rendering is not acceptable.

I have been able reproduce this issue on two different Linux machines running Manjaro and in a virtual machine running Debian with the following code:

package de.localtoast.fonttest;

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Label;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;

public class FontTest extends Application {

@Override

public void start(Stage primaryStage) {

VBox root = new VBox();

Label label1 = new Label("0000000000000000000000");

Label label2 = new Label("OOOOOOOOOOOOOOOOOOOOOO");

Label label3 = new Label("oooooooooooooooooooooo");

root.getChildren().add(label1);

root.getChildren().add(label2);

root.getChildren().add(label3);

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle("Font Test");

primaryStage.setScene(scene);

primaryStage.show();

}

public static void main(String[] args) {

launch(args);

}

}

解决方案

It is not a problem of JavaFX but a configuration issue on my Linux system. JavaFX needs subpixel rendering to position the glyphs correctly. I'm using Manjaro, which is a derivative of Archlinux. In Archlinux, subpixel rendering is disabled by default, which has to do with patents covered by Microsoft.

In my case the problem could be solved by installing the freetype2-ultimate5 package from AUR, although the in the wiki mentioned freetype2-cleartype package is probably the better choice. But the latter one currently doesn't compile on my system because of another issue.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值