Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding System Fonts with Delphi

What is the best way to find all the system fonts a user has available so they can be displayed in a dropdown selection box?

I would also like to distinguish between Unicode and non-Unicode fonts.

I am using Delphi 2009 which is fully Unicode enabled, and would like a Delphi solution.

like image 894
lkessler Avatar asked Dec 31 '08 00:12

lkessler


2 Answers

The Screen.Fonts property is populated via the EnumFontFamiliesEx API function. Look in Forms.pas for an example of calling that function.

The callback function that it calls will receive a TNewTextMetricEx record, and one of the members of that record is a TFontSignature. The fsUsb field indicates which Unicode subranges the font claims to support.

The system doesn't actually have "Unicode fonts." Even the fonts that have the word Unicode in their names don't have glyphs for all Unicode characters. You can distinguish between bitmap, printer, and TrueType fonts, but beyond that, the best you can do is to figure out whether the font you're considering supports the characters you want. And if the font isn't what you'd consider a "Unicode font," but it supports all the characters you need, then what difference does it make? To get this information, you may be interested in GetFontUnicodeRanges.

The Microsoft technology for displaying text with different fonts based on which fonts contain which characters is Uniscribe, particularly font fallback. I'm not aware of any Delphi support for Uniscribe; I started writing a set of import units for it once, but my interests are fickle, and I moved on to something else before I completed it. Michael Kaplan's blog talks about Uniscribe sometimes, so that's another place to look.

like image 160
Rob Kennedy Avatar answered Oct 10 '22 07:10

Rob Kennedy


I can answer half your question, you can get a list of the Fonts that your current environment has access to as a string list from the global Screen object

i.e.

Listbox1.Items.AddStrings(Screen.Fonts);
like image 39
Tim Jarvis Avatar answered Oct 10 '22 07:10

Tim Jarvis