On Aug 31, 2006, at 14:10, Ray(:bies, :mundo) wrote:

> Hi, I'm looking for a way to read Truetype & PS Type 1 font metrics so
> that I can generate a list of installed fonts by name in a Ruby script.
> I have been searching the Internet for some tips on how-to with no luck
> so far. Can anyone point me in the right direction?

Hmm. First, you should figure out if your operating system offers a way 
to do that. For example, on the Macintosh, fonts are almost certainly 
in three different locations (/System/Library/Font, /Library/Fonts, 
~/Library/Fonts) and could easily be in five or more (/System 
Folder/Font, /Network/Library/Fonts). Using RubyCocoa to make a call to 
the OS's font manager delivers a list of installed fonts without having 
to try to track them all down. Dunno what the Win equivalent would be.

Second, if what you want are font names, you don't need any special 
tool for PostScript fonts. .pfb files start with a text header that 
contains the name of the font. Just read the first 1k or so of the file 
into memory, and grep for the line with the info you want. In the case 
of Caflisch Script Bold, your choices are:

	/FullName (Caflisch Script Bold) readonly def
	/FamilyName (Caflisch Script) readonly def
	/FontName /CaflischScript-Bold def

You'll have to figure out which of those you want. All three are 
required in a PostScript font.

TrueType fonts are more likely to be all-binary, and have to be run 
through a translator of some kind. "ttf2afm" is a good tool for this; 
it's available on a lot of platforms. The output will be very similar 
to the above:

	FullName Caflisch Script Bold
	FamilyName Caflisch Script
	FontName CaflischScript-Bold