I am attempting to marry a couple of APIs together to facilitate XPS Printing. As True Type Fonts are sometimes restricted on how they may be used it is suggested that you query the OS (Windows) for the license associated with a font. The proscribed method I've found for doing that looks like this:
HDC hDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);
// logfont is a valid instance of LOGFONTW
HGDIOBJ hfont = ::CreateFontIndirect(&logfont);
if (!SelectObject(hDC, hfont))
return;
ULONG privstatus = 0;
LONG ttStatus;
ttStatus = TTGetEmbeddingType(hDC, &privstatus);
At this point ttStatus should be E_NONE
if TTGetEmbeddingType
succeeded and privstatus should be one of {EMBED_PREVIEWPRINT, EMBED_EDITABLE, EMBED_INSTALLABLE, EMBED_NOEMBEDDING}
. I had this example working Friday. Today when I run my executable TTGetEmbeddingType returns 0x0A (E_NOTATRUETYPEFONT)
instead of E_NONE
. Wat? Am I missing something fundamental about the OS's ability to determine whether a font can be embedded?
The error message text you quoted ("The environment is incorrect") belongs to the ERROR_BAD_ENVIRONMENT
system error code, which has a numeric value of 10 (0x0A). However, TTGetEmbeddingType()
does not return a system error code. The TTGetEmbeddingType()
documentation states:
If successful, returns E_NONE.
This function reads the embedding privileges stored in the font and transfers the privileges to pulPrivStatus.
Otherwise, returns an error code described in Embedding-Function Error Messages.
If you look at the actual definitions in T2embapi.h
, a return value of 0x000A
is E_NOTATRUETYPEFONT
The specified font is not a TrueType font.