我如何知道一种字体是否具有给定 Unicode 字符的字形?

How do I know if a font has a glyph for a given Unicode character?

我已经看到针对 C#、PHP 等类似问题的回答,但我无法在我的 Pascal 工作(Lazarus 和 Delphi)中使用这些解决方案。

问题很简单:我想以编程方式知道字体是否具有给定 unicode 字符的字形 - 使用 Lazarus(最好)或至少 Delphi。

在我的具体情况下,我想在某些 TLabel 中使用 unicode 箭头字符,但我希望能够检查该字体中是否存在该 unicode 箭头字符。

顺便说一句:我目前的迂回解决方案是获取 Unicode 字符的 TextWidth 和 TextHeight,并将其与我确定没有字形的字符(比如 U0001)的 TextWidth 和 TextHeight 进行比较。如果它们不同,则表示该字形存在。如果它们相同,则字符没有字形,或者字形恰好与(“字形缺失)替换字符的大小相同。显然不是一个非常令人满意的解决方案。如果你能想到更好的回旋处解决方案,也请告诉我。

谢谢!

参见GetGlyphIndices()

The GetGlyphIndices function translates a string into an array of glyph indices. The function can be used to determine whether a glyph exists in a font.

GetFontUnicodeRanges()

The GetFontUnicodeRanges function returns information about which Unicode characters are supported by a font. The information is returned as a GLYPHSET structure.