[reportlab-users] Re: warnOnMissingFontGlyphs does not work?

Tim Roberts timr at probo.com
Mon Jun 19 13:22:26 EDT 2006

On Mon, 19 Jun 2006 14:24:42 +0200, G?bor Farkas <gabor at nekomancer.net>

>i have a simple script, like this:
>import reportlab.rl_config
>reportlab.rl_config.warnOnMissingFontGlyphs = 1
>from reportlab.pdfbase import pdfmetrics
>from reportlab.pdfbase.ttfonts import TTFont
>from reportlab.pdfgen import canvas
>pdfmetrics.registerFont(TTFont('arial', 'arial.ttf'))
>c = canvas.Canvas("hello.pdf")
>c.setFont('arial', 32)
>c.drawString(10, 150, "some text with missing glyphs")
>(the text contains some japanese characters that are not in arial.ttf)

How did you write them?  You haven't specified an encoding in this file,
so unless your default code page includes Japanese, there is no way you
could have written Japanese characters in an 8-bit string.

>i assumed that i get a warning, or an exception, but nothing.
>the script finished without problems,
>but in the pdf file (of course), there were only the usual rectangles in 
>the place of the missing glyphs.
>could you please tell me what am i doing wrong?

Unfortunately, that's not the purpose of warnOnMissingFontGlyphs.  All
that it does is enable an error if the font does not contain glyphs for
all of the characters in the current encoding.  It doesn't actually
check each character of each string.

>also, is there a way to specify more fonts, and somehow combine them so 
>that reportlab picks the needed glyph from them? i mean, so that for 
>example, arial.ttf will be the default, but when a glyph is missing, he 
>takes it from kochi-mincho.ttf.

No, that would be unpredictable, which is never a good thing with PDF. 
The whole point is to get precise and predictable output.  However,
Mincho contains all of the glyphs in Arial.  They aren't as pretty, but
you couldn't just use Mincho for everything.

Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

More information about the reportlab-users mailing list