Author: Jonas Bilinkevicius
I have a situation where I'd like to loop through about 100 font files and extract
their friendly name from the file. Has anyone ever done this?
Answer:
Assuming that all fonts are already installed, you need to use EnumFontFamilies and
a callback function:
1 {the callback function prototype}2 3 function FontEnumProc(LogFont: PEnumLogFont; TextMetrics: PNewTextMetric;
4 FontType: Integer; lParam: LPARAM): Integer; stdcall;
5 6 implementation7 8 function FontEnumProc(LogFont: PEnumLogFont; TextMetrics: PNewTextMetric;
9 FontType: Integer; lParam: LPARAM): Integer; stdcall;
10 begin11 {add the font name and its font type to a list box}12 Form1.ListBox1.Items.AddObject(TEnumLogFont(LogFont^).elfLogFont.lfFaceName,
13 TObject(FontType);
14 {continue enumeration}15 Result := 1;
16 end;
17 18 procedure TForm1.FormClick(Sender: TObject);
19 begin20 EnumFontFamilies(Form1.Canvas.Handle, nil, @FontEnumProc, 0);
21 end;
If the fonts are not installed, you can install them temporarely.