我正在尝试将几个 API 结合在一起以促进 XPS 打印。由于 True Type 字体有时会限制它们的使用方式,因此建议您查询操作系统 (Windows) 以获取与字体关联的许可证。我发现这样做的被禁止方法如下所示:
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);
此时 ttStatus 应该是 E_NONE
如果 TTGetEmbeddingType
成功并且 privstatus 应该是 {EMBED_PREVIEWPRINT, EMBED_EDITABLE, EMBED_INSTALLABLE, EMBED_NOEMBEDDING}
之一。星期五我有这个例子。今天,当我运行我的可执行文件时,TTGetEmbeddingType 返回 0x0A (E_NOTATRUETYPEFONT)
而不是 E_NONE
。哇?我是否遗漏了有关操作系统确定是否可以嵌入字体的能力的一些基本信息?
最佳答案
您引用的错误消息文本(“环境不正确”)属于ERROR_BAD_ENVIRONMENT
系统错误代码,其数值为10(0x0A)。但是,TTGetEmbeddingType()
不会返回系统错误代码。 TTGetEmbeddingType()
documentation状态:
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.
如果您查看 T2embapi.h
中的实际定义,0x000A
的返回值是 E_NOTATRUETYPEFONT
The specified font is not a TrueType font.
关于C++ LogFont 嵌入到 XPS 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36271576/