Archive: Font


Font
  Hi!

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

But!:eek:

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).


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 :p

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!


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.


Font
  :weird: 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...:cry:


Don't worry, be happy :D

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.
; Ifit 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.
; Ifit 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

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


Your code should work just fine.


did not work in nsis 2.0 alpha :(


Could you be a little bit more specific please?


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.


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.


Are you using using about NSIS 2 or 1.98/9?


I used both 1.96 and now 1.98.


Please try the attached script and tell me which messages you get.
Don't forget to change the file extension to .nsi.


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 ;)

Thanks to both of you, but only Joost's fix worked. Thanks again, no more restarts after my installer, YAY! :D


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 ;)


All of the code you need to copy+paste it up there :up:


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.


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!


You can use the same DLL for uninstalling... Please check the code above...


is it necessary to use that .dll for old .fon fonts, or can i just copy them without registering them?


As far as I know you should register them too.


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"

Sorry to bring up and old topic, but...

I'm still not clear on how to register a font without rebooting... :confused:


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.


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"

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.


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
>

Put Fonts.dll in your Plugins directory.
If you don't have a plugins directory you either installed a minimal version of NSIS or you are not using NSIS 2.

Oops. I thought you were talking about the Winamp plugins directory :p

But I'm still getting the same error message. Is this code wrong?

SetOutPath "$WINDIR\system32\"
File "c:\nsis\plugins\Fonts.dll"


First, make sure you got the latest NSIS 2 version, beta 0. You can download it from http://prdownloads.sourceforge.net/n....exe?download.

Now copy fonts.dll to the Plugins dir of NSIS (that is a directory on the system where NSIS is installed). Usually the path is C:\Program Files\NSIS\Plugins.

NSIS will detect your plugin and you can use fonts::registerFont in your NSIS script. NSIS handles the extracting, deleting etc. of the file. There is nothing else where you have to worry about.


I have the latest NSIS2. I'm still getting an error message when I compile that says fonts::registerfont is an invalid function.

I'll try rebooting...


Didn't work. Where does the DLL have to be in relation to the .NSI file, and where does the .NSI file have to be in relation to the NSIS installation path?


The DLL should be copied to the NSIS Plugins directory of YOUR system. That is the subdirectory 'Plugins' in the directory of the NSIS installation. You don't have to worry about extracting it on the user's system, NSIS does everything for you.

At the beginning of the NSIS compiler output, you can see a list of all detected plugins.


Okay, so it doesn't matter where the .NSI file is, I take it...?

I'm gonna post my script here. I'm also having troubles with the instdir page not having the default path...


That's not a NSIS 2.0b0 script, it has .onNextPage and .onPrevPage in it. If you are sure it is supposed to work with b0 notify Jheriko that it is highly out of date.

When you compile the script do you see on the top of the output after the credits stuff a list that starts with:

Processing plugin dlls: "<nsis dir>\plugins\*.dll"

?

If you don't see that line and a list after it you are not using NSIS 2.0b0. If you do, do you see fonts::registerFont there? If it is there, try copying the line exactly as it is and paste into the script, then see if you get errors (don't forget to add the font name if it works). If there is a list and fonts::registerFont is not there you didn't put fonts.dll in the right directory (use !error "${NSISDIR}\Plugins" in any script to see what it is).


Ooookay...I'm gonna tell Jheriko that, after I smack the fuckin shit out of him.

The script compiles to fast for me to read anything at the top, so I wouldn't know


Anyway, thanx, sorry for all the trouble :rolleyes:


Aren't you using MakeNSISw? It's a windows wrapper for NSIS that comes with NSIS. Just right click a script and choose Compile NSI. If you still get a DOS box you are not using NSIS 2 for sure.