[reportlab-users] Bug when importing TrueType fonts with names containing blanks

Dinu Gherman gherman at darwin.in-berlin.de
Thu Nov 29 09:53:41 EST 2007


Hi,

I'm getting an error when trying to use TrueType fonts containing
blanks in their font names. See the following traceback:

Traceback (most recent call last):
...
File "test.py", line 13, in registerTrueTypeFont
font = TTFont(name, path)
File "/usr/local/lib/python2.5/site-packages/reportlab/pdfbase/
ttfonts.py", line 989, in __init__
self.face = TTFontFace(filename, validate=validate,
subfontIndex=subfontIndex)
File "/usr/local/lib/python2.5/site-packages/reportlab/pdfbase/
ttfonts.py", line 898, in __init__
TTFontFile.__init__(self, filename, validate=validate,
subfontIndex=subfontIndex)
File "/usr/local/lib/python2.5/site-packages/reportlab/pdfbase/
ttfonts.py", line 412, in __init__
self.extractInfo(charInfo)
File "/usr/local/lib/python2.5/site-packages/reportlab/pdfbase/
ttfonts.py", line 487, in extractInfo
raise TTFError, "psName=%r contains invalid character '%s' ie U+
%04X" % (psName,c,ord(c))
reportlab.pdfbase.ttfonts.TTFError: psName='UniversalCondensed
Regular' contains invalid character ' ' ie U+0020

I can workaround this with the following simple minded patch to
reportlab/pdfbase/ttfonts.py, but I'm not sure if this is a proper
solution:

--- ttfonts0.py 2007-11-29 15:43:25.000000000 +0100
+++ ttfonts.py 2007-11-29 15:45:29.000000000 +0100
@@ -478,6 +478,7 @@
names[nameId] = N
nameCount -= 1
if nameCount==0: break
+ names[6] = names[6].replace(" ", "-") # FIX(?) DCG
psName = names[6]
if not psName:
raise TTFError, "Could not find PostScript font name"

Regards,

Dinu


More information about the reportlab-users mailing list