I'm trying to write a Java program that finds the TTF for a font face given its name. For example, inputting "Times New Roman" on my Windows machine would return the path "C:\Windows\Fonts\times.ttf".
Most other font face names are abbreviated in a similar manner in the name of their TTF file. Is there a standard somewhere that I can use to map font face names to corresponding TTF filenames predictably?
Remember the name of the font is defined within the contents of the file, so there's no reason there should be any relation with the name of the font file itself.
In Windows XP the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
lists all the permanent installed system fonts. You can enumerate this list of font files, opening each one in turn and if it is a ttf you can get the checkSumAdjustment
from its head
table. Build a list of items, each item containing a pair of values - the font file name and the checksum value.
Then when you later realize a font, call GetFontData
on it and read the head
table and find the checkSumAdjustment
for that font. Then look it up in the list you made earlier.