On installing and removing fonts, Part 5: The takeaway from that is...

by Michael S. Kaplan, published on 2008/07/14 10:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2008/07/14/8730741.aspx


series:

It has been quite an odd little series -- initially showing hopelessness than only got worse, then moving into the normal information one might expect.

This blog is going to talk about the half that seen less often than the previous blog about installation -- this one is going to be about font removal.

Why do I claim it is less common when almost every installer has an uninstaller?

Well, frankly, because most fonts are not uninstalled. They are either build into the platform or they are bought or downloaded later. Most of them live out their existence in a random font folder.

But uninstall is important, since it sometimes happens.

Now Part 2 and Part 3 discuss some of the more difficult aspects of removal. The ones that seem largely intractable.

But we'll deal with those issues as best as we can later.

For now, I'm going to focus on the easier difficult issues....

The process is kind of the reverse of the installation process, not necessarily in this order:

  1. Remove the HKLM\SOFTWARE\Microsoft\Windows[ NT]\CurrentVersion\Fonts entry in the registry that loads the file on session initialization;
  2. Call the RemoveFontResource function;
  3. Remove the file (or at least try to);
  4. Send the WM_FONTCHANGE message so everyone can know now.

Now all of the problems mentioned before are still around, but there are some interesting additional problems....

For example, did you know that calls to AddFontResource and RemoveFontResource are ref-counted?

It's true.

And this makes very little sense if you think about it -- refcounting is an attempt to maintain usage information. And for pairs like LoadLibrary/FreeLibrary where the use is bounded and the same process is probably going to make both calls, this makes sense.

But the most typical usage here is an initial call to AddFontResource on install, with follow-up calls done by GDI on new session starts/reboots in the future, with the font then being available to everyone and with no way to really know if everyone is done yet.

The reference count for the one occasional case where separate calls are made but ignoring the larger issue of the possibility that the font is widely in use seems a bit like a hubcap on a tractor, all things considered.

Does one imagine that a font uninstaller is going to change its mind if it discovered that the font was in use after calling RemoveFontResource?

Well, technically that question is irrelevant -- RemoveFontResource, just like FreeLibrary, does not indicate the difference between decrementing a reference count an the refcount hitting zero -- both function succeed in the exact same way in both cases. And since the font uninstaller is going to remove the font anyway, it actually makes sense to keep calling RemoveFontResource a few more times just for good luck (or until it fails) to do one's best to ensure it is not in use.

This will not help 100% of the time since not all usage it tracked this way. But if you are removing the font anyway it can't hurt (and it might actually help!).

And there is one more removal issue that is worth mentioning... you'll in fact witness me blogging about it tomorrow!

 

This blog brought to you by ʩ (U+02a9, aka LATIN SMALL LETTER FENG DIGRAPH)


no comments

referenced by

2008/09/08 On installing and removing fonts, Part 8: Sometimes being selfish makes you more trustworthy

2008/07/30 On installing and removing fonts, Part 7: What was the question, exactly?

2008/07/15 On installing and removing fonts, Part 6: That's your name? What's your real name? Nah. What was it before you changed it?

go to newer or older post, or back to index or month or day