tags:

views:

175

answers:

1

If I have a .NET Font object, is there a way to programmatically determine which ttf file in the C:\Windows\Fonts directory it was created with?

+2  A: 

This helpful article suggests that by looking at registry key

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts

You'll get a list of fontname, filename pairs. Open said registry key, iterate through the names until you find a match, then the value contains the filename (without a path).

Bob Kaufman
Thanks! Actually, a couple of them in my Hive do have full path. So it looks like its assumed to be in the system fonts folder, unless it has a full path, in which case its that path. Either way, this is exactly what I needed.
Nick
@Nick: One thing to note is that those in the registry hive don't actually match the Font.Name - they are usually appended with something in the Registry key like "(TrueType)" as in `Arial (TrueType)". This works, most of the time, to just use a RegEx to normalize a font name by removing the appending descriptor, but not always. My need was similar to yours, but I needed exactness, including potentially foreign language names for fonts. So what I did was grabbed all font file names from the hive and read each ttf or ttc's header file to extract the name to match it to an installed font name.
Otaku