Enabling additional command prompt fonts

I’ve always wondered why there are so few fonts available for the command prompt, knowing that I have many mono-spaced fonts installed.

So, doing some research (yes, googling) I found this trick:
Stupid Geek Tricks: Enable More Fonts for the Windows Command Prompt

As with many cool configuration tricks in Windows, it involves editing the registry.
I don’t mind that, but I’m sure I will forget all about it in a couple of days and I’ll need to find the trick again whenever I want to add (or remove) fonts.

So, I decided to create a little utility to automate the whole process.

Command Prompt Fonts

Command Prompt Fonts

Enumerating the available mono-spaced fonts

This should be an easy task but, as it happens with many things in the .NET framework, there’s no managed way to do so and we must rely on the dreaded Win32 API.

The function to do the job is GetTextMetrics, which is used to fill a TEXTMETRIC structure from which we are able to query the value of the PitchAndFamily member. Testing the last bit of this member can tell us if the font is mono-spaced (a value of 0) or not (a value of 1).

We should be able to fill that structure by using the ToLogFont() method of the Font class but, although it works for the most part, the PitchAndFamily member always returns 0. That’s why we need to rely on a native Win32 function call.

Enumerating the available command prompt fonts

Here we simply check the values in the HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont registry key.
Each entry has a name, which appears to represent the code page for which the font should be displayed, and a value which corresponds to the font family.
An entry name whose integer value equals zero seems to make the font available for any code page.

Here are the links to download both the compiled binary, or the source code (in Visual Studio 2012 format):

Command Prompt Fonts 1.1 [25.89 kB]
Command Prompt Fonts Source Code 1.1 [51.86 kB]