The other day, Peter Parker (probably not his real name) asked:

How can I determine if a font is fixed width, like Visual Studio does?

Well, he certainly can't rely on his spidey sense even if he was the real Peter Parker, since Spiderman doesn't scale! :-)

When he referred to "like Visual Studio does", he meant the Bold items on the list:

Fixed width fonts are BOLD as love

 The principle is simple enough:

  • if the font identifies itself as fixed in its own data as you get by asking for a FIXED_PITCH font in the fdwPitchAndFamily member, or
  • it follows the "fixed enough" principles discussed here for East Asian fonts.

You can see many examples of this being correctly done for Meiryo/Meiryo UI (since the Latins are based on Verdana) and Microsoft YaHei/Microsoft JhengHei (since the Latins are based on Segoe UI) and so on.

It may even interest our Marvel action hero enough to want to emulate the checks.

However, there are three problems here;

  • while Visual Studio correctly flags MingLiU, it misses in the three MingLiU-esque fonts that are just as fixed as well as others, and
  • almost every East Asian font is fixed width for the East Asian characters, at least, and
  • some other scripts show the same characteristics of "fixed width within the script".

I suppose there could be an IsfixedWidth method where you can pass the font name and some text.

It could then return whether all of that text you passed in is the exact same width per character!

For now, you are mildly on your own checking for this.

Even if you spin a web any size and catch thieves just like flies...