问题:
给定一个Font对象,如何绘制该字体的所有字符/符号/字形?
我知道以下内容:
我知道如何从文件创建Font对象。
我知道使用g.setFont(...); // g是Graphics2D
我知道使用g.drawString(...); // g是Graphics2D
然而,我不想只画A-Z,a-z,0-9字符。 我想绘制该字体的所有字形。 有没有办法实现这个需求?
谢谢!
给定一个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:
c == 0xFFFF
时,c++
会将其设置为 0
。 - Nateowamichar
的使用方式与 int
类似,但它们的最大值不同Integer.MAX_VALUE != Character.MAX_VALUE
和0xFFFF == Character.MAX_VALUE
。尝试运行代码,你会发现它是无限的:https://ideone.com/SMwSb3 - Nateowami