Java 绘制一个字体的所有字形

标签 java fonts

问题:

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

我知道以下内容:

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

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

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

但是,我不想只绘制 A-Z、a-z、0-9 字符。我想绘制字体的所有字形。有办法做到这一点吗?

谢谢!

最佳答案

怎么样:

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)

Checks if this Font has a glyph for the specified character.

Parameters:

codePoint - the character (Unicode code point) for which a glyph is needed.

Returns:

true if this Font has a glyph for the character; false otherwise.

Throws:

IllegalArgumentException - if the code point is not a valid Unicode code point.

Since:

   1.5

See Also:

Character.isValidCodePoint(int)

关于Java 绘制一个字体的所有字形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10647332/

相关文章:

java - 自定义 JLabel 字体太小

css - 字体图标 - 如何检索符号代码?

html - CSS 中的通用绝对/相对 URL

python - 获取 ttf/otf 字体本地化名称

Java:创建具有变量类型的对象并在具有变量名称的对象上调用方法

java - 空 Java 扫描仪

用于解析的java原生JSON api

css - 有没有办法在ie7中通过css导入字体?

java - 连接到远程服务器并使用 Ant 启动/停止在该特定服务器上运行的 Tomcat?

java - 循环更改位图图像