Mega Code Archive

 
Categories / Delphi / Examples
 

How to tell if a selected font is a True Type font

Title: How to tell if a selected font is a True Type font? Question: How to tell if a selected font is a True Type font? Answer: uses SysUtils, WinTypes, Classes, Forms, Dialogs, StdCtrls, Controls; function isTrueType(FontName: string): Boolean; procedure Button1Click(Sender: TObject); procedure TForm1.Button1Click(Sender: TObject); begin if isTrueType( 'Courier' ) then showmessage( 'Is a true type font' ) else showmessage( 'Not true type' ); end; function EnumFontFamProc(var LogFont: TLogFont; var TextMetric: TTextMetric; FontType: Integer; TF: TForm1): Integer; export; stdcall; begin Result := 1; if FontType and TRUETYPE_FONTTYPE 0 then Result := 0; {stop enumerating} end; function TForm1.isTrueType(FontName: string): Boolean; var Buffer: array[0..255] of Char; begin StrPCopy(Buffer, FontName); result := (EnumFontFamilies(Canvas.Handle, Buffer, @EnumFontFamProc, LongInt(Self)) = false); end;