PDA

View Full Version : How to get Font Names


JimS
03-14-2005, 07:41 PM
How do I get the Font Name from the font Filename?

i.e
Font Name = Arial, Font Filename = Menu1.ttf
Font Name = Arial Black, Font Filename = ARIBLK.TTF

I can get a list or table of the Font Filenames on a machine, but I want to convert these into a list or table of the common Font Names. Any ideas?

Thanks.

Ted Sullivan
03-14-2005, 07:46 PM
Ouch! I can tell you for sure that doing such a thing is about as convoluted a thing as can be attempted. We do it internally in AutoPlay Media Studio 5.0, Setup Factory 7.0 and TrueUpdate 2.0 for packaging up the fonts referenced in your projects. It required some pretty involved parsing of the TTF file format (which isn't documented very well either...).

Corey
03-14-2005, 07:50 PM
Another approach might be to find/create a list of the most common font/filename associations and compare against that. Two centavos anyhow...

JimS
03-15-2005, 04:45 AM
Thanks guys, I’ve just started my search so I’m not quite ready yet to give up and go with the list of common names. It’s a good idea Corey, and I’ll go that way if I have to, but I’m still hoping to find a DLL or something.

Ted, I’ve tried opening the font files with a text editor, to see if I can figure an easy way to parse the name, but so far I can’t figure a pattern to search for, that would work with all the files.

It seems like a fairly common feature in software, so I figured that Windows would have a built in facility for it somewhere. “Convoluted” doesn’t sound too promising for a half-baked programmer like me. Still, maybe I’ll get lucky.

Either way, thanks for the replies.

JimS
03-15-2005, 06:08 AM
Looks like it might be possible to get them from the registry

This works on XP machines

all_keys = Registry.GetValueNames(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
TextFile.WriteFromTable("AutoPlay\\Docs\\fonts.txt", all_keys, false);

Worm
03-16-2005, 08:34 PM
Maybe something like this:

JimS
03-17-2005, 01:56 AM
Worm, what can I say? Thank you doesn’t seem to be nearly enough. You are incredible my friend. Your on fire too, what is that three or four new DLL’s this week? How do you ever find the time? I checked out your function on this, and your code is so tight that it is a beautiful thing to look at. It’s always a pleasurable learning experience for a fellow like me to have the chance to learn code from a master like you. Now if I could just be smart enough to retain it for the next time I’m writing a similar chunk of code.

As good as this forum is, it just wouldn’t be the same without your amazing skill, generosity, and unequivocal mastery. All that, and your incredible under spoken, and nonchalant attitude to boot. I’m telling you that if I had one-tenth the talent you have, I’d be stopping strangers on the street, just to brag about it. :D

Thanks Brad, you’ve come to my rescue again. :yes

Corey
03-17-2005, 01:58 AM
As good as this forum is, it just wouldn’t be the same without your amazing skill, generosity, and unequivocal mastery.

No question about it. :yes

Intrigued
03-17-2005, 10:04 AM
Worm, I see you as the programmer-Santa of our time!

.dll Bling-Bling goes a long way with us AMS'sters!



:yes

yosik
03-18-2005, 05:17 AM
Jim, what you said is on-the-dot!
Brad is one cool guy, ready to help and a MASTER at programming!
and, Brad! Don't be shy, Man! You ARE the Numero Uno!

Yossi

Worm
03-18-2005, 08:18 AM
Wow! You are all way too kind.

Thank you.