I've seen similar questions answered for C#, PHP, etc. but I was not able to use those solutions in my Pascal work (Lazarus and Delphi).
The question is simple: I'd like to know programmatically if a font has a glyph for a given unicode character - using Lazarus (preferably) or at least Delphi.
In my specific case I'd like to use a unicode arrow char in some TLabel but I'd like to be able to check if that unicode arrow character is present in that font.
As an aside: my current roundabout solution is get TextWidth and TextHeight of the unicode character, and compare it with the TextWidth and TextHeight of a character that I'm sure does NOT have a glyph (say U0001). If they are different, it means the glyph exists. If they are the same, either the character doesn't have a glyph, or the glyph happens to have the same size as the ("glyph missing) replacement char. Clearly not a very satisfying solution. If you can think of a better roundabout solution, please let me know as well.
Thanks!
See 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.
The
GetFontUnicodeRanges
function returns information about which Unicode characters are supported by a font. The information is returned as aGLYPHSET
structure.