「VCS/FontSearch」の編集履歴(バックアップ)一覧に戻る

VCS/FontSearch - (2020/07/28 (火) 17:42:50) のソース

|開発環境|Microsoft Visual Studio Community 2019|
|実行環境|Microsoft Windows 10 Home (64bit)|
|プロジェクト テンプレート|[C#] コンソール アプリ (.NET Framework)|
|プロジェクト名|FontSearch|
#table_zebra(project, #fff, #ddd)

・参考
フォントに入っているグリフを調べる | 株式会社エイチ・オー・エス
[[https://www.hos.co.jp/blog/20160725/]]

&image(FontSearch.png)

Program.cs
#highlight(c#){{
using System;
using System.Linq;
using System.Windows.Media;

namespace FontSearch
{
    class Program
    {
        static void Main(string[] args)
        {
            // 参照の追加 アセンブリ フレームワーク PresentationCore

            int codePoint = 0xfdfd;
            var fontFamilies = Fonts.SystemFontFamilies;

            foreach (FontFamily fontFamily in fontFamilies)
            {
                var typefaces = fontFamily.GetTypefaces();
                Typeface typeface = typefaces.First();

                if (typeface.TryGetGlyphTypeface(out GlyphTypeface glyphTypeface))
                {
                    var glyphMap = glyphTypeface.CharacterToGlyphMap;
                    if (glyphMap.ContainsKey(codePoint))
                    {
                        ;
                        Console.WriteLine($"{fontFamily.ToString()} ({glyphMap[codePoint]})");
                    }
                }
            }

            Console.WriteLine($"\nフォントファミリ数: {fontFamilies.Count()}");
            Console.WriteLine($"CodePoint: {codePoint:X8}");
        }
    }
}
}}