根据字体名称和样式(粗体/斜体)获取字体文件名 [英] Get a font filename based on Font Name and Style (Bold/Italic)
问题描述
我需要根据名字得到一个字体文件名(例如Arial.ttf)(在这种情况下是Arial) ),无论是粗体,斜体还是两者。使用这些信息,我需要找到字体文件,所以我可以用它来渲染。
更多的例子:
- Calibri,Bold将解析为calibrib.ttf。
- Calibri,Italic将解析为calibrii.ttf。 b
关于如何在C ++(Win32)中实现这一点的任何想法
首先,据我所知,没有可靠的方法去做。
Windows API处理字体系列和映射,而不是字体文件,在较低的水平处理。还要注意的是,即使你设法得到一个字体的文件名,没有渲染函数(我知道的)会接受它,那么你将如何处理它?</ p>
<这就是说,你可以在注册表键 HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows NT \CurrentVersion\Fonts
中以获取文件名来自其逻辑名称的字体。该解决方案的实现可以在这里找到。
This has been driving me crazy all day.
I need to get a font filename (eg. Arial.ttf) based on its name (Arial in this case) and whether it is bold, italic or both. Using those pieces of information, I need to find the font file so I can use it for rendering.
Some more examples:
- Calibri, Bold would resolve to calibrib.ttf.
- Calibri, Italic would resolve to calibrii.ttf.
Any ideas on how I could achieve this in C++ (Win32)
First, to my knowledge, there is no reliable way to do that.
The Windows API deals with font families and mappings, not with font files, which are dealt with at a lower level. Also note that even if you manage to get the file name of a font, no rendering function (that I know of) will accept it, so what will you do with it?
That said, you can look in the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts
in order to obtain the file name of a font from its logical name. An implementation of that solution can be found here.
这篇关于根据字体名称和样式(粗体/斜体)获取字体文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!