tags:

views:

246

answers:

3

How can I test if a font is installed?

Ultimately, I want to implement a HTML-like font selection, i.e. when specifying e.g. "Verdana,Arial", it should pick the first font that is installed.

This Question provides an answer for .NET - it seems the recommended way is to create the font, and then cmpare the font face actually used.

Is that the most efficient way?

+2  A: 

You can use EnumFontFamiliesEx to enumerate the list of Fonts on the system, or if you pass a font name you can enumerate the fonts for that family.

Steven
Do you know what is the point of the DC parameter to EnumFonts et al.? It isn't required in CreateFont. Passing the Desktop Window's DC seems to work, but I can't find any documentation (except the "handle to the device context") in MSDN
peterchen
I suspect it might be for when using a printer dc but I have only ever used GetDC(NULL) and have never tried anything else.
Steven
+4  A: 

You can either try to create the font and see what you get (thus using the OS's font name matching/substitution).

Or you can enumerate installed fonts and do that matching yourself.

The "most efficient" way will depend on the details of a "match", and, in all likelihood, how many fonts are installed. On a system with, say, 50 fonts you will probably find performance is significantly different to a system with 1000 fonts installed.

In the end you can only profile on representative systems, if you first approach (keep it simple) turns out to be a performance bottleneck.

Richard
A: 

Have you tried AddFontResource?

dirkgently