gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:25:54 25 4
gpt4 key购买 nike

问题:

给定一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com