Register Fonts: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (FontName plug-in warning)
 
(18 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{PageAuthor|Vytautas}}
<div style="border: 1px solid #808040; background-color:#f8f880; color:#000; padding:0.3em;"><b>Warning: </b>The FontName plug-in does not support Unicode, consider using the [[FontInfo plug-in]] instead.</div>
== Description ==
== Description ==
'''A more advanced version of font registration can be found [http://nsis.sourceforge.net/archive/viewpage.php?pageid=400 here.] Although this version might be more appropriate if you do not need the advanced functionality.'''
'''A more advanced version of font registration can be found [[Advanced Font Installation|here]]. Although this version might be more appropriate if you do not need the advanced functionality.'''


This page has been redesigned to include the functionality of the '''FontName plugin.'''  This will allow you to register TTF fonts without the need to supply the font's registry name. The second macro is designed to register FON fonts and still requires the input of the font's name.
This page has been redesigned to include the functionality of the [[FontName plug-in]]. This will allow you to register TTF fonts without the need to supply the font's registry name. The second macro is designed to register FON fonts and still requires the input of the font's name.


These macros have been designed to work with NSIS 2.0b4 (CVS), although it could possibly be modified to work with earlier versions of NSIS.
These macros have been designed to work with NSIS 2.0b4 (CVS), although it could possibly be modified to work with earlier versions of NSIS.
You should also note that a version of this script is now included in the FontName plugin by default.


''Please note that uninstalling fonts is generally not a good idea since other programs might depend on them.  Exceptions would be custom created fonts which would only be used by your program or when installing a *huge* amount of fonts.''
''Please note that uninstalling fonts is generally not a good idea since other programs might depend on them.  Exceptions would be custom created fonts which would only be used by your program or when installing a *huge* amount of fonts.''
Line 19: Line 26:
   !define CSIDL_FLAG_CREATE 0x8000
   !define CSIDL_FLAG_CREATE 0x8000
!endif
!endif
### Modified Code from FileFunc.nsh    ###
### Original by Instructor and kichik  ###
!ifmacrondef GetFileNameCall
        !macro GetFileNameCall _PATHSTRING _RESULT
                Push `${_PATHSTRING}`
              Call GetFileName
              Pop ${_RESULT}
        !macroend
!endif
!ifndef GetFileName
!define GetFileName `!insertmacro GetFileNameCall`
Function GetFileName
Exch $0
Push $1
Push $2
StrCpy $2 $0 1 -1
StrCmp $2 '\' 0 +3
StrCpy $0 $0 -1
goto -3
StrCpy $1 0
IntOp $1 $1 - 1
StrCpy $2 $0 1 $1
StrCmp $2 '' end
StrCmp $2 '\' 0 -3
IntOp $1 $1 + 1
StrCpy $0 $0 '' $1
end:
Pop $2
Pop $1
Exch $0
FunctionEnd
!endif
### End Code From ###


!macro InstallTTFFont FontFile
!macro InstallTTFFont FontFile
  Push $0 
   Push $R0
   Push $R0
   Push $R1
   Push $R1
Line 26: Line 75:
    
    
   !define Index 'Line${__LINE__}'
   !define Index 'Line${__LINE__}'
 
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName "$0"
    
    
   SetOutPath $FONT_DIR
   SetOutPath $FONT_DIR
   IfFileExists "$FONT_DIR\${FontFile}" ${Index}
   IfFileExists "$FONT_DIR\${FontFileName}" ${Index}
     File '${FontFile}'
     File '${FontFile}'


${Index}:
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
  ClearErrors
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   IfErrors "${Index}-9x" "${Index}-NT"
   IfErrors "" +2
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
!endif


"${Index}-NT:"
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
  goto "${Index}-GO"
"${Index}-9x:"
  StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
  goto "${Index}-GO"
"${Index}-GO:"
   ClearErrors
   ClearErrors
   !insertmacro FontName "$FONT_DIR\${FontFile}"
   !insertmacro FontName "$FONT_DIR\${FontFileName}"
   pop $R2
   pop $R2
   IfErrors 0 "${Index}-Add"
   IfErrors 0 "${Index}-Add"
