uwp 獲取系統字體庫
阿新 • • 發佈:2018-04-29
for 一個 arp cti src ++ AC blog lse 原文: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
uwp 獲取系統字體庫