Get supported characters of a font - in C#

后端 未结 2 1973
南方客
南方客 2020-11-29 05:32

I have a third party font with support for japanese characters which I need to use for an application. Whenever a character is not supported by this font, the often seen rec

相关标签:
2条回答
  • 2020-11-29 05:42

    Can't you just pull it up in Character Map and take note of the character ranges that are not defined?

    There's probably a programmatic way to parse a TTF file for this information but if it's just one particular font then it's probably easier just to open Character Map, set the Group by to Unicode Subrange and Group by "Japanese Hiragana/Katakana" and just take note of the defined ranges.

    0 讨论(0)
  • 2020-11-29 05:45

    Based on this answer.

    Be sure to reference PresentationCore.dll

    Try using this code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Media;
    
    namespace fontChecker
    {
        class Program
        {
            static void Main(string[] args)
            {
                var families = Fonts.GetFontFamilies(@"C:\WINDOWS\Fonts\Arial.TTF");
                foreach (FontFamily family in families)
                {
                    var typefaces = family.GetTypefaces();
                    foreach (Typeface typeface in typefaces)
                    {
                        GlyphTypeface glyph;
                        typeface.TryGetGlyphTypeface(out glyph);
                        IDictionary<int, ushort> characterMap = glyph.CharacterToGlyphMap;
    
                        foreach (KeyValuePair<int, ushort> kvp in characterMap)
                        {
                            Console.WriteLine(String.Format("{0}:{1}", kvp.Key, kvp.Value));
                        }
    
                    }
                }
            }
        }
    }
    

    Output image removed due to ImageShack replacing old, deleted image with an advert.

    0 讨论(0)
提交回复
热议问题