public DrawingFontInfo() { this.ProportionalList = new List <Font>(); this.MonospaceList = new List <Font>(); var fontNames = new InstalledFontCollection().Families.Select(x => x.Name).ToArray(); Console.WriteLine(fontNames.Length); using (var bmp = new Bitmap(1, 1)) using (var graphics = Graphics.FromImage(bmp)) { foreach (var name in fontNames) { using (Font font = new Font(name, emSize: 20)) { float iiSize = graphics.MeasureString("iiii", font).Width; float wwSize = graphics.MeasureString("wwww", font).Width; if (iiSize == wwSize) { float aaSize = graphics.MeasureString("ああ", font).Width; if (Math.Abs(iiSize - aaSize) < 1) { MonospaceList.Add(font); continue; } } ProportionalList.Add(font); } } } }
public MediaFontInfo() { this.ProportionalList = new List <System.Windows.Media.FontFamily>(); this.MonospaceList = new List <System.Windows.Media.FontFamily>(); XmlLanguage lang = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name); IEnumerable <string> fontNames = new InstalledFontCollection().Families.Select(x => x.Name); using (var bmp = new Bitmap(1, 1)) using (var graphics = Graphics.FromImage(bmp)) { foreach (System.Windows.Media.FontFamily family in System.Windows.Media.Fonts.SystemFontFamilies) { string cltName = family.FamilyNames.FirstOrDefault(x => x.Key == lang).Value ?? family.Source; string name = fontNames.FirstOrDefault(x => x.StartsWith(cltName)); if (!string.IsNullOrEmpty(name)) { using (Font font = new Font(name, emSize: 20)) { float iiSize = graphics.MeasureString("iiii", font).Width; float wwSize = graphics.MeasureString("wwww", font).Width; if (iiSize == wwSize) { float aaSize = graphics.MeasureString("ああ", font).Width; if (Math.Abs(iiSize - aaSize) < 1) { MonospaceList.Add(family); continue; } } ProportionalList.Add(family); } } } } }