Java没有合成斜体字体 [英] Java is not Synthesizing Italic Font Faces

查看:236
本文介绍了Java没有合成斜体字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要问题:

OpenJDK中是否有一个设置可以像Oracle JDK一样合成斜体字体.

Is there a setting in OpenJDK that will synthesize italic font faces like the Oracle JDK does.

背景:

使用OpenJDK,在Graphics2D对象上绘制文本时,除非以所需字体系列注册了斜体,否则文本不会以倾斜样式显示. Oracle的JDK确实合成斜体字体.摆动部件也被合成.

Using OpenJDK, when drawing text on a Graphics2D object, text will not appear with an oblique style unless there is an italic font face registered with the desired font family. Oracle's JDK does synthesize italic font faces. Swing components also are synthesized.

注释:

  • 粗体是合成的,粗体斜体只是粗体.
  • 我知道,为了获得最佳效果,应注册斜体字体.对于已经利用合成字体外观的应用程序,这可能不是一个完美的解决方案.
  • 关于JavaFX和字体的信息很多,不是JavaFX,而是AWT.

这是一个说明问题的简单类.

Here is a simple class that illustrates the issue.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UnsupportedLookAndFeelException;

public class SimpleFontTest {
    private static Font FONT = new Font("Impact", Font.ITALIC, 18);
    private static String TEXT = "The Quick Brown Fox";

    public static void main(String args[]) throws UnsupportedLookAndFeelException {     
        if (args.length > 0 && args[0] != null) {
            String fontName = args[0];
            FONT = new Font(fontName, Font.ITALIC, 18);
        }

        JFrame f = new JFrame("Simple Font Test: " + System.getProperty("java.vendor"));
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel label = new JLabel("JLabel: " + TEXT);
        label.setFont(FONT);

        GraphicsConfiguration gc = f.getGraphicsConfiguration();
        BufferedImage image = gc.createCompatibleImage(400, 50);
        Graphics2D g = image.createGraphics();
        g.setFont(FONT);
        g.setColor(Color.BLACK);
        g.setBackground(Color.WHITE);
        g.clearRect(0, 0, image.getWidth(), image.getHeight());
        g.drawString("BufferedImage: " + TEXT, 10, 15);
        g.dispose();
        JLabel picLabel = new JLabel(new ImageIcon(image));

        f.add(label, BorderLayout.PAGE_START);
        f.add(picLabel, BorderLayout.CENTER);
        f.setSize(400, 200);
        f.setVisible(true);
    }
}

输出将取决于用于构建和运行该类的JDK.这是一个比较图像:

The output will depend on the JDK used to build and run the class. Here is a comparison image:

谢谢大家.

推荐答案

因为我不喜欢看到没有答案的问题:看起来这只是从T2K字体渲染器到FreeType更改的结果.

Because I don't like seeing questions without answers: it looks like this is just a result of the change from T2K font renderer to FreeType.

一些解决方法:

  • 制作斜体字体(如果法律允许您许可)
  • 将AffineTransform应用于Font对象(-20的偏斜效果很好).

这篇关于Java没有合成斜体字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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