0
votes

I have a desktop WPF application which allows user to customize fonts.

After investigating rendering performance, I found that OpenType fonts render noticeably faster, than TrueType fonts.I would like to filter out TrueType fonts from settings dialog, so user can only select OpenType fonts. But I can't find how to determine the format of font in WPF.

I looked in Fonts.SystemFontFamilies and Fonts.SystemTypefaces and can't find any relevant properties.

1

1 Answers

0
votes

I don't believe Windows comes with any OpenType fonts, so unless you install them yourself, Fonts.SystemFontFamilies won't contain any.

That said, you could try filtering the list by retrieving the font's file name:

GlyphTypeface glyph;
var fonts = Fonts.SystemFontFamilies.Where(f => f.GetTypefaces().Any(t => 
     t.TryGetGlyphTypeface(out glyph) &&
     glyph.FontUri.ToString().EndsWith("otf", StringComparison.OrdinalIgnoreCase)));

Another way is to use the private FontTechnology proeprty:

GlyphTypeface glyph;
var FontTechnologyProperty = typeof(GlyphTypeface).GetProperty("FontTechnology", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
var OpenType = Enum.Parse(FontTechnologyProperty.PropertyType, "PostscriptOpenType");
var fonts = Fonts.SystemFontFamilies.Where(f => f.GetTypefaces().Any(t => 
     t.TryGetGlyphTypeface(out glyph) &&
     Object.Equals(FontTechnologyProperty.GetValue(glyph), OpenType)));