[reportlab-users] TTF fontname issue with blanks?!

Dinu Gherman gherman at darwin.in-berlin.de
Tue Mar 13 06:21:39 EDT 2007


when trying to register a TTF (Universal) using RL 2 I get the
suspicious traceback below, which seems to indicate that blanks
(U+0020) are considered to be invalid characters in the font
name (like in "Universal Regular"):

dinu$ python2.4 test.py
Traceback (most recent call last):
File "test.py", line 61, in ?
pdfmetrics.registerFont(TTFont(name, path))
File "/opt/lib/python2.4/site-packages/reportlab/pdfbase/ttfonts.py",
line 1000, in __init__
self.face = TTFontFace(filename, validate=validate,
File "/opt/lib/python2.4/site-packages/reportlab/pdfbase/ttfonts.py",
line 915, in __init__
TTFontFile.__init__(self, filename, validate=validate,
File "/opt/lib/python2.4/site-packages/reportlab/pdfbase/ttfonts.py",
line 434, in __init__
File "/opt/lib/python2.4/site-packages/reportlab/pdfbase/ttfonts.py",
line 507, in extractInfo
raise TTFError, "psName contains invalid character '%s' ie U+%04X"
% (c,ord(c))
reportlab.pdfbase.ttfonts.TTFError: psName contains invalid character '
' ie U+0020

As it turns out, I can change the respective code in ttfonts.py
to simply ignore this issue (test oc<32 instead of oc<33):

for c in psName:
oc = ord(c)
if oc<32 or oc>126 or c in ('[', ']', '(', ')', '{', '}', '<',
'>', '/', '%'):
raise TTFError, "psName contains invalid character '%s' ie
U+%04X" % (c,ord(c))

When doing this, I can use my TTF file just fine. I'm not sure,
though, if this is the best possible fix or if TTFonts need some
more fundamental checks...

BTW, one might also want to rewrite the code above like this, which
would improve code, save some bytes and print the font name being
rejected when the exception is raised:

for c in psName:
oc = ord(c)
if oc < 32 or oc > 126 or c in "[](){}<>/%":
msg = "psName '%s' contains invalid character '%s' = U+%04X"
raise TTFError, msg % (psName, c, ord(c))



Dinu C. Gherman
I love my Mac. I just wish it came in green! - www.greenmyapple.com

More information about the reportlab-users mailing list