Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Font loader from batch files or macros?


  • Please log in to reply
25 replies to this topic
bluegecko
  • Members
  • 14 posts
  • Last active: May 02 2011 01:48 AM
  • Joined: 18 Oct 2006
This is an amazing forum; fittingly so for the amazing autohotkey. Seeing as you lot appear to be the bees' knees in terms of knowing about obscure apps, I'd like to hazard one request.

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.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Mmm, looking for the API to load fonts on the fly, I found FontLoader which can be useful for you.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Strange and cool request.

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...
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

I understood that you want to connect certain fonts to certain apps.

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.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

bluegecko
  • Members
  • 14 posts
  • Last active: May 02 2011 01:48 AM
  • Joined: 18 Oct 2006
Thanks guys

@PhiLho
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.

@majkinetor
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?

BoBo
  • Guests
  • Last active:
  • Joined: --

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

Rem fontinst.bat
copy akbar.ttf %systemroot%\fonts
regedit /s font.reg

The font.reg would contain the following:

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"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.

[UpdateInis]
"E:\WINNT\WIN.INI","Fonts",,"Akbar Plain (TrueType)=akbar.ttf"

[Source]

Sorry, I've currently no idea how to trigger the reinitialising of your target app ... :(

BoBo
  • Guests
  • Last active:
  • Joined: --

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
8)

bluegecko
  • Members
  • 14 posts
  • Last active: May 02 2011 01:48 AM
  • Joined: 18 Oct 2006
BoBo

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.

bluegecko
  • Members
  • 14 posts
  • Last active: May 02 2011 01:48 AM
  • Joined: 18 Oct 2006

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.)

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.

By the way, Virtual Font Folder isn't freeware as I said above, but shareware.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
http://msdn.microsof... ... t_371v.asp
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
You can do that thing you suggested - A: simualate user acction in explorer, select files etc...

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
Posted Image

bluegecko
  • Members
  • 14 posts
  • Last active: May 02 2011 01:48 AM
  • Joined: 18 Oct 2006
@majkinetor
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.

@PhiLho
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.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

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?

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... :-)
See the DllCall manual page.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

bluegecko
  • Members
  • 14 posts
  • Last active: May 02 2011 01:48 AM
  • Joined: 18 Oct 2006

Ugh, no!

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?

[edit] 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.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
I haven't much time to give you a complete solution (perhaps later), but I thought of using DllCall to call AddFontResource (and perhaps RemoveFontResource later), then PostMessage to send the WM_FONTCHANGE. Or not, you probably need to use DllCall to broadcast the message to all programs, I don't recall the exact function name.
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!)
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")