Line 56: Line 105:
   ReadRegStr $R0 HKLM "$R1" "$R2"
   ReadRegStr $R0 HKLM "$R1" "$R2"
   IfErrors 0 "${Index}-End"
   IfErrors 0 "${Index}-End"
     System::Call "GDI32::AddFontResourceA(t) i ('${FontFile}') .s"
     System::Call "GDI32::AddFontResource(t) i ('${FontFileName}') .s"
     WriteRegStr HKLM "$R1" "$R2" "${FontFile}"
     WriteRegStr HKLM "$R1" "$R2" "${FontFileName}"
     goto "${Index}-End"
     goto "${Index}-End"


Line 63: Line 112:


   !undef Index
   !undef Index
  !undef FontFileName
    
    
   pop $R2
   pop $R2
   pop $R1
   pop $R1
   pop $R0
   Pop $R0  
  Pop $0
!macroend
!macroend


!macro InstallFONFont FontFile FontName
!macro InstallFONFont FontFile FontName
  Push $0 
   Push $R0
   Push $R0
   Push $R1
   Push $R1
    
    
   !define Index 'Line${__LINE__}'
   !define Index 'Line${__LINE__}'
 
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName "$0"
    
    
   SetOutPath $FONT_DIR
   SetOutPath $FONT_DIR
   IfFileExists "$FONT_DIR\${FontFile}" ${Index}
   IfFileExists "$FONT_DIR\${FontFileName}" ${Index}
     File '${FontFile}'
     File '${FontFile}'


${Index}:
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
   ClearErrors
   ClearErrors
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   IfErrors "${Index}-9x" "${Index}-NT"
   IfErrors "" +2
 
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
"${Index}-NT:"
!endif
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
  goto "${Index}-GO"


"${Index}-9x:"
  StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
  goto "${Index}-GO"
"${Index}-GO:"
   ClearErrors
   ClearErrors
   ReadRegStr $R0 HKLM "$R1" "${FontName}"
   ReadRegStr $R0 HKLM "$R1" "${FontName}"
   IfErrors 0 "${Index}-End"
   IfErrors 0 "${Index}-End"
     System::Call "GDI32::AddFontResourceA(t) i ('${FontFile}') .s"
     System::Call "GDI32::AddFontResource(t) i ('${FontFileName}') .s"
     WriteRegStr HKLM "$R1" "${FontName}" "${FontFile}"
     WriteRegStr HKLM "$R1" "${FontName}" "${FontFileName}"
     goto "${Index}-End"
     goto "${Index}-End"


Line 103: Line 154:


   !undef Index
   !undef Index
  !undef FontFileName


   pop $R1
   pop $R1
   pop $R0
   Pop $R0
  Pop $0
!macroend
!macroend


Line 111: Line 164:


!macro RemoveTTFFont FontFile
!macro RemoveTTFFont FontFile
  Push $0 
   Push $R0
   Push $R0
   Push $R1
   Push $R1
Line 116: Line 170:


   !define Index 'Line${__LINE__}'
   !define Index 'Line${__LINE__}'
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName $0


   SetOutPath $FONT_DIR
   SetOutPath $FONT_DIR
   IfFileExists "$FONT_DIR\${FontFile}" ${Index} "${Index}-End"
   IfFileExists "$FONT_DIR\${FontFileName}" ${Index} "${Index}-End"


${Index}:
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
  ClearErrors
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   IfErrors "${Index}-9x" "${Index}-NT"
   IfErrors "" +2
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
!endif


"${Index}-NT:"
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
  goto "${Index}-GO"
"${Index}-9x:"
  StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
  goto "${Index}-GO"
"${Index}-GO:"
   ClearErrors
   ClearErrors
   !insertmacro FontName "$FONT_DIR\${FontFile}"
   !insertmacro FontName "$FONT_DIR\${FontFileName}"
   pop $R2
   pop $R2
   IfErrors 0 "${Index}-Remove"
   IfErrors 0 "${Index}-Remove"
