Use TTF Font Without Installing


/ Published in: Delphi
Save to your folder(s)

Here's how to use a TTF (true type font) in your Delphi application without having to install it in Windows:
In the OnCreate event for the main form in your Delphi application call the AddFontResource API function. The AddFontResource function adds the font resource from the specified file to the system font table.
When an application no longer needs a font resource that it loaded by calling the AddFontResource function, it must remove that resource by calling the RemoveFontResource function. Do this in the OnDestroy event for the main form.


Copy this code and paste it in your HTML
  1. procedure TForm1.FormCreate(Sender: TObject) ;
  2. begin
  3.  
  4. AddFontResource('c:\FONTS\MyFont.TTF') ;
  5. SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
  6. end;
  7.  
  8. {Before application terminates we must remove our font:}
  9. procedure TForm1.FormDestroy(Sender: TObject; var Action: TCloseAction) ;
  10. begin
  11. RemoveFontResource('C:\FONTS\MyFont.TTF') ;
  12. SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
  13. end;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.