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

gabor gabor at nekomancer.net
Mon Jun 19 15:04:26 EDT 2006


Tim Roberts wrote:
> On Mon, 19 Jun 2006 14:24:42 +0200, G?bor Farkas <gabor at nekomancer.net>
> wrote:
> 
>> 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")
>> c.showPage()
>> c.save()
>> ===============================================================
>>
>> (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.

hi, thanks for your response..

actually the file started with
# -*- coding: utf-8 -*-

so it was simple to use utf8 encoded characters in the string.

btw. please note, that even without the coding-specifier, i could have 
simply used escape sequences.
this '\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e' for example is nihongo in utf8.


> 
>> 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.

i see..

> 
>> 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.

i'm sorry but i don't agree. what do you mean by unpredictable?
i simply would define a list of truetype files, and reportLab would fall 
back to the next font file in case of missing characters. afaik all the 
browsers do this.


thanks,
gabor


More information about the reportlab-users mailing list