How To Install and Uninstall Font from Delphi Code

If you have new font and you need to make it available in every document processing softwares, you just need to copy font files into Windows font directory and you are done. Windows Explorer will manage font registration and housekeeping for you. If you need to know what is going on behind the scened or you need to know how to install/uninstall font programmatically through Delphi code, this short tutorial will explain it. 

Step 1

To add a font resource, Windows Application Programming Interface (API) provides a developer with AddFontResource() function. This function expects font filename to be added. Following code snippet, add Arial font stored in file arial.ttf.

AddFontResource('c:\my custom fonts\arial.ttf'); 

Step 2

Calling AddFontResource() is half of the process. To be able to notify any applications that a new font is installed, you need to broadcast WM_FONTCHANGE message to any applications.


Font installation is now complete. 


Step 3

To remove any installed font, Windows API gives you RemoveFontResource(). Similar to AddFontResource(), this function also expects font filename to uninstall.

RemoveFontResource('c:\my custom fonts\arial.ttf');  

To notify any applications that a font has been uninstalled, you repeat StepTwo above after calling RemoveFontResource().


Share this article!

Follow us!

Find more helpful articles: