0

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 Answer 1

0

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)));
3
  • Hm. I can see that Arial is OpenType. Segoe UI too. It seems there are lots of OpenType fonts in my Windows 7SP1 installation. Jul 20, 2016 at 8:54
  • PS While mentioned fonts have .ttf extension. System font viewer tell they have OpenType format... Jul 20, 2016 at 8:56
  • Thanks for you help. Your could should work, but it find zero items. I found this internal property too, and there are really no fonts marked with PostscriptOpenType on my system. I will look for other solution. Jul 20, 2016 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.