Posted by member 1885 on 2006-08-30 15:10:33
If you need to automatically install several fonts with your LiteStep theme you can not rely on the theme.ini, as it will only install one font (strange but true). Instead there's a couple of other methods you can use.
The first one involves a small Microsoft utility called fontinst.exe. You will need to include this 40kB utility with your theme, and the main benefit of this method is that the fonts will be instantly available once they are installed. First of all you will need to download fontinst.exe from here. Then put this file in the same dir as the theme fonts, i.e. "\yourtheme\misc\fonts\". Secondly you'll have to create an inf file that lists the filenames of the fonts you want to install, for example like this:
Save this file as -- for example -- fonts.inf in the font dir. To run the installation simply call,
You will of course need some way of autorunning this command when the theme loads, which most likely will require a scripting module to be loaded. But we'll get to that later.
--------
The second method is similar but uses only a batch file and a reg file to copy and install the fonts. This is mainly for those who are concerned about bloat and/or are unwilling to include third-party apps with their themes. The big drawback is that the fonts will not be ready to use immediately, the machine willl need to be rebooted first.
First create two plain text files in the theme font dir, one called fontinstall.bat and one called fonts.reg (again, this is just an example, call the files what you want). Open fontinstall.bat and enter the following:
You should of course edit the above to match the filenames of your fonts, and the file name of the reg file you created.
Then open the reg file in your editor and enter:
Again, you will need to edit that. To find out the full names of the fonts, double click the ttf files. Don't forget that "(TrueType)" should also be included, as in the above example.
To install the fonts, simply run fontinstall.bat. But as mentioned, this method requires the computer to be restarted in order for the fonts to be available, something you should inform the user of in case you use this method.
--------
Now, for these little tricks to be useful we will need to autorun them somehow, so that the fonts are installed automatically when the theme is run for the first time. As mentioned this step will require a scripting module, unless someone else has a better suggestion for autorunning commands. Normally this isn't a problem since most themes use scripting in one way or another (mzscript/lslua, or if you happen to be Boreas, alias). I'm not going to go into this in great detail, as how to load scripting modules and what their syntax looks like is really beyond the scope of this little guide. Just as an example, running a command on startup using mzscript is done like this:
I'll leave it to the luaphiles to explain how it's done with lslua (and honestly, if you're using lslua in your theme you most likely already know how to do this).
The problem with this is that we don't want the fonts to be re-installed everytime the theme is started or recycled. This is easily solved by defining a variable in your var file that simply states if the theme has been run before or not, and having the above command change it when it's been executed. Let's call it "firstrun". If you then put the entire startup line inside a conditional statement, we can keep it from being run again. Like so:
If you like, you can tack on a [!recycle] at the end of that !execute line, as I'm not 100% sure the fonts will be available if they're copied as the theme is already starting up.
There. I think that was it. Hope it'll be useful for someone, and don't hesitate to tell me if I've made any mistakes. I haven't tested all this extensively, but I believe it should work.
The first one involves a small Microsoft utility called fontinst.exe. You will need to include this 40kB utility with your theme, and the main benefit of this method is that the fonts will be instantly available once they are installed. First of all you will need to download fontinst.exe from here. Then put this file in the same dir as the theme fonts, i.e. "\yourtheme\misc\fonts\". Secondly you'll have to create an inf file that lists the filenames of the fonts you want to install, for example like this:
[fonts]
calibri.ttf
ds-digital.ttf
franklingoth.ttf
calibri.ttf
ds-digital.ttf
franklingoth.ttf
Save this file as -- for example -- fonts.inf in the font dir. To run the installation simply call,
fontinst.exe /f fonts.inf
You will of course need some way of autorunning this command when the theme loads, which most likely will require a scripting module to be loaded. But we'll get to that later.
--------
The second method is similar but uses only a batch file and a reg file to copy and install the fonts. This is mainly for those who are concerned about bloat and/or are unwilling to include third-party apps with their themes. The big drawback is that the fonts will not be ready to use immediately, the machine willl need to be rebooted first.
First create two plain text files in the theme font dir, one called fontinstall.bat and one called fonts.reg (again, this is just an example, call the files what you want). Open fontinstall.bat and enter the following:
copy calibri.ttf %systemroot%\fonts
copy ds-digital.ttf %systemroot%\fonts
copy franklingoth.ttf %systemroot%\fonts
regedit /s fonts.reg
copy ds-digital.ttf %systemroot%\fonts
copy franklingoth.ttf %systemroot%\fonts
regedit /s fonts.reg
You should of course edit the above to match the filenames of your fonts, and the file name of the reg file you created.
Then open the reg file in your editor and enter:
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Calibri (TrueType)"="calibri.ttf"
"DS-Digital Bold Italic (TrueType)"="ds-digital.ttf"
"Franklin Gothic Medium Cond (TrueType)"="franklingoth.ttf"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Calibri (TrueType)"="calibri.ttf"
"DS-Digital Bold Italic (TrueType)"="ds-digital.ttf"
"Franklin Gothic Medium Cond (TrueType)"="franklingoth.ttf"
Again, you will need to edit that. To find out the full names of the fonts, double click the ttf files. Don't forget that "(TrueType)" should also be included, as in the above example.
To install the fonts, simply run fontinstall.bat. But as mentioned, this method requires the computer to be restarted in order for the fonts to be available, something you should inform the user of in case you use this method.
--------
Now, for these little tricks to be useful we will need to autorun them somehow, so that the fonts are installed automatically when the theme is run for the first time. As mentioned this step will require a scripting module, unless someone else has a better suggestion for autorunning commands. Normally this isn't a problem since most themes use scripting in one way or another (mzscript/lslua, or if you happen to be Boreas, alias). I'm not going to go into this in great detail, as how to load scripting modules and what their syntax looks like is really beyond the scope of this little guide. Just as an example, running a command on startup using mzscript is done like this:
*script start "$themedir$misc\fonts\fontinst.exe /f fonts.inf"
I'll leave it to the luaphiles to explain how it's done with lslua (and honestly, if you're using lslua in your theme you most likely already know how to do this).
The problem with this is that we don't want the fonts to be re-installed everytime the theme is started or recycled. This is easily solved by defining a variable in your var file that simply states if the theme has been run before or not, and having the above command change it when it's been executed. Let's call it "firstrun". If you then put the entire startup line inside a conditional statement, we can keep it from being run again. Like so:
IF firstrun=1
*script start !execute ["$themedir$misc\fonts\fontinst.exe /f fonts.inf"][!varset firstrun 0][!varsaveall]
ENDIF
*script start !execute ["$themedir$misc\fonts\fontinst.exe /f fonts.inf"][!varset firstrun 0][!varsaveall]
ENDIF
If you like, you can tack on a [!recycle] at the end of that !execute line, as I'm not 100% sure the fonts will be available if they're copied as the theme is already starting up.
There. I think that was it. Hope it'll be useful for someone, and don't hesitate to tell me if I've made any mistakes. I haven't tested all this extensively, but I believe it should work.