Line 142: Line 196:
"${Index}-Remove:"
"${Index}-Remove:"
   StrCpy $R2 "$R2 (TrueType)"
   StrCpy $R2 "$R2 (TrueType)"
   System::Call "GDI32::RemoveFontResourceA(t) i ('${FontFile}') .s"
   System::Call "GDI32::RemoveFontResource(t) i ('${FontFileName}') .s"
   DeleteRegValue HKLM "$R1" "$R2"
   DeleteRegValue HKLM "$R1" "$R2"
   delete /REBOOTOK "$FONT_DIR\${FontFile}"
   delete /REBOOTOK "$FONT_DIR\${FontFileName}"
   goto "${Index}-End"
   goto "${Index}-End"


Line 150: Line 204:


   !undef Index
   !undef Index
  !undef FontFileName


   pop $R2
   pop $R2
   pop $R1
   pop $R1
   pop $R0
   Pop $R0
  Pop $0
!macroend
!macroend


!macro RemoveFONFont FontFile FontName
!macro RemoveFONFont FontFile FontName
  Push $0 
   Push $R0
   Push $R0
   Push $R1
   Push $R1


   !define Index 'Line${__LINE__}'
   !define Index 'Line${__LINE__}'
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName $0


   SetOutPath $FONT_DIR
   SetOutPath $FONT_DIR
   IfFileExists "$FONT_DIR\${FontFile}" "${Index}" "${Index}-End"
   IfFileExists "$FONT_DIR\${FontFileName}" "${Index}" "${Index}-End"


${Index}:
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
  ClearErrors
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
   IfErrors "${Index}-9x" "${Index}-NT"
   IfErrors "" +2
 
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
"${Index}-NT:"
!endif
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
  goto "${Index}-GO"


"${Index}-9x:"
   System::Call "GDI32::RemoveFontResource(t) i ('${FontFileName}') .s"
  StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
  goto "${Index}-GO"
 
"${Index}-GO:"
   System::Call "GDI32::RemoveFontResourceA(t) i ('${FontFile}') .s"
   DeleteRegValue HKLM "$R1" "${FontName}"
   DeleteRegValue HKLM "$R1" "${FontName}"
   delete /REBOOTOK "$FONT_DIR\${FontFile}"
   delete /REBOOTOK "$FONT_DIR\${FontFileName}"
   goto "${Index}-End"
   goto "${Index}-End"


Line 186: Line 243:


   !undef Index
   !undef Index
  !undef FontFileName


   pop $R1
   pop $R1
   pop $R0
   Pop $R0
  Pop $0
!macroend</highlight-nsis>
!macroend</highlight-nsis>


After including that file in your script you should make sure that the '$FONT_DIR' variable is set to the right fonts directory of the target machine. Also of note is the last command in the fonts Section, it enables Windows and other programs to refresh their fonts lists without the need to restart the computer.  You MUST also include the FontName.nsh file from the FontName plugin.
After including that file in your script you should make sure that the '$FONT_DIR' variable is set to the right fonts directory of the target machine. Also of note is the last command in the fonts Section, it enables Windows and other programs to refresh their fonts lists without the need to restart the computer.  You MUST also include the FontName.nsh file from the FontName plugin.


Calling the RemoveTTFFont and RemoveFONFont macros is identical to their installation variants.
Calling the RemoveTTFFont and RemoveFONFont macros is identical to their installation variants.
The new script includes work by other members of the NSIS community and is marked as such.


<highlight-nsis>!include FontReg.nsh
<highlight-nsis>!include FontReg.nsh
!include FontName.nsh
!include FontName.nsh
!include WinMessages.nsh


[...]
[...]
Line 224: Line 286:
A few notes about using InstallFONFont macro:  You should copy the 'FontName' out of the registry of the Source machine as the fonts might not work if the wrong name or type is specified.
A few notes about using InstallFONFont macro:  You should copy the 'FontName' out of the registry of the Source machine as the fonts might not work if the wrong name or type is specified.


