[reportlab-users] Using non-standard fonts on Mac OS X

Tim Jarman reportlab-users@reportlab.com
Wed, 26 May 2004 13:05:13 +0100


Sorry if this is an FAQ, but I don't see the answer anywhere obvious...

I am developing a system to run on Mac OS X.3 (Panther) and the client wants 
output in Arial. (Yes, I could use Helvetica, but sadly the client is a 
typographer and can tell the difference :) I am using ReportLab 1.14.

Now my understanding is that OS X uses TrueType, which seems to be supported 
by a distinct lack of .afm and .pfb files. However, when I try and register 
Arial as a TrueType font using the code below (shamelessly cribbed from the 
User Guide) I get a TTFError saying "Not a TrueType font." 

<code>
import os.path
from reportlab.pdfbase  import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

arial_path = "/Library/Fonts/Arial"
assert os.path.exists(arial_path)

print "Creating TTFont object"
arial = TTFont("Arial", arial_path)   # <--- This is where it fails
print "Registering font"
pdfmetrics.registerFont(arial)
</code>

This happens both for the Apple pre-installed version (/Library/Fonts/Arial) 
and for the one installed by MS Office (/Applications/Microsoft Office 
X/Office/Fonts/Arial).

Is this a known issue? More to the point, anyone know a solution? If all else 
fails I guess I can use Helvetica but it would be nice to crack this one.

TIA

Tim J