问题:
给定一个 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 ...
}
}
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 thisFont
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:
关于Java 绘制一个字体的所有字形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10647332/