Monday, December 12, 2005

Fonts and Process (or how to make things more complicated)

Last weekend I formatted my computer.

After a few days installing everything back, I found an old CD of mine with thousands of fonts. With nothing better to do, I copied everything to my computer and started examining the fonts.

Have you noticed that, with rare exceptions, the name of the file doesn't match the name of the font?

When we were using Win3.1 that had the file name limitation, it was OK. But today?

Why people still do this kind of thing?

Anyway, searching here and there, I found a nice program from Styopkin Software that does what I was going to do manually: make the file match the font name.

But...

Besides a few duplicated fonts among all those files, the program named a few fonts with wrong names.

And that made my coding fingers itch like hell.

Being a nice developer I wrote a small specification of what the little guy should do, and because I just got my copy of the Visual Studio 2005, I decided that I would build my very own Font Renamer, as a debut project.

Here is what my Font Renamer will do:
  1. Open the font file and examine the name of the font it contains
  2. Close the file and rename it with the name.
Pretty simple, huh? And it is, but I needed to make it complex (oh boy!).

I don't know why I do this kind of stuff... Well... I know. I am a nerd. I admit.

No, not the program. The program it is still simple. The process. The process I made complex.

Well, if I am going to read the font file, I need to know what I need to look, I need to know how the font file is structured, and everything else. So, I searched a little bit more and found all I needed to know (and a little more that I didn't need too) at Microsoft Typography.

After reading all the documentation about the font files, I was starting to think that it was not that good idea to write my own Font Renamer... But since I'm too much of a stubborn for my own good, I decided to keep going.

And then, looking through the .NET documentation, I found the PrivateFontCollection, which methods allowed dig into the font file and allow not only to retrieve information from the file, but also even to draw text with non-installed fonts.

So, with a few lines of code I built my Font Renamer.

0 Comments:

Post a Comment