[reportlab-users] Font finding issue in CGI vs. command-line scripts

Dinu Gherman reportlab-users@reportlab.com
Wed, 27 Aug 2003 14:11:52 +0200


I'm trying to generate bitmaps dynamically using RLG from a CGI
application. The baseline is RL 1.18 + recent renderPM on OS X.

Now I'm encountering a strange behaviour related to finding some
font files. Funny enough, these files are found when running the
script below, testFindFont.py from the command-line. But when
running it as a CGI script called by a browser on the same box
the files aren't found anymore! And there is nothing exotic about
the font itself, being Times-Roman.

Here are the details. This is the script I'm running (more about
the commented two lines, later):

# --- testFindFont.py ----------------------------
#!/usr/bin/env python

from reportlab.pdfbase.pdfmetrics import getFont
from reportlab import rl_config

# fontDir = '/Users/dinu/Library/Fonts'
# rl_config.T1SearchPath.insert(0, fontDir)

fontName = "Times-Roman"
font = getFont(fontName)
fontFile = font.face.findT1File()

print "Content-type: text/text"
print "font name:", fontName
print "font file:", fontFile
print "T1SearchPath:", rl_config.T1SearchPath
# ------------------------------------------------

And these are my settings for the T1 search path:

# --- reportlab/rl_config.py ---------------------
   T1SearchPath =  ('/Users/dinu/Library/Fonts',
# ------------------------------------------------

Running the script from the command-line gives the following result:

   [localhost:/Library/WebServer/CGI-Executables] dinu% python 
   Content-type: text/text

   font name: Times-Roman
   font file: /Users/dinu/Library/Fonts/_er_____.pfb
   T1SearchPath: ['/Users/dinu/Library/Fonts', '/Library/Fonts']

While running it from a browser gives this result (fontFile is None!):

   # http://localhost/cgi-bin/testFindFont.py
   font name: Times-Roman
   font file: None
   T1SearchPath: ['/Library/Fonts']

Obviously, the T1 search path differs, but if you uncomment the two
lines in testFindFont.py you still get the same result for the font
file (None via CGI), although the additional entry shows up in the
search path.

In case I don't need fonts anyway I can reduce _setFonts() in the
file reportlab/graphics/renderPM.py to completely ignore this error
and the bitmaps are generated ok, but this is not a general solution.
(Also, I wonder why fonts have to be set at all, before there is a
real need for them?)

Has anybody a good explanation of this behaviour?

BTW, yes, I can copy my fonts from /Users/dinu/Library/Fonts to
/Library/Fonts and everything works again, but this might not be
an option without root privileges. And apart from that it looks
like a pretty strange thing to me...



Dinu C. Gherman
"The making of a journalist: no ideas and the ability to express
them." (Karl Kraus)