tags:

views:

322

answers:

3

We use a third-party PDF Generator library which requires that you specify the TrueType or Type1 file name when using a font other than the 14 or so that are part of the default PDF standard.

So if I want to use Bitstream Arrus Bold I have to know to reference arrusb.ttf.

Short of enumerating all of the files in the font folder and creating a disposable PrivateFontCollection to extract the relationships, is there a way to obtain the underlying font name from font information, i.e. given Courier New, Bold, Italic derive CourBI.ttf?

I've already looked at the InstalledFontCollection and there's nothing.

+2  A: 

If you don't mind poking around in the registry, take a look at

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

It has pairs like

Name = "Arial (TrueType)"
Data = "arial.ttf"

You can do this the necessary queries like this:

static RegistryKey fontsKey =
    Registry.LocalMachine.OpenSubKey(
        @"Software\Microsoft\Windows NT\CurrentVersion\Fonts");

static public string GetFontFile(string fontName)
{
    return fontsKey.GetValue(fontName, string.Empty) as string;
}

A call to GetFontFile("Arial (TrueType)") returns "arial.ttf"

You could of course modify the code to append the (TrueType) portion to the fontName, or to look through everything returned by fontsKey.GetValueNames() to find the best match.

Daniel LeCheminant
Thanks I'll check that out.
Bill
A: 

Never use registry. Use Win32 Font apis.

If you can provide an alternative that uses the Win32 Font APIs to address the OP's question, I (and I'm sure the OP) be interested to see it :]
Daniel LeCheminant
Why never use the registry
Daniel A. White
A: 

Unfortunately for this task there is no API that can be used. If you know of one, please share.