tags:

views:

154

answers:

1

In Delphi 2009 using win32, how would I obtain a list of GDI+ fonts available on the system?

Supplementary question: is there a font dialog available that can show just this this of fonts to the user? Bonus points if the same method can be used in Lazerous.

A: 

You should enumerate all fonts in the system:

procedure TPDFFontMapper.EnumFonts;
var
  LF: TLogFont;
begin
  System.FillChar(LF, sizeof(LF), 0);
  LF.lfCharSet := DEFAULT_CHARSET;
  FDC := CreateCompatibleDC(0);
  try
    Windows.EnumFontFamiliesEx(FDC, LF, @EnumFFProc, Integer(Self), 0);
  finally
    Windows.DeleteDC(FDC);
  end;
end;

You should have a function that is called for each font and test if it is a vector font (both TrueType and OpenType fonts are considered truetype fonts):

function EnumFFProc(const LogFont: TEnumLogFontEx; const TextMetric: TNewTextMetric; FontType: DWORD; LParam: DWORD): Integer; stdcall;
begin
  if FontType and TRUETYPE_FONTTYPE = TRUETYPE_FONTTYPE then
    // do sometghing useful with the logfont...
  Result := 1;
end;
Ritsaert Hornstra