none
How do I determine if a font has a glyph for a given character? RRS feed

  • Question

  • Hi all;

    I need to walk a string of text and determine if a font has glyphs for all the characters. And if it does not, then walk 3 backup fonts to see if they do. And I have to do this a lot so fast is important.

    1. I think GlyphTypeface.CharacterToGlyphMap is what I need but what/how does it work to determine if a glyph exists?
    2. And is this the fastest code to make this determination?
    3. And for a given Font, how do I create the matching GlyphTypeface object? Is there a wau to get the uri from Font of the font file?

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Wednesday, March 19, 2014 11:51 PM

Answers

  • Hi Dave,

    I am working with Herro to help you on your questions.

    For your questions:

    1. I think GlyphTypeface.CharacterToGlyphMap is what I need but what/how does it work to determine if a glyph exists?

    A: As mentioned in the msdn document, it will get a dictionary which represents the CAMP table. And you can try to understand more about CAMP table from https://www.microsoft.com/typography/otspec/cmap.htm

    2. And is this the fastest code to make this determination?

    A: As far as I know, it is.

    3. And for a given Font, how do I create the matching GlyphTypeface object? Is there a wau to get the uri from Font of the font file?

    A: To create a GlyphTypeface object, you need to create a Typeface object, and then call Typeface.TryGetGlyphTypeface .

    Please let me know if it works for you.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by DavidThi808 Thursday, March 20, 2014 10:25 PM
    Thursday, March 20, 2014 7:13 AM

All replies

  • Hi David,

    I am trying to involve someone familiar with this issue to come into this thread. Thank you for your understanding.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 20, 2014 3:31 AM
    Moderator
  • Hi Dave,

    I am working with Herro to help you on your questions.

    For your questions:

    1. I think GlyphTypeface.CharacterToGlyphMap is what I need but what/how does it work to determine if a glyph exists?

    A: As mentioned in the msdn document, it will get a dictionary which represents the CAMP table. And you can try to understand more about CAMP table from https://www.microsoft.com/typography/otspec/cmap.htm

    2. And is this the fastest code to make this determination?

    A: As far as I know, it is.

    3. And for a given Font, how do I create the matching GlyphTypeface object? Is there a wau to get the uri from Font of the font file?

    A: To create a GlyphTypeface object, you need to create a Typeface object, and then call Typeface.TryGetGlyphTypeface .

    Please let me know if it works for you.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by DavidThi808 Thursday, March 20, 2014 10:25 PM
    Thursday, March 20, 2014 7:13 AM
  • That did it - thank you!

    For others, here's the code:

            static void Main(string[] args)
            {
                Typeface typeface1 = new Typeface("Verdana");
                Console.Out.WriteLine("typeface = " + typeface1);
    
                GlyphTypeface glyphTypeface;
                bool b = typeface1.TryGetGlyphTypeface(out glyphTypeface);
                Console.Out.WriteLine("TryGetGlyphTypeface = " + b);
    
                IDictionary<int, ushort> map = glyphTypeface.CharacterToGlyphMap;
    
                Console.Out.WriteLine("Has glyph for 'a' = " + map.ContainsKey('a'));
                Console.Out.WriteLine("Has glyph for '\\u5678' = " + map.ContainsKey('\u5678'));
    
                Console.Out.WriteLine("all done...");
    
            }


    Who will win The Windward International Collegiate Programming Championships?

    Thursday, March 20, 2014 10:25 PM