【转载】uwp 获取系统字体库

效果图:

 

要获取到字体库首先要在 NuGet 添加 SharpDx.Direct2D1  api:

 /// <summary>
        /// 获取系统字体库列表
        /// </summary>
        public void GetFontLibrary()
        {
            SharpDX.DirectWrite.Factory factory = new SharpDX.DirectWrite.Factory();



            var fontCollection = factory.GetSystemFontCollection(false);
            var familCount = fontCollection.FontFamilyCount;

            for (int i = 0; i < familCount; i++)
            {
                var fontFamily = fontCollection.GetFontFamily(i);
                var familyNames = fontFamily.FamilyNames;

                int index;

                if (!familyNames.FindLocaleName(CultureInfo.CurrentCulture.Name, out index))
                {
                    if (!familyNames.FindLocaleName("en-us", out index))
                    {
                        index = 0;
                    }
                }

                string name = familyNames.GetString(index);

                FontList.Add(name);
            }


        }

  因为 设置FontFamily 属性需要的时一个字符串类型,我们只要获取到字体的名字添加到一个字符串集合上就可以了。

原文地址:http://edi.wang/post/2017/1/22/windows-10-uwp-get-fonts

posted @ 2018-04-28 15:40  吃饭/睡觉  阅读(936)  评论(0编辑  收藏  举报