Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if a font is installed (Win32)

Tags:

c++

fonts

winapi

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?

like image 266
peterchen Avatar asked Dec 22 '22 11:12

peterchen


1 Answers

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.

like image 123
Richard Avatar answered Dec 28 '22 10:12

Richard