1
votes

I need to add font chooser to my WPF text editor. I'm adapting this font chooser.

However, it lists all the installed fonts. I only need a list of fixed-width (monospace) fonts.

How do I check if a given System.Windows.Media.FontFamily is a fixed-width font?

There is a solution that uses System.Drawing.FontFamily but those fonts are not exactly compatible with WPF and the code I'm adapting uses System.Windows.Media.FontFamily.

1

1 Answers

1
votes

Maybe you can filter the System.Windows.Media.FontFamily list by creating a System.Drawing.Font with the same name and use inteop and LOGFONT from there.

This is a horrible hack but I believe it will work in most cases (if you only use fonts installed on the system the System.Windows.Media.FontFamily and System.Drawing.FontFamily lists should mostly match)

Using something like this to get font sizing information or information about advanced font properties would be completely useless due to the differences in the font renderer between WPF and GDI - but for basic properties of the font like being fixed-width I expect this should work.