# Reading font metrics

**URL:** <https://www.ruby-forum.com/t/reading-font-metrics/67134>\
**Category:** Ruby\
**Created:** [August 31, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/reading-font-metrics/67134 "2006-08-31T23:15:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaySSbiesS\_Smundo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@RaySSbiesS\_Smundo](https://www.ruby-forum.com/u/RaySSbiesS_Smundo)\
**Post date:** [August 31, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/reading-font-metrics/67134/1 "2006-08-31T23:15:13Z")

</div>

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?  
Ta, Ray.

---

<div class="post-metadata">

**Author:** ![RaySSbiesS\_Smundo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@RaySSbiesS\_Smundo](https://www.ruby-forum.com/u/RaySSbiesS_Smundo)\
**Post date:** [August 31, 2006, 11:25pm UTC](https://www.ruby-forum.com/t/reading-font-metrics/67134/2 "2006-08-31T23:25:16Z")

</div>

On 8/31/06, Ray(:bies, :mundo) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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?

I haven’t implemented it yet, but there’s definite information you can  
get from one of the TeX distributions. Look for ttf2afm.

-austin

---

<div class="post-metadata">

**Author:** ![RaySSbiesS\_Smundo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@RaySSbiesS\_Smundo](https://www.ruby-forum.com/u/RaySSbiesS_Smundo)\
**Post date:** [September 6, 2006, 1:54am UTC](https://www.ruby-forum.com/t/reading-font-metrics/67134/3 "2006-09-06T01:54:51Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![RaySSbiesS\_Smundo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/13edae/32.png) [@RaySSbiesS\_Smundo](https://www.ruby-forum.com/u/RaySSbiesS_Smundo)\
**Post date:** [September 6, 2006, 9:34am UTC](https://www.ruby-forum.com/t/reading-font-metrics/67134/4 "2006-09-06T09:34:41Z")

</div>

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?  
> Ta, Ray.

Hi,

I have just started a rubyforge project (‘fontlib’) that should be able  
to do so. I’ll take  
some code from ‘rfil’ (the ruby font installler library - ) and put it  
there. There is currently  
only type1 support and truetype via the ttftoafm (from your favourite  
TeX distribution).

Just in case you want to reply off-list: pg levana . de

Patrick
