从C ++ / Windows中获取名称和样式的字体文件路径 [英] Get a font filepath from name and style in C++/Windows
问题描述
我目前在我的一个项目中实现FreeType 2,因此在我的系统上需要用于字体的文件路径。我需要一个仅使用字体名称和所需字体样式(例如粗体或斜体)的解决方案,然后返回字体的文件路径。 b
$ b
我已经尝试了这个答案堆栈溢出问题,但它不适用于Windows 7(也可能在Vista上),但显然我需要一个解决方案,在这些系统和未来的系统。
请问为什么你需要一个物理文件的路径?
- 如果您只需要字体的二进制数据,您可以使用 GetFontData 。
- 如果需要字体的度量,可以创建一个HFONT,将HFONT放入字体保持器HDC中,并使用 font_link.cpp 。
- 以上都是纯粹的GDI函数。如果你真的需要字体路径,而不介意使用DirectWrite,请看 IDWriteFontFile :: GetReferenceKey and IDWriteLocalFontFileLoader :: GetFilePathFromKey 。这会给你比GDI更多的未来保险。
I'm currently implementing FreeType 2 in a project of mine and thus need the filepaths for Fonts on my system. I need a solution that only takes the fonts name and the desired font style (eg. bold or italic) and then returns the filepath for the font.
I already tried the answer from this Stack Overflow question, but it doesn't work on Windows 7 (and probably neither on Vista), but obviously I need a solution that works on these systems and future systems as well.
May I ask why do you need the path to a physical file?
- If you just need the binary data of the font, you can use GetFontData.
- If need the metrics of the font, you can create an HFONT, select the HFONT into an font holder HDC, and use GetOutlineTextMetrics.
- If you need information about font linking, take a look at my project: font_link.cpp.
- All above are pure GDI functions. If you really need the font path, and not mind using DirectWrite, take look at IDWriteFontFile::GetReferenceKey and IDWriteLocalFontFileLoader::GetFilePathFromKey. This would give you more future insurance than GDI.
这篇关于从C ++ / Windows中获取名称和样式的字体文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!