Search code examples
fontsnsis

How do I install a font using NSIS?


I have been trying to build an installer in NSIS that installs a font file. Here's my main installer script:

!include FontName.nsh
!include FontReg.nsh
!include WinMessages.nsh

RequestExecutionLevel admin
InstallDir $DESKTOP

Name "Orange Juice"
OutFile fonttest.exe

Section "install"

    StrCpy $FONT_DIR $FONTS
    !insertmacro InstallTTFFont "orangejuice.ttf"
    DetailPrint "Installing Orange Juice Font..."
    SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000

SectionEnd

I got the file FontReg.nsh from here and copied it verbatim into my Program Files\NSIS\Include folder. I got the file FontName.nsh (along with the corresponding DLL file) from here and copied those verbatim. Yet... when I run this script, the font doesn't get installed. What am I missing?


Solution

    • the FontReg.nsh defines its proper variable to get the font installation directory while you are defining a constant with the same name that does not what you think, also you can use directly the $FONTS variable that points to the system font directory
    • You need to signal the addition of a new font to the system via a broadcast of the WM_FONTCHANGE message

    Try the following: Delete your !define FONT_DIR line and change your section with

    StrCpy $FONT_DIR $FONTS
    !insertmacro InstallTTFFont "orangejuice.ttf"
    SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000