Java中内置字体与第三方字体有什么区别?

3
尝试查找MultiLineLabel代码中可能存在的错误,该代码可在此处找到:http://samuelsjoberg.com/archive/2009/10/multiline-labels-in-swing。基本上,如果使用Arial等字体,则该示例将正常运行。但是,如果我在Mac上安装了自定义字体,例如ITCKorinna-Bold,则它仍然会渲染MultiLineLabel,但不会添加任何换行符,因此“This is a long line.”变成了“This is ...”。

为了更快地获得帮助,请发布一个SSCCE。 在网络上热链接字体。 - Andrew Thompson
1个回答

0
在Linux上,使用OpenJDK 7更新19版就可以正常工作。由于你没有提供你的代码,所以很难看出是否有任何问题。
当我修改示例以使用Roboto时,换行符按预期工作。
我不知道你正在使用哪个Java运行时,但如果你使用的是由Apple提供的那个,那么FontMetrics对象返回的值可能会有所不同(因为Apple Java运行时与例如Linux上的OpenJDK进行字体渲染方式不同)。我建议尝试使用OpenJDK并查看是否有所不同,或在不同的平台上运行应用程序并查看是否有所不同。
    Font robotoFont = null;
    try {
        robotoFont = Font.createFont(Font.TRUETYPE_FONT, new File("/usr/share/fonts/roboto/Roboto-Black.ttf"));
        robotoFont = robotoFont.deriveFont(14f);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Using the MultiLineLabel class.
    final MultiLineLabel mLabel = new MultiLineLabel(
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
                    + "Phasellus non sapien quam. Fusce posuere, nisl "
                    + "vitae tristique volutpat, augue erat faucibus nisl, "
                    + "nec venenatis metus sem vel enim. Cras in libero "
                    + "sapien, vitae euismod neque. Proin hendrerit, odio "
                    + "et faucibus suscipit, eros tellus blandit justo, "
                    + "ac cursus risus elit ut risus.");
    mLabel.setForeground(Color.WHITE);
    mLabel.setFont(robotoFont);

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接