The location of the fonts folder can be attained in a number of different ways, reading a registry key from the target machine or the way shown above, obtained from an example by Lobo Lunar.  Note that this way uses the system plugin and if the size of your installer is a *very* big issue reading the registry might save a few bytes in the final installer size.
The location of the fonts folder can be attained in a number of different ways, reading a registry key from the target machine or the way shown above, obtained from an example by [[User:Joel|Joel]].  Note that this way uses the system plugin and if the size of your installer is a *very* big issue reading the registry might save a few bytes in the final installer size.
 
<s>'''Note:''' The InstallTTFFont macro requires no whitespace in the filename.  Thus C:\My Fonts\LUCON.TTF will fail with an error about too many parameters.  Use a path without spaces to fix this issue.  (ie. C:\MyFonts\LUCON.TTF)</s>


== Version History ==
== Version History ==
; [Update 2010-11-23]
: More path white space fixes
; [Update 2008-04-14]
: Fixed error when TTF Font path has white space.
; [Update 2005-10-23]
: Fixed problem with installation not working when font file was in a different folder as reported by Francois Gelinas
; [Update 2005-01-18]
; [Update 2005-01-18]
: Fixed problem with FON installation as reported by Francois Gelinas  
: Fixed problem with FON installation as reported by Francois Gelinas  
Line 251: Line 321:
PS. Created with a lot of help from members of the NSIS Forum.
PS. Created with a lot of help from members of the NSIS Forum.


Page author: Vytautas
[[Category:System Related Functions]]

Latest revision as of 00:09, 17 October 2022

Author: Vytautas (talk, contrib)


Warning: The FontName plug-in does not support Unicode, consider using the FontInfo plug-in instead.


Description

A more advanced version of font registration can be found here. Although this version might be more appropriate if you do not need the advanced functionality.

This page has been redesigned to include the functionality of the FontName plug-in. This will allow you to register TTF fonts without the need to supply the font's registry name. The second macro is designed to register FON fonts and still requires the input of the font's name.

These macros have been designed to work with NSIS 2.0b4 (CVS), although it could possibly be modified to work with earlier versions of NSIS.

You should also note that a version of this script is now included in the FontName plugin by default.

Please note that uninstalling fonts is generally not a good idea since other programs might depend on them. Exceptions would be custom created fonts which would only be used by your program or when installing a *huge* amount of fonts.

The Script

Save this script as a NSIS Include file in the Include directory of NSIS so that then you can easily get font registration functionality in any script by simply including this file. (Suggested file name: FontReg.nsh)

var FONT_DIR
 
!ifndef CSIDL_FONTS
  !define CSIDL_FONTS '0x14' ;Fonts directory path constant
!endif
!ifndef CSIDL_FLAG_CREATE
  !define CSIDL_FLAG_CREATE 0x8000
!endif
 
### Modified Code from FileFunc.nsh    ###
### Original by Instructor and kichik  ###
 
!ifmacrondef GetFileNameCall
        !macro GetFileNameCall _PATHSTRING _RESULT
                Push `${_PATHSTRING}`
              	Call GetFileName
               	Pop ${_RESULT}
        !macroend
!endif
 
!ifndef GetFileName
	!define GetFileName `!insertmacro GetFileNameCall`
 
	Function GetFileName
		Exch $0
		Push $1
		Push $2
 
		StrCpy $2 $0 1 -1
		StrCmp $2 '\' 0 +3
		StrCpy $0 $0 -1
		goto -3
 
		StrCpy $1 0
		IntOp $1 $1 - 1
		StrCpy $2 $0 1 $1
		StrCmp $2 '' end
		StrCmp $2 '\' 0 -3
		IntOp $1 $1 + 1
		StrCpy $0 $0 '' $1
 
		end:
		Pop $2
		Pop $1
		Exch $0
	FunctionEnd
!endif
 
### End Code From ###
 
