12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Media;
- namespace FWindSoft.Wpf
- {
- /// <summary>
- /// wpf下字体相关命令
- /// </summary>
- public class FontsUtil
- {//zh-cn
- public static List<string> FontNames { get; private set; }
- static FontsUtil()
- {
-
- FontNames = GetAllFontNames();
- //FontFamily不能加载我安装的字体,通过样式却可以
- //try
- //{
- // Awesome = new FontFamily(new Uri("pack://application:,,,/FWindSoft.Wpf;.component/Resources"), "FontAwesome");
- //}
- //catch (Exception ex)
- //{
- // throw;
- //}
- AwesomeKey= new ComponentResourceKey(typeof(FontsUtil), "FontAwesome");
- }
- private static List<string> GetAllFontNames()
- {
- List<string> names=new List<string>();
- var collection = Fonts.SystemFontFamilies;
- foreach (var fontFamily in collection)
- {
- var tempFontName = fontFamily.FamilyNames;
- var chName = tempFontName.FirstOrDefault(c => c.Key.IetfLanguageTag == "zh-cn");
- if (chName.Key == null)
- {
- chName = tempFontName.FirstOrDefault();
- }
- if (chName.Key == null)
- continue;
- names.Add(chName.Value);
- }
- return names;
-
- }
- public static ResourceKey AwesomeKey { get; private set; }
- //public static FontFamily Awesome { get; set; }
- }
-
- }
|