[reportlab-users] Some of the ttf font can't be registered

Robin Becker robin at reportlab.com
Wed Sep 16 11:57:31 EDT 2009


Tony Gu wrote:

> Hi,

> I'm trying to register ttf font as stated below. It does work for many

> fonts that I tested, but for certain fonts, it just throw AttributeError

> as below:

>

> pdfmetrics.registerFont(TTFont('hei', 'Heiti.ttf'))

>

> in extractInfo

> psName = names[6].replace(" ", "-") #Dinu Gherman's fix for font names

> with spaces

> AttributeError: 'NoneType' object has no attribute 'replace'

>

> Also, I tested on reportlab.lib.fontfinder module, it will return empty

> list when I do the search in the folder where those above mentioned

> 'Problematic' fonts located.

>

> so far the 'Problematic' fonts that I tested on are all Chinese fonts,

> and probably they contain Chinese type face name. Will this be the

> source of the problem? Is there anyway I can workaround this problem?

>

> Thanks and best regards,

>

> Tony Gu

........

that sounds like it might be right. Can you send me one of the fonts that fails
then I can look at exactly what the problem is.

I suppose that the names[6] is being determined as None which implies that the
postscript name is unset or in some unknown character set.

Dinu's fix is actually hiding the true error I think as it comes immediately before

if not psName:
raise TTFError, "Could not find PostScript font name"

which would get done if psName is None.
--
Robin Becker


More information about the reportlab-users mailing list