!macro InstallTTFFont FontFile
  Push $0  
  Push $R0
  Push $R1
  Push $R2
 
  !define Index 'Line${__LINE__}'
 
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName "$0"
 
  SetOutPath $FONT_DIR
  IfFileExists "$FONT_DIR\${FontFileName}" ${Index}
    File '${FontFile}'
 
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
  ClearErrors
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
  IfErrors "" +2
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
!endif
 
  ClearErrors
  !insertmacro FontName "$FONT_DIR\${FontFileName}"
  pop $R2
  IfErrors 0 "${Index}-Add"
    MessageBox MB_OK "$R2"
    goto "${Index}-End"
 
"${Index}-Add:"
  StrCpy $R2 "$R2 (TrueType)"
  ClearErrors
  ReadRegStr $R0 HKLM "$R1" "$R2"
  IfErrors 0 "${Index}-End"
    System::Call "GDI32::AddFontResource(t) i ('${FontFileName}') .s"
    WriteRegStr HKLM "$R1" "$R2" "${FontFileName}"
    goto "${Index}-End"
 
"${Index}-End:"
 
  !undef Index
  !undef FontFileName
 
  pop $R2
  pop $R1
  Pop $R0 
  Pop $0
!macroend
 
!macro InstallFONFont FontFile FontName
  Push $0  
  Push $R0
  Push $R1
 
  !define Index 'Line${__LINE__}'
 
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName "$0"
 
  SetOutPath $FONT_DIR
  IfFileExists "$FONT_DIR\${FontFileName}" ${Index}
    File '${FontFile}'
 
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
  ClearErrors
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
  IfErrors "" +2
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
!endif
 
  ClearErrors
  ReadRegStr $R0 HKLM "$R1" "${FontName}"
  IfErrors 0 "${Index}-End"
    System::Call "GDI32::AddFontResource(t) i ('${FontFileName}') .s"
    WriteRegStr HKLM "$R1" "${FontName}" "${FontFileName}"
    goto "${Index}-End"
 
"${Index}-End:"
 
  !undef Index
  !undef FontFileName
 
  pop $R1
  Pop $R0  
  Pop $0
!macroend
 
; Uninstaller entries
 
!macro RemoveTTFFont FontFile
  Push $0  
  Push $R0
  Push $R1
  Push $R2
 
  !define Index 'Line${__LINE__}'
 
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName $0
 
  SetOutPath $FONT_DIR
  IfFileExists "$FONT_DIR\${FontFileName}" ${Index} "${Index}-End"
 
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
  ClearErrors
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
  IfErrors "" +2
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
!endif
 
  ClearErrors
  !insertmacro FontName "$FONT_DIR\${FontFileName}"
  pop $R2
  IfErrors 0 "${Index}-Remove"
    MessageBox MB_OK "$R2"
    goto "${Index}-End"
 
"${Index}-Remove:"
  StrCpy $R2 "$R2 (TrueType)"
  System::Call "GDI32::RemoveFontResource(t) i ('${FontFileName}') .s"
  DeleteRegValue HKLM "$R1" "$R2"
  delete /REBOOTOK "$FONT_DIR\${FontFileName}"
  goto "${Index}-End"
 
"${Index}-End:"
 
  !undef Index
  !undef FontFileName
 
  pop $R2
  pop $R1
  Pop $R0  
  Pop $0
!macroend
 
!macro RemoveFONFont FontFile FontName
  Push $0  
  Push $R0
  Push $R1
 
  !define Index 'Line${__LINE__}'
 
; Get the Font's File name
  ${GetFileName} "${FontFile}" $0
  !define FontFileName $0
 
  SetOutPath $FONT_DIR
  IfFileExists "$FONT_DIR\${FontFileName}" "${Index}" "${Index}-End"
 
${Index}:
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
!if "${NSIS_CHAR_SIZE}" <= 1
  ClearErrors
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
  IfErrors "" +2
    StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
