private static TypographicFontFamilyCollection CreateFamilyList() { var subfamilesByFont = new Dictionary <string, List <TypographicFont> >(); foreach (var installedFontFile in TypographicFont.GetInstalledFontFiles()) { if (!File.Exists(installedFontFile)) { continue; } foreach (var font in TypographicFont.FromFile(installedFontFile)) { List <TypographicFont> list; if (!subfamilesByFont.TryGetValue(font.Family, out list)) { subfamilesByFont.Add(font.Family, list = new List <TypographicFont>()); } list.Add(font); } } var r = new List <TypographicFontFamily>(); foreach (var kvp in subfamilesByFont) { kvp.Value.Sort((a, b) => String.Compare(a.SubFamily, b.SubFamily, StringComparison.OrdinalIgnoreCase)); r.Add(new TypographicFontFamily(kvp.Key, kvp.Value)); } r.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase)); return(new TypographicFontFamilyCollection(r)); }
private void TypographicFontDialog_Load(object sender, EventArgs e) { /* * for (int i=0; i < listView2.Items.Count; i++) * { * var size = float.Parse(listView2.Items[i].Text); * if (FontSize > size) continue; * if (FontSize < size) * { * listView2.Items.Insert(i, FontSize.ToString()); * } * listView2.Items[i].Selected = true; * break; * } */ comboBox1.SelectedIndex = -1; comboBox1.Text = FontSize.ToString(); foreach (var ff in TypographicFontFamily.InstalledFamilies) { //var fc = new PrivateFontCollection(); var normalFont = ff.NormalFont; //fc.AddFontFile(normalFont.FileName); var font = new FontFamily(normalFont.Name); var famFont = ff.Fonts.FirstOrDefault(tf => tf.Name == FontName); if (famFont != null) { selectedFont = famFont; } listView1.Items.Add(new ListViewItem() { Text = ff.Name, Font = new Font(font, listView1.Font.Size, listView1.Font.Unit), ToolTipText = ff.Name, Tag = ff, Selected = famFont != null, Group = normalFont.Panose.Proportion == Panose.PanoseProportion.Monospaced ? listView1.Groups["lvgMono"] : listView1.Groups["lvgNormal"] }); } }