[reportlab-users] TTF fontname issue with blanks?!
Robin Becker
robin at reportlab.com
Tue Mar 13 07:58:07 EDT 2007
Dinu Gherman wrote:
> Hi,
>
> 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"):
>
.......
>
> 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))
>
> Regards,
>
........
You're probably right about the rewrite, but the main issue is whether the
space character can be part of the postscript name. Not having written the code
it's impossible to be completely sure why the space was included, but I can
guess that spaces are not allowed in legal postscript identifiers so may be
inapplicable in font identifiers for postscript printers. Probably that test is
only applicable if you're going to run the font in postscript (already a hard
problem for ttf fonts).
--
Robin Becker
More information about the reportlab-users
mailing list