问题描述
在 Windows 中,CreateFontIndirect()
如果请求的字体没有被请求,调用可以默默地替换兼容的字体.GetObject()
调用不反映这种替换;它返回相同的 LOGFONT
传入.如何找到实际创建的字体?或者,如何强制 Windows 仅返回所请求的确切字体?
In Windows, the CreateFontIndirect()
call can silently substitute compatible fonts if the requested font is not requested. The GetObject()
call does not reflect this substitution; it returns the same LOGFONT
passed in. How can I find what font was actually created? Alternately, how can I force Windows to only return the exact font requested?
推荐答案
进行替换的不是 CreateFontIndirect.当字体被选入 DC 时,就会发生替换.CreateFontIndirect 只是为您提供了 LOGFONT 内部副本的句柄.这就是 GetObject 返回相同 LOGFONT 的原因.
It's not CreateFontIndirect that's doing the substitution. The substitution happens when the font is selected into the DC. CreateFontIndirect just gives you a handle to an internal copy of the LOGFONT. That's why GetObject gives you the same LOGFONT back.
如何找到实际创建的字体?
如果您将 HFONT 选择到目标 DC,那么您可以向 DC 询问有关实际选择为与 LOGFONT 最佳匹配的字体的信息.
If you select the HFONT into the target DC, you can then ask the DC for the information about the font that was actually chosen as the best match to the LOGFONT.
- 面部名称可通过 GetTextFace 获得.
- 您可以使用 GetTextMetrics 获取指标.莉>
- 如果所选字体是 TrueType 或 OpenType,您可以通过 GetOutlineTextMetrics.
- The face name is available with GetTextFace.
- You can get metrics with GetTextMetrics.
- If the selected font is TrueType or OpenType, you can get additional metrics with GetOutlineTextMetrics.
这基本上会告诉您实际创建的字体.
That essentially tells you what font was actually created.
旁白:
在做打印预览之类的事情时,可以从一个LOGFONT开始,选择到打印机DC(或IC)中,抓取实际字体的细节(打印机经常替换字体),然后创建一个新的LOGFONT.代表实际字体.将其选择到屏幕 DC 中,并通过适当的尺寸转换与用户实际获得的内容相匹配.
When doing something like print preview, you can start with a LOGFONT, select it into the printer DC (or IC), grab the details of the actual font (printers often substitute fonts), and then create a new LOGFONT that's more representative of the actual font. Select that into the screen DC, and--with appropriate size conversions--do a pretty good match of what the user will actually get.
这篇关于如何找到我的 CreateFont 调用实际使用的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!