(page requirements)

How to install fonts

So you're ready to distribute your application as soon as you add the code to install new fonts on to your user's system? Unfortunately, I don't have a quick tip on how to install Windows fonts, so here are the long and boring steps:

For the reminder of this tip, "windows" and "c:\windows" directories will naturally refer to the directory where your version of windows is installed in and "myfont.ttf" will refer to the name of the font file you're about to install.

First of all, you must make sure that the fonts you're about to install does not already exist on the system. Before we get into how to do this, let's go through the final steps of installing fonts:

Windows 3.x / Delphi 1.x

  1. Copy your font files to the "windows\system" directory
  2. List your font resource in the "[fonts]" section of the WIN.INI file
  3. Restart windows.

    If you want to make your fonts available without restarting windows, you should call
    AddFontResource() function as follows:

AddFontResource( 
  'c:\windows\system\myfont.ttf' );
SendMessage( 
  HWND_BROADCAST, 
  WM_FONTCHANGE, 0, 0 );

Windows 95, Windows NT 3.x, Windows NT 4.x

  1. Copy your font files to the proper fonts directory.
    • If you're using Windows NT 3.x, your fonts directory would be "windows\system"
    • If you're using Windows 95 or Windows NT 4.x, default fonts directory would be "windows\fonts"
  2. Call AddFontResource() function and let all top level windows know about the new font by sending the WM_FONTCHANGE message:

    AddFontResource( 
      'c:\windows\system\myfont.ttf' );
    
    { or }
    
    AddFontResource( 
      'c:\windows\fonts\myfont.ttf' );
    
    { and }
    
    SendMessage( 
      HWND_BROADCAST, 
      WM_FONTCHANGE, 0, 0 );


  3. To make your fonts a permanent part of the system, list them in the following registry section:
    • Windows 95:

      HKEY_LOCAL_MACHINE\
      SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts
    • Windows NT:

      HKEY_LOCAL_MACHINE\
      SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts

    Each font listing should have the following format:

    key name: <name of the font>
    key data: <path to the font file>

    for example:

    "My Font (True Type)"
    c:\windows\fonts\myfont.ttf

Now, back to the tricky part -- verifying if the font you're about to install isn't already installed on the system. This is very important; if you install your new font over an existing font, you may experience random [fonts related] problems.

If you're using win 3.1, you should get a list of installed fonts from the WIN.INI "[fonts]" section.

If you're using Windows 95 or Windows NT, you should get a list of installed fonts using the EnumFontFamilies() function. The actual font names could be found by looking in the following registry key:

HKEY_LOCAL_MACHINE\
SOFTWARE\Microsoft\Windows[NT]\CurrentVersion\Fonts

Once you have a list of installed fonts, compare them against the font you're about to install and make sure that...

It does not exist/not installed, or [if it's already installed,] the currently installed version of the font is older than the version you're about to install.

 
 
Applicable Keywords : Delphi, Delphi 1.x, Delphi 2.x, Win32
 
 
 
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Created in HTML Kit editor