This is a feature which I have encountered in 2 different environments. This is (perhaps)
due to the fact, that some internal caching or namespace settings gets messed up. This does
_not_ happen, if using some internal fonts, only if using _custom_ fonts.
traceback looks like:
Traceback (most recent call last):
File "d:\pub\webkit\tst\spotpdfmaker.py", line 272, in run
spm.create_pdf(None, self.outfn)
File "d:\pub\pylib\spm\__init__.py", line 200, in create_pdf
draw_matrix(tmp,mycanvas,hdr)
File "d:\pub\pylib\spm\__init__.py", line 72, in draw_matrix
spotfont=pdfmetrics.EmbeddedType1Face(fontpath+'spot.afm',fontpath+'spot.pfb')
File "c:\python\reportlab\pdfbase\pdfmetrics.py", line 438, in __init__
self._loadMetrics(afmFileName)
File "c:\python\reportlab\pdfbase\pdfmetrics.py", line 494, in _loadMetrics
registerEncoding(enc)
File "c:\python\reportlab\pdfbase\pdfmetrics.py", line 543, in registerEncoding
if enc.isEqual(_encodings[enc.name]):
File "c:\python\reportlab\pdfbase\pdfmetrics.py", line 249, in isEqual
return ((enc.name == other.name) and (enc.vector == other.vector))
NameError: global name 'enc' is not defined
These environments, in which the same thing happens, are Zope and Webware. The catch here is,
that everyting works fine, when reportlab -module is loaded (used) the first time. Following
attemts to use module results in the crash above.
Zope and Webware are environments, which cache code and data for performance boost. it seems
that this is not what reportlab takes care of. Or takes, but it has a bug in it.
Well, there are a simple workaround too, for this feature. Just use construction:
try:
myfont=pdfmetrics.EmbeddedType1Face('font.afm','font.pfb')
pdfmetrics.registerTypeFace(spotfont)
pdfmetrics.registerFont(pdfmetrics.Font('Spot','Spot','WinAnsiEncoding'))
except NameError:
# it is loaded allready
pass
but this is not very convenient for obvious reasons.
Cheers!
-Lode
Logged In: YES
user_id=6946
ReportLab is not thread safe, I suspect/know that these
environments spawn a new thread each time a request is made.
That means you need to make sure things are set up
in each thread or do some kind of job handling where
the setup persists.