Search code examples
winapiopentype

How to programmatically determine whether a font is CFF?


Alrighty, I promise this is the closest I'll ever get to a "code for me" question :) If this doesn't drum up any responses I'll bite the bullet and build an OTF parser to check for the existence of a CFF table.

This info is available in the Windows font preview ('TrueType outlines' vs 'PostScript outlines'), so presumably there's a WinAPI function to this effect, but damned if I can find it.

Thoughts anyone?

ps - It's not a dealbreaker if only installed fonts can be checked, but checking files would be preferable.


Solution

  • You can do this using the GetFontData function.

    Create the font in question and select it into a DC, then call GetFontData to query the size of the CFF table. This will only succeed if the font has PostScript outlines.

    DWORD dwSize = GetFontData(hdc, ' FFC', 0, nullptr, 0);
    if (dwSize && dwSize != GDI_ERROR)
    {
        // has PostScript outlines
    }