Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if a font has a glyph for a given character?

Tags:

.net

fonts

glyph

How can I determine from the .NET runtime if, for a given font, if it has the glyph for a character? I want to switch the font to Arial Unicode MS if I have text that the specified font does not have a glyph for (very common for CJK).

Update: I'm looking for a C# (ie all managed code) solution. I think GlyphTypeface may be what I need but I can't see a way in it to ask if a given character has a glyph. You can get the entire map back, but I assume that would be an expensive call.

like image 887
David Thielen Avatar asked Sep 02 '25 02:09

David Thielen


1 Answers

I've done some unicode tools and the technique I use is getting the map and chache it for each font used.

IDictionary<int, ushort> characterMap = GlyphTypeface.CharacterToGlyphMap

will give you the defined glyph index per codepoint.

msdn ref

if (characterMap.ContainsKey(CodePoint))
    glyphExists = true;
else
    glyphExists = false;
like image 182
j-p Avatar answered Sep 05 '25 02:09

j-p