Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Add new font files to Windows during install?



Permlink Replies: 2 - Last Post: Aug 30, 2017 2:06 PM Last Post By: Remy Lebeau (Te...
Carl Olsen

Posts: 124
Registered: 3/29/00
Add new font files to Windows during install?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 30, 2017 10:55 AM
I use InnoSetup for the installer, and call some custom Delphi.exe files to do some custom stuff here and there during the install process.

One of those custom actions is that I need to install about 10 custom true type fonts into Windows. (These fonts are later used in some HTML based help screens by a program not written in Delphi)

Googling around, I see what appears to be out of date information that may have been true for Windows XP to to "simply copy the files into the Windows Fonts folder". In reality, it seems copying files into the Windows\Fonts folder is really hard to do. With CopyFile, I do not see that the font ever makes it into the Fonts folder. In some cases, it might give me "access denied", and in other cases CopyFile returns successfully, but the font file does not go into the font folder, as far as I can tell. This is despite the fact that my installer is running as Admin.

An alternate thing we tried is to temporarily load into the font at run-time when needed with code like this:

  AddFontResource(pChar(MyFontFile));
  SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);


...which I can do as a work-around, but is awkward, and sometimes the above code is quite slow (as in 5 to 10 seconds per font)

So, what is the correct way to "install" a font into Windows using Delphi? Ideally, I would like the fonts to go right into the Fonts folder for all applications to use.

Do you have code you know for 100% sure works you might share?

Thanks!

Carl.
Robert Small

Posts: 44
Registered: 5/12/98
Re: Add new font files to Windows during install?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 30, 2017 1:28 PM   in response to: Carl Olsen in response to: Carl Olsen
Carl Olsen wrote:

I use InnoSetup for the installer, and call some custom Delphi.exe
files to do some custom stuff here and there during the install
process.

One of those custom actions is that I need to install about 10 custom
true type fonts into Windows. (These fonts are later used in some
HTML based help screens by a program not written in Delphi)

You need to add the FontInstall parameter to the [Files] entry to
install fonts.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Add new font files to Windows during install?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 30, 2017 2:06 PM   in response to: Carl Olsen in response to: Carl Olsen
Carl Olsen wrote:

I use InnoSetup for the installer, and call some custom Delphi.exe
files to do some custom stuff here and there during the install
process.

Why EXEs and not DLLs?

One of those custom actions is that I need to install about 10 custom
true type fonts into Windows. (These fonts are later used in some
HTML based help screens by a program not written in Delphi)

Why is the HTML not simply using embedded fonts?

Googling around, I see what appears to be out of date information
that may have been true for Windows XP to to "simply copy the files
into the Windows Fonts folder".

That certainly still works in later Windows versions. It is also
possible to install fonts in any folder of your choosing, by
registering the font locations in the following Registry key:

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

In reality, it seems copying files into the Windows\Fonts folder is
really hard to do.

Not really.

With CopyFile, I do not see that the font ever makes it into the Fonts
folder. In some cases, it might give me "access denied", and in
other cases CopyFile returns successfully, but the font file does not
go into the font folder, as far as I can tell.

Then you are likely not copying the files to the correct folder to
begin with. How are you determining the font folder location? You
should be using SHGetFolderPath(CSIDL_FONTS) or
SHGetKnownFolderPath(FOLDERID_Fonts) from the Shell API.

This is despite the fact that my installer is running as Admin.

Then you shouldn't be running into these kind of problems.

An alternate thing we tried is to temporarily load into the font at
run-time when needed with code like this:

  AddFontResource(pChar(MyFontFile));
  SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);


...which I can do as a work-around, but is awkward, and sometimes the
above code is quite slow (as in 5 to 10 seconds per font)

It also installs the font only temporarily. When the user logs out or
reboots, the installed font is removed. To preserve the installation
through restarts, you have to register the font in the above Registry
key.

This is all explained in the AddFontResource() documentation:

https://msdn.microsoft.com/en-us/library/dd183326.aspx

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02