RTF中的嵌入式字体 [英] Embedded fonts in RTF
问题描述
根据rtf规范,我们可以使用\ fontemb和\ fontfile控制字将字体嵌入到rtf文件中.有人可以给我一个可行的例子吗?我希望rtf文件使用单独文件(即.ttf文件)中的字体
According to the rtf specs, we can embed a font in an rtf file using the \fontemb and \fontfile control words. Can someone give me a working example of that? I'd like the rtf file to use the font that's located in a separate file (i.e. .ttf file)
推荐答案
您应该使用TTEmbedFont函数创建嵌入的字体数据. http://msdn.microsoft .com/en-us/library/windows/desktop/dd145145(v = vs.85).aspx
You should use TTEmbedFont function to create embedded font data. http://msdn.microsoft.com/en-us/library/windows/desktop/dd145145(v=vs.85).aspx
喜欢这个.
//WRITEEMBEDPROC
unsigned long WriteEmbedProc(void *lpvWriteStream, const void *lpvBuffer, const unsigned long cbBuffer)
{
BYTE *rgByte = new BYTE[cbBuffer];
memcpy(rgByte, lpvBuffer, cbBuffer);
//stream to store your font information
std::ofstream *ofs = static_cast<std::ofstream*>(lpvWriteStream);
//convert binary data to hexadeciaml, that rtf uses
std::string byte_string = BinToHex(rgByte, cbBuffer);
//Write formated data to your file (stream)
for (int i = 0; i < byte_string.size(); ++i)
{
*ofs << byte_string[i];
if((i + 1) % 128 == 0)
{
*ofs << "\n";
}
}
delete rgByte;
return cbBuffer;
}
void EmbedFontWrap(HDC hdc)
{
ULONG ulPrivStatus = 0;
ULONG ulStatus = 0;
std::ofstream *lpvWriteStream = new std::ofstream("D:\\out.txt", std::ios::binary);
USHORT *pusCharCodeSet;
USHORT usCharCodeCount;
USHORT usLanguage;
LONG ret = TTEmbedFont(
hdc,
TTEMBED_RAW | TTEMBED_EMBEDEUDC,
CHARSET_UNICODE,
&ulPrivStatus,
&ulStatus,
WriteEmbedProc,
lpvWriteStream,
nullptr,
0,
0,
nullptr);
lpvWriteStream->close();
delete lpvWriteStream;
}
要嵌入的字体应通过SelectObject函数设置为设备上下文的当前字体.
Font you want to embed should be set as current for you device context by SelectObject function.
这篇关于RTF中的嵌入式字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!