PDA

View Full Version : Recommended way to install fonts?



AlexLee
10-03-2003, 03:44 AM
Is there a recommended way to install fonts with Dev Studio 9?

Is it the same for installs to all OSs (Win98, WinME, WinNT, Win2K, WinXP) ?

Or is it as simple as copying (installing) the fonts (.ttf files) to the Windows/Fonts folder?

Thanks,
Alex

alex42
10-03-2003, 04:08 AM
I think its as simple as that...

I never tried with InstallShield, but when I get a font off the net, I just copy it in the fonts folder and I'm ready to go. Shouldn't be any different when installing one.

AlexLee
10-03-2003, 04:30 AM
ah yes, but copying manually invokes different shell commands than using a low-level copy command.

Have you noticed that when you copy and paste a font into the fonts folder, windows actually throws up a "installing fonts" progress dialog... The fonts folder doesn't look like a normal explorer folder... it's "special".

Alex

alex42
10-03-2003, 06:14 AM
dang, you got me there....no, I never actually noticed that more things are done than copying, I was always wondering how it can be that easy..:p

Anyway, you got me feeling guilty, so I tried to retrieve some information on that. You can easily do it when using the Windows Installer, you can choose to create a 'Font-Component' in the component wizard. So you might want to create a InstallScript MSI project.
I don't think theres an automated way to do it in InstallScript only projects.

alex42
10-03-2003, 06:40 AM
it also registers when you execute it after copying
or
check out this function: AddFontResource() in gdi32.dll

good luck.

RobertDickau
10-03-2003, 11:03 AM
I haven't used it, but perhaps see www.installsite.org > InstallScript Samples > Operating System > Font Installation.

AlexLee
10-03-2003, 11:11 AM
Thanks, I've seen that article.

With InstallShield Professional 6.1, I was using the "recommended" approach from InstallShield's own knowledge base - article Q100057 - despite it only referring to IS 3 and IS 5.x Professional.

I would love to see an in-built "Install Font" mechanism in the same way that DLLs can get self-registered, or an internal function.

The main reason for asking this is that I have been having an odd font installation problem on Win98 and Win ME, but we are investigating whether this is actually a red-herring and rather a problem with our application - fonts appear to install correctly, but then don't work in our app after a reboot, then after a second reboot, they work correctly again!

Alex

DevinEllingson
10-03-2003, 04:49 PM
Everyone,

Here is some sample code from an upcoming KB article that shows how to install/uninstall fonts in an event based setup.

Also, we have had many requests for built in font support and are considering adding this for a future release, the tracking # is 1-D2RQ8.

Devin Ellingson
InstallShield Software Corporation



//===========================================================================
//
// File Name: Setup.rul
//
// Description: Blank setup main script file
//
// Comments: Blank setup is an empty setup project. If you want to
// create a new project via. step-by step instructions use the
// Project Wizard to create a new setup instead.
//
//===========================================================================

// Included header files ----------------------------------------------------
#include "ifx.h"

prototype Gdi32.AddFontResource( byref string );
prototype Gdi32.RemoveFontResource( byref string );
#define HWND_BROADCAST 0xffff
#define WM_FONTCHANGE 0x001D

//---------------------------------------------------------------------------
// OnInstallingFile
//
// The OnInstallingFile event is called when a file is about to be installed
// as a result of ComponentTransferData or ComponentMoveData.
//
// szFile will contain the full path of file being installed when the event
// is called.
//---------------------------------------------------------------------------
function OnInstallingFile(szFile)
string szExtension;
string szCount;
number nCount;
begin

ParsePath( szExtension, szFile, EXTENSION_ONLY );
if( szExtension = "ttf" ) then

// Get the current font count and increment.
LogReadCustomNumber( "FontCount", nCount );

// Record this font.
NumToStr( szCount, nCount );
LogWriteCustomString( "Font" + szCount, szFile );

// Write updated count.
nCount = nCount + 1;
LogWriteCustomNumber( "FontCount", nCount );

endif;

end;

//---------------------------------------------------------------------------
// OnMoved
//
// The OnMoved event is called as a result of the setup calling
// ComponentTransferData or ComponentMoveData. The event is called when
// all file transfer operations are completed except for batch
// self-registration which is performed immediately after this event returns.
// During uninstallation this event sent after uninstallation is completed,
// therefore you should not modify system state in this event.
//---------------------------------------------------------------------------
function OnMoved()
number nTotal, nCurrent, nResult;
string szCurrent, szFile;
begin

// Don't do this when uninstalling.
if( REMOVEALLMODE ) then
return 0;
endif;

// Get the installed font count.
LogReadCustomNumber( "FontCount", nTotal );

// Handle each font.
while( nCurrent < nTotal )

// Get the font name.
NumToStr( szCurrent, nCurrent );
LogReadCustomString( "Font" + szCurrent, szFile );

// Register the font.
if( StrLengthChars( szFile ) ) then
AddFontResource( szFile );
endif;

// Next font.
nCurrent = nCurrent + 1;

endwhile;

// Completed registering fonts, notify other apps.
SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );

end;

//---------------------------------------------------------------------------
// OnUninstallingFile
//
// The OnUninstallingFile event is called when a file is about to be
// uninstalled as a result of ComponentTransferData or ComponentMoveData.
//
// szFile will contain the full path of file being installed when the event
// is called.
//---------------------------------------------------------------------------
function OnUninstallingFile(szFile)
string szExtension;
begin

// Remove fonts.
ParsePath( szExtension, szFile, EXTENSION_ONLY );
if( szExtension = "ttf" ) then
RemoveFontResource( szFile );
endif;

end;

Harley0226
10-03-2003, 05:36 PM
You could easily use the Font Component wizard and this will correctly setup the Font installation.

AlexLee
10-04-2003, 03:53 AM
I realised that I had given the wrong KnowldgeBase article number - I use the .h and .rul files given in article number Q106077 which is for Professional 5.x and 6.x.

Harley0226: I am using a script based setup, not an MSI one, and so the Font Component Wizard is not available; thanks for your comment anyhow.

DevinEllingson: Thank you very much for this information. Interestingly, the method you show is similar to the one in the smplfont.rul file given in the article mentioned above. The biggest difference is that you don't register the font in the registry. Maybe this will solve a problem that I have been having? I will have to re-build the installer with that part removed and try it out.

Thanks and I hope that a future release does include built-in font support (sooner rather than later, please!),

Alex

J_Shawver
10-08-2003, 08:29 AM
I have been working on font installation for some time. I was unable to get fonts to install properly unless I include the code to add them to the Fonts key in the registry.

I would also like to see built-in font installation support for InstallScript projects.