!endif
 
  System::Call "GDI32::RemoveFontResource(t) i ('${FontFileName}') .s"
  DeleteRegValue HKLM "$R1" "${FontName}"
  delete /REBOOTOK "$FONT_DIR\${FontFileName}"
  goto "${Index}-End"
 
"${Index}-End:"
 
  !undef Index
  !undef FontFileName
 
  pop $R1
  Pop $R0  
  Pop $0
!macroend

After including that file in your script you should make sure that the '$FONT_DIR' variable is set to the right fonts directory of the target machine. Also of note is the last command in the fonts Section, it enables Windows and other programs to refresh their fonts lists without the need to restart the computer. You MUST also include the FontName.nsh file from the FontName plugin.

Calling the RemoveTTFFont and RemoveFONFont macros is identical to their installation variants.

The new script includes work by other members of the NSIS community and is marked as such.

!include FontReg.nsh
!include FontName.nsh
!include WinMessages.nsh
 
[...]
 
Section "Fonts"
; Alternate for older versions of NSIS: pre NSIS v2.0rc1
;  push $1
;  System::Call "Shell32::SHGetSpecialFolderLocation(i $HWNDPARENT, i ${CSIDL_FONTS}|${CSIDL_FLAG_CREATE}, *i .r0)"
;  System::Call "Shell32::SHGetPathFromIDList(i r0, t .r1)"
;  System::Call 'shell32::SHGetMalloc(*i . r2)' ; IMalloc
;  System::Call '$2->5(i r0)' ; ->Free
;  System::Call '$2->2()' ; ->Release
;  StrCpy $FONT_DIR $1
;  pop $1
 
  StrCpy $FONT_DIR $FONTS
 
  !insertmacro InstallTTFFont 'ARLRDBD.TTF'
  !insertmacro InstallTTFFont 'LUCON.TTF'
  !insertmacro InstallTTFFont 'OCRAEXT.TTF'
  !insertmacro InstallFONFont 'ROMAN.FON'   'Roman (All res)'
  !insertmacro InstallFONFont 'SMALLE.FON'  'Small Fonts (VGA res)'
 
  SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000
SectionEnd

A few notes about using InstallFONFont macro: You should copy the 'FontName' out of the registry of the Source machine as the fonts might not work if the wrong name or type is specified.

The location of the fonts folder can be attained in a number of different ways, reading a registry key from the target machine or the way shown above, obtained from an example by Joel. Note that this way uses the system plugin and if the size of your installer is a *very* big issue reading the registry might save a few bytes in the final installer size.

Note: The InstallTTFFont macro requires no whitespace in the filename. Thus C:\My Fonts\LUCON.TTF will fail with an error about too many parameters. Use a path without spaces to fix this issue. (ie. C:\MyFonts\LUCON.TTF)

Version History

[Update 2010-11-23]
More path white space fixes
[Update 2008-04-14]
Fixed error when TTF Font path has white space.
[Update 2005-10-23]
Fixed problem with installation not working when font file was in a different folder as reported by Francois Gelinas
[Update 2005-01-18]
Fixed problem with FON installation as reported by Francois Gelinas
[Update 2004-01-29]
Updated to use FontName v0.6.
[Update 2003-12-29]
Fixed Macro naming errors, added CSIDL_FLAG_CREATE flag definition.
[Update 2003-12-28]
Added a note about $FONTS variable first included in NSIS v2.0rc1
[Update 2003-11-28]
Fixed problem with TTF font installation on Windows 9x with help from brainsucker and kichik. Added error reporting functionality for the FontName plugin.
[Update 2003-11-18]
Added Remove functionality for the uninstaller as requested by lewellyn.
[Update 2003-11-17]
Added TIMEOUT to the SendMessage command to prevent installer from freezing as suggested by kichik.
[Update 2003-11-12]
Changed the macros so that they no longer require a unique index, with help from Joost Verburg.
[Update 2003-11-11]
Added support for the 'TTF Font Name' plugin. Added macro for FON font installation.

Credits

Vytautas

PS. Created with a lot of help from members of the NSIS Forum.