Skip to content
⌘ NSIS Forum Archive

Font

58 posts

ghale#

Font

Hi!

Ok, I create an installer that include a font.
I install font to target machine.

But!😱

The font is not "registered(?)" in Windows automatically.

I have to manually open and close Fonts Dir with Control Panel.

What can I do to install a font and "register" it with Windows automagically?

Sorry for my english,
I speak only Italiano (and not so very well).
Yathosho#
i'm not 100% sure since i didn't test it, but try the following (i used example Time New Roman):

Windows NT/2000/XP
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" \
"Times New Roman (TrueType)" "TIMES.TTF"
Windows 95/98/ME
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" \
"Times New Roman (TrueType)" "TIMES.TTF"
you can use the GetWindowsVersion function (see NSIS\functions.htm) to determine the windows version.

hope it works, let us know 😛
ghale#
Yes, yes. It works!!!🙂
Thank you.
After writing keys in registry, I need to reboot machine.

After, I find all fonts ready for applications!!!

Thank you!
kichik#
There is a way of doing this without requiring a reboot.
This way involves Windows' API calls so you will need an external DLL or EXE.

First you need to call AddFontResource(lpszFilename) with the font's file name (for example: AddFontResource("TIMES.TTF"). Next you need to broadcast a message so all of the runnint applications will reload the system font table. To do so, you should use PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0).

If you need any help writing the DLL/EXE let me know.

KiCHiK

EDIT: If you are building an uninstaller too you will need to use RemoveFontResource(lpszFilename), and manually delete the registry entry. You will also need to send another WM_FONTCHANGE message.
ghale#
Font

🤪 I need a DLL to call AddFontResource("TIMES.TTF") and PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0).

Ok.

I can use some NSIS function to do the same thing?

Sorry, but I have no idea on writing a DLL making this...😢
kichik#
Don't worry, be happy 😁

Attached is the DLL + source.

To use it in your installation add the following code:
GetTempFileName $R0
File /oname=$R0 fonts.dll
; Change this line to your real font name.
; If it is not in the default Windows' directory wirte it's full path!
Push "MyFontName.TTF"
CallInstDLL $R0 registerFont 
To use it in your uninstallation add the following code:
GetTempFileName $R0
File /oname=$R0 fonts.dll
; Change this line to your real font name.
; If it is not in the default Windows' directory wirte it's full path!
Push "MyFontName.TTF"
CallInstDLL $R0 unregisterFont 
These functions only call AddFontResource/RemoveFontResource and PostMessage so don't forget to copy/delete the font yourself and add/remove it from the registry.

KiCHiK
cchian#
Kichik,

Your code and dll works great, but how do you make it register more than one font? Will this work?:

GetTempFileName $R0
File /oname=$R0 fonts.dll
; Change this line to your real font name.
; If it is not in the default Windows' directory write it's full path!
Push "Font1.TTF"
CallInstDLL $R0 registerFont
Push "Font2.TTF"
CallInstDLL $R0 registerFont
Push "Font3.TTF"
CallInstDLL $R0 registerFont
Push "Font4.TTF"
CallInstDLL $R0 registerFont
Guest#
Just to remind you: NSIS 2.0a0 is not free of bugs! The latest supported and official version is NSIS 1.98. I suggest that you use that one for compiling your scripts.

-Hendri.
ParallaxTZ#
I followed all the instructions above, but when I run the installer, this happens:

rosInst.exe - Bad Image
The application or DLL G:\Documen~1\Markri~Locals~1\Tempnst964.tmp is not a valid Windows image. Please check this against your installation disk.

my script file is attached.

Any help would be most appreciated.

[edit]
I'm on an XP Pro system.
kichik#
Please try the attached script and tell me which messages you get.
Don't forget to change the file extension to .nsi.
Joost Verburg#
Originally posted by ParallaxTZ
I followed all the instructions above, but when I run the installer, this happens:

rosInst.exe - Bad Image
The application or DLL G:\Documen~1\Markri~Locals~1\Tempnst964.tmp is not a valid Windows image. Please check this against your installation disk.

my script file is attached.

Any help would be most appreciated.
I'm on an XP Pro system.
GetTempFileName $R0
File /oname=$R0 G:\windows\system32\fonts.dll
Push "MAEL____.TTF"
CallInstDLL $R0 registerFont
You are using GetTempFileName. This creates the temp file. The File command does not overwrite the file created by GetTempFileName, that's why the DLL does not work.

You should SetOverwrite On before the File command.

GetTempFileName $R0
SetOverwrite On
File /oname=$R0 G:\windows\system32\fonts.dll
SetOverwrite ifnewer
Push "MAEL____.TTF"
CallInstDLL $R0 registerFont
I have not tested this 😉
ParallaxTZ#
Thanks to both of you, but only Joost's fix worked. Thanks again, no more restarts after my installer, YAY! 😁
Yathosho#
i had no errors during the compilation, but it just didnt install or copy the fonts. maybe i am stupid, could you please paste some code doing this with a common windows font, so it will work in my code only copy+pasted? pleeease 😉
ParallaxTZ#
Attached is my .nsi file (.zipped since you can't upload .nsi files), it appears to work perfectly for both 9x based and NT based systems. Hopefully you can follow it.
Yathosho#
can i use the same .dll to uninstall the font again? it would surely be better -even for testing purposes- to remove the font everytime for the system i'm testing on. so far i had to send all installers to friends, which consumes quite some time. uninstalling would be a great help!
Yathosho#
is it necessary to use that .dll for old .fon fonts, or can i just copy them without registering them?
Sunjammer#
Reminder

Just a little reminder that since NSIS 2.0a4 you can make this kinda thing:-
GetTempFileName $R0 
File /oname=$R0 fonts.dll 
Push "Font1.TTF" 
CallInstDLL $R0 registerFont 
Push "Font2.TTF" 
CallInstDLL $R0 registerFont 
Push "Font3.TTF" 
CallInstDLL $R0 registerFont 
Push "Font4.TTF" 
CallInstDLL $R0 registerFont 
much simpler:-
fonts::registerFont "Font1.TTF"
fonts::registerFont "Font2.TTF"
fonts::registerFont "Font3.TTF"
fonts::registerFont "Font4.TTF" 
dirkdeftly#
Sorry to bring up and old topic, but...

I'm still not clear on how to register a font without rebooting... 😕
kichik#
Put Fonts.dll in your Plugins directory.
After you copy the font over and write the registry entries, just call Fonts::registerFont "FontName"
If you have installed the font in the Windows font folder, just use its name (times.ttf for example), if not use its full path ($INSTDIR\times.ttf for example).

That's it, the font is then registered, and you don't need a reboot.

For the uninstaller, remove the registry entries, call Fonts::unregisterFont "FontName" and delete the font.
dirkdeftly#
I can't find Fonts.dll, is fontreg.exe the same thing? It seems to work okay compiling...

fyi I'm running Win98 SE.

Am I right in assuming that I need to put the GetWindowsVersion function at the top of the script, and use something along the lines of ParalaxTZ's script:
Section "Adolescense font"
SectionIn 4
RegisterFonts:
StrCmp $0 '95' lbl_95_98_me
StrCmp $0 '98' lbl_95_98_me
StrCmp $0 'ME' lbl_95_98_me
lbl_nt_2k_xp:   
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Adolescense" "Adolesce.TTF"
lbl_95_98_me:
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" "Adolescense" "Adolesce.TTF" 
kichik#
Never heard of font reg... A zip file containing fonts.dll is attached above in one of my posts...

To add the registry writing you must call GetWindowsVersion (find it in the useful functions section in the docs), Pop and compare like in the script you just wrote. Then call registerFont like I said in the earlier post.
dirkdeftly#
Thanx, didn't see that.

Now I'm getting an error message:
WriteRegStr: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\Adolescense=Adolesce.TTF
WriteRegStr: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts\Adolescense=Adolesce.TTF
Invalid command: fonts::registerfont
Error in script "C:\NSIS\tff2.0\custom.nsi" on line 229 -- aborting creation process

This is the end of my script:

lbl_nt_2k_xp:   
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "Adolescense" "Adolesce.TTF"
lbl_95_98_me:
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" "Adolescense" "Adolesce.TTF"
fonts::registerfont "Adolesce.TTF"
SectionEnd