3

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.

David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • 1
    Many topics on SO: http://stackoverflow.com/questions/103725/is-there-a-way-to-programatically-determine-if-a-font-file-has-a-specific-unicod http://stackoverflow.com/questions/1633495/detecting-glyphs-occurrences-in-any-fonts?rq=1 http://stackoverflow.com/questions/5025740/c-check-for-unsupported-characters-glyphs-in-a-font?rq=1 http://stackoverflow.com/questions/13730544/is-there-a-glyph-not-found-character?rq=1 http://stackoverflow.com/questions/103725/is-there-a-way-to-programatically-determine-if-a-font-file-has-a-specific-unicod – bosnjak Mar 19 '14 at 23:14

1 Answers1

4

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;
j-p
  • 1,622
  • 10
  • 18
  • I haven't used .net in years but isn't `glyphExists = characterMap.ContainsKey(codePoint);` valid? (and more succinct) – Suragch Sep 30 '17 at 10:10
  • @Suragch code is a language, when explaining, verbosity wins against concision in my spirit I guess... – j-p Oct 17 '17 at 14:12