Installing fonts with themes Thread last updated on 2007-11-28 10:34:00

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:

[fonts]
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


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"


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


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.

Posted by member 37809 on 2006-08-31 17:50:55 link

There is also the lsfonts module.

It works by loading fonts into memory while it is loaded.

Posted by member 1885 on 2006-08-31 18:04:28 link

Fractal has suggested that as well and I'm perfectly aware of that module. :)

The problem is that lsfonts only makes the fonts available for LiteStep. So in case you include for example XP or syscolor themes, or maybe matching skins for other apps, lsfonts just won't cut it.

Posted by member 248213 on 2006-09-01 08:19:10 link

Well...

I was just going to write: "Yeah, I think I will try updating lsfonts to install fonts if you want" then I got a shudder.

I think that its the same shudder I get when any auto-install is used in my vicinity...

Posted by member 1885 on 2006-09-01 08:50:03 link

Should I take that as you think this is all a bad idea? :)

Posted by member 5575 on 2006-09-01 10:44:32 link

A vbscript could do the same thing, but it'd just be a repackaging of the methods (file copy + regedit) that you already posted. You could set it up so that it could be used in a bang-like fashion, though (e.g., !installFont "franklingoth.ttf"), and have the option to require a confirmation dialog for the more paranoid out there. =P

Posted by member 248213 on 2006-09-01 17:49:39 link

West: No its a good idea, for those that want fonts auto-installed, so yeah a confirm box might be an idea.

Posted by member 37809 on 2006-09-12 15:35:34 link

I guess I'd be in the minority of users who doesn't normally use Windows with admin rights (contradiction because you typically need admin to install litestep, unless you use seg@'s lsportable). To do this means you have an admin account with a password, and you still have the winxp service enabled that lets you use "runas". So, just more work for me for something I guess I wouldn't use anyway—I don't think INFs ask you to run as a different user upon launching. I'm okay with manually installing fonts given this assumption.

Posted by member 305666 on 2007-11-22 16:05:18 link

this thread is so old, i doubt someone will see this, but i tried using the fontisnt.exe method, but i can't get it to work. I have my script.rc set to:

*script start "$themedir$misc\fonts\fontinst.exe /f fonts.inf"


and my fonts.inf reads:

[fonts]
CALIBRI.TTF
CALIBRIB.TTF
H 8pt.ttf
HaxrCor0.fon
STAN0755.TTF
STAN0757CAPS.TTF


naturally, if it worked i'd set an !IfEq Firstload "True" !bang once i know it works, but i can't get it to work in the first place.

when i load the theme, i get this error:

"Windows cannot find 'C:\Litestep\themes\sandwich\misc\fonts\fontsinst.exe / fonts.inf'. Make suer you typed the name correctly, and then try again. To search for a file, click the start button, and then click Search."

Any ideas what the problem could be?

Posted by member 1 on 2007-11-22 18:33:14 link

Are you sure that you aren't missing the f from the /f in your config? I can't see it stripping just that letter.

Posted by member 305666 on 2007-11-22 19:27:41 link

no, that was an accident when i was typing the error, the f was there.

anyway, i came up with a solution to get around this:

instead of calling for the fontinst.exe /f fonts.inf from mzscript, i made a batch file with "fontinst.exe /f fonts.inf" in it, and call the .bat from mzscript instead.

maybe a little tacky, but hey, it works.

on a side note, fontinst.exe seems to have a problem with .fon's, though google says it doesnt. maybe its just the specific font i was trying to use: haxrcorp. can anyone confirm this?

Posted by member 31 on 2007-11-27 17:06:38 link

the problem was with how you were quoting the command. That error indicates it tried to execute the entire string, parameters included, rather than executing the exe and passing the parameters. try:

*script start "$themedir$misc\fonts\fontinst.exe" /f fonts.inf

Posted by member 305666 on 2007-11-28 10:34:00 link

yeah that definitely did the trick! thanks jugg. i was going by what west had originally posted, trusting that the syntax he had was correct. maybe his original post should be edited so no one else will be confused.