private void AddFontFamily(FontFamily family) { string familyName; CultureInfo familyCulture; // First try getting a name in the user's language. familyCulture = CultureInfo.CurrentUICulture; family.FamilyNames.TryGetValue(familyCulture, out familyName); if (familyName == null) { // Fall back to en-US culture. This is somewhat arbitrary, but most fonts have English // strings so this at least yields predictable fallback behavior in most cases. familyCulture = enUSCulture; family.FamilyNames.TryGetValue(familyCulture, out familyName); } if (familyName == null) { // As a last resort, use the first name we find. This will just be the name associated // with whatever locale name sorts first alphabetically. foreach (KeyValuePair <CultureInfo, string> entry in family.FamilyNames) { familyCulture = entry.Key; familyName = entry.Value; } } if (familyName == null) { return; } //add info to list of structs used as a cache of text layouts var displayFormats = new List <TextLayout>(); var format = dwriteFactory.CreateTextFormat( family.Fonts[0].IsSymbolFont ? Font.FontFamily.Name : familyName, DropDownFontSize, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, familyCulture); format.WordWrapping = WordWrapping.NoWrap; var layout = dwriteFactory.CreateTextLayout( familyName, format, 10000, 10000); DropDownWidth = Math.Max(DropDownWidth, (int)layout.Metrics.Width); maxHeight = Math.Max(maxHeight, layout.Metrics.Height); displayFormats.Add(layout); //add name to list primaryNames.Add(familyName); layouts.Add(familyName, layout); }
private void AddFontFamily(FontFamily family) { string familyName; CultureInfo familyCulture; // First try getting a name in the user's language. familyCulture = CultureInfo.CurrentUICulture; family.FamilyNames.TryGetValue(familyCulture, out familyName); if (familyName == null) { // Fall back to en-US culture. This is somewhat arbitrary, but most fonts have English // strings so this at least yields predictable fallback behavior in most cases. familyCulture = enUSCulture; family.FamilyNames.TryGetValue(familyCulture, out familyName); } if (familyName == null) { // As a last resort, use the first name we find. This will just be the name associated // with whatever locale name sorts first alphabetically. foreach (KeyValuePair<CultureInfo, string> entry in family.FamilyNames) { familyCulture = entry.Key; familyName = entry.Value; } } if (familyName == null) return; //add info to list of structs used as a cache of text layouts var displayFormats = new List<TextLayout>(); var format = dwriteFactory.CreateTextFormat( family.Fonts[0].IsSymbolFont ? Font.FontFamily.Name : familyName, DropDownFontSize, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, familyCulture); format.WordWrapping = WordWrapping.NoWrap; var layout = dwriteFactory.CreateTextLayout( familyName, format, 10000, 10000); DropDownWidth = Math.Max(DropDownWidth, (int)layout.Metrics.Width); maxHeight = Math.Max(maxHeight, layout.Metrics.Height); displayFormats.Add(layout); //add name to list primaryNames.Add(familyName); layouts.Add(familyName, layout); }