3

问题:

给定一个字体对象,我如何绘制字体的所有字形/符号/字符?

我知道以下内容:

我知道如何从文件创建 Font 对象。

我知道使用 g.setFont(...) ;// g 是一个 Graphics2D

我知道使用 g.drawString(...); // g 是一个 Graphics2D

但是,我不想只画 AZ、az、0-9 字符。我想绘制字体的所有字形。有没有办法做到这一点?

谢谢!

4

1 回答 1

4

怎么样:

final Font f = new Font(...);

for (char c = 0x0000; c <= Character.MAX_VALUE; c++) {
    if (f.canDisplay(c)) {
        // draw it ...
    }
}

Font.canDisplay()

public boolean canDisplay(int codePoint)

检查此字体是否具有指定字符的字形。

参数:

codePoint- 需要字形的字符(Unicode 代码点)。

回报:

true如果这Font有字符的字形;false除此以外。

抛出:

IllegalArgumentException- 如果代码点不是有效的 Unicode 代码点。

自从:

   1.5

也可以看看:

Character.isValidCodePoint(int)

于 2012-05-18T06:17:01.710 回答