Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

c++ - Get a font filename based on Font Name and Style (Bold/Italic)

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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_MACHINESoftwareMicrosoftWindows NTCurrentVersionFonts in order to obtain the file name of a font from its logical name. An implementation of that solution can be found here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...