Font loader from batch files or macros?
Some programs, especially encyclopaedias and dictionaries, need a whole lot of fonts in order to work properly. One program I have in mind installs almost 25! Now, I'm a writer, and I do have my favourite fonts. Thing is, I don't want to have to scroll down through masses of never-to-be-used typefaces in word processor font menus to get to the ones I do use. So, I've been experimenting with tricks to load/unload fonts on a per application basis.
Not as easy as it sounds, as all flavours of Windows are a pain when it comes to installing fonts automatically. The best I've got so far is a combination of a batch file and the Virtual Font Folder program (free; http://www.loseyourmind.com/vff10.asp). The latter watches a user-defined folder – whenever a font gets copied into it, it loads it and broadcasts the change to other apps (so no reboot required). Likewise, whenever a font is removed from the folder, it uninstalls it and broadcasts the change. The combination works well, and would be perfect were it not for Virtual Font Folder being extremely slow: for 25 fonts, it can almost a minute to load them all, and another minute to unload them when I exit the program.
Much quicker would be to open up the required fonts in Windows' own fontview.exe (what you see when you double-click a ttf, otf or pfm font file, or – from a batch file – load shortcuts to each of the required fonts), which has the wonderful effect of instantly loading the fonts and making them available to applications.
I have a couple of problems with that though:
1. 25 fonts loading cluttering up the task bar isn't the slickest way of going about things...
2. I can't find a way of closing the fonts (ie. the 25 instances of fontview.exe) once the main program (eg. the encyclopaedia) exits. Fontview.exe appears to lack command line switches other than the required font path+name, and I can't find a way of referencing it for closure from a batch file (tried and failed with tskill.exe).
My request then is this: does anyone know of an application that might be useful in instantly firing up fonts from a batch file or macro, and also closing them when the same application closes? Ideally using some kind of hidden window so I won't see 25 fonts in the task bar? Might it even be possible to use autohotkey?
Any suggestions would be welcome – thanks in advance.
FontLoader might be what you need except it is not automatic. I understood that you want to connect certain fonts to certain apps.
This can be done within AHK very nice. If Application exists in given moment (timer, for instance etach 2 seconds) load its fonts, if not, unload them. There should be some command line tool to esasy your pain of installing/removing fonts for first moment. I doubt that installing 25 fonts is so long procedure..
So, thing can be done in AHK and is pretty cool to do so...
Note it can be done with tools like Suitcase (coming from Mac world) or Adobe Type Manager, but these are commercial tools, powerful but more or less expensive, that's why I didn't wrote about them.
I understood that you want to connect certain fonts to certain apps.
I came across FontLoader while trying to solve this. Interesting little app, and it loads the fonts instantly, too (also has a choice between loading temporarily and installing permanently), but it's a shell extension and I have no idea how to pass font path/names to it (it's a dll). I'm hoping for a really simply hack, as it must be possible seeing as FontLoader gets font paths/names on the fly whenever a user right clicks them in explorer. Any ideas on how to send input to a dll would be great.
The delay with Virtual Font Folder seems to be that it sends a new system-wide broadcast for each new font that is installed or uninstalled, rather than only sending one broadcast once a batch of them has been installed.
Using AHK would be clever. Thing is I only just came across AHK, so my learning curve is still steep (for now, it's done away with hotkeycontrol xp for keyboard shortcuts for things like emdashes and endashes). "There should be some command line tool" ... I hope so, as it's what I'm looking for.
In my ignorance, the only AHK hack I can think of would be to combine a macro with FontLoader. The macro would store the following actions: open the temporary fonts folder, select all files, right click and choose the FontLoader extension... Do you reckon that's possible?
Sorry, I've currently no idea how to trigger the reinitialising of your target app ...
A. When you install a font all it does is copy the .ttf file to the %systemroot%\fonts and add an entry in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts. This can be automated with a batch file as follows
copy akbar.ttf %systemroot%\fonts
regedit /s font.reg
The font.reg would contain the following:
"Akbar Plain (TrueType)"="akbar.ttf"
In this example it copies akbar.ttf which is called "Akbar Plain (TrueType)" (yes its the Simpsons font ;-) ). The reg scipt actually creates a value called "Akbar Plain (TrueType)" under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts with its contents "akbar.ttf". The new font would be visable once the machine has been rebooted.
If you have some older 16bit applications you may want to add the font to win.ini as well in the [fonts] section. This could be accomplished using a .inf file, e.g.
"E:\WINNT\WIN.INI","Fonts",,"Akbar Plain (TrueType)=akbar.ttf"
sysrefresh - make a general system refresh after modifying your system settings in the Registry.
[here we go ...]
btw. I woudn't move/register an installed ttf, but would simply rename it (or change its attributes) to something the system/app will ignore if should so. JM2€C
Thanks for the suggestion. I did try that registry hack. Once the registry file is merged, opening the windows font folder should in theory update the system's font structure and make the new fonts accessible to programs without rebooting, but in my case it didn't always work. I'm not sure, but I think the problem is that disk caching interferes, especially when reopening the windows font folder after removing the fonts and registry settings. Recently used fonts tend to remain in memory, too, and resist attempts to delete them.
Else it's the traditionally mangled font handling of Windows that's at fault. I did trying disabling disk caching, but the cost to other programs is unacceptable.
The problem with that is that whilst the font itself wouldn't be accessible, the font name would remain in the drop down font lists of programs. The system might not need a complete refresh, but it does need a broadcast - Virtual Font Folder, which uses the dotNet framework, calls the AddFontResource() Win32 API.
I woudn't move/register an installed ttf, but would simply rename it (or change its attributes) to something the system/app will ignore if should so.)
By the way, Virtual Font Folder isn't freeware as I said above, but shareware.
B: I think it is better to find some console tool for installing/removing the fonts. In ahk there is easy mechanism to recognise witch app is runinng and when you notice it you call console tool with list of fonts with that app (in A you would open explorer in folder containing fonts for that , select them all, isue property key, use FontLoader hotkey) then broadcast the message yourself via SendMessage (in A you do nothing) and do vice versa upon application exit.
I think A will be much faster. There is no way to call dll with fonthandler extension yourself as it is COM object and AHK doesn't have COM access (AutoIT has it) and above all, it is complicated procedure...
As a n00b, you can do A if you find appropriate console tool in lets say 7-10 days, as you must learn AHK in the meantime.
I googled a little and found you batch script that you can use to install fonts:
http://www.windowsit... ... 15167.html
THe message is: WM_FONTCHANGE (look at msdn)
You can use this script to install all fonts, for given app and then using AHK you can broadcast the message after executing the batch dynamicaly depending on application that is exectuing
thanks for the suggestion. It's the same script as quoted by BoBo a few posts up, in which broadcasting the change is still the problem.
Funny, I also gandered over to msdn after my last post to see exactly what AddFontResource() and RemoveFontResource() are. Looks like the most elegant solution would be to learn a bit of Visual Basic and write my own loader/unloader... If that sounds viable, can anyone suggest a simple, lightweight, freeware compiler?
Many thanks once again.
Ugh, no! First, VB is made by Microsoft and not freeware... Second, you can do that in AHK, in a few lines of code... Third, VB programs are small, but need a huge runtime, so it isn't so elegant... :-)
Looks like the most elegant solution would be to learn a bit of Visual Basic and write my own loader/unloader... If that sounds viable, can anyone suggest a simple, lightweight, freeware compiler?
See the DllCall manual page.
is definitely the right phrase! Looks like my autohotkey learning curve will be steeper than I thought - this is getting into complete n00b territory for me.
If I understood the last posts correctly, other than the possibility of using autohotkey, another solution would be to use the reg file approach googled by majkinetor and Bobo, and somehow find a way of calling WM_FONTCHANGE without VB. Is that right?
 Ah, I think I'm getting it: use autohotkey's DllCall() to call WM_FONTCHANGE. That might just be much, much simpler than I'd thought.
But that's the idea.
Oh, not exactly related or perhaps even not useful for you, but you might want to take a look at one of my script: TrueType font file informations (name that .TTF font!)