Re: Font Helvetica always used?

Glenn Linderman <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <[email protected]>
On 6/18/2015 5:08 AM, Robin Becker wrote:
> On 17/06/2015 20:55, Glenn Linderman wrote:
>> On 6/17/2015 5:09 AM, Robin Becker wrote:
>>> If you don't want to mess with the settings overrides then this code 
>>> at the
>>> start of your initial script should do the trick
> .........
>>
>> So what is the real restriction?  This has to be done before what? 
>> Before first
>> canvas instantiation, or before other imports, or before what, 
>> specifically?
> .......
> The Canvas class needs a default fontname at instantiation. It can be 
> passed in,

But do I understand correctly that simply providing the fontname='arial' 
parameter when instantiating the Canvas class could bypass all the 
settings weirdness, and/or the initial script hacks?

Except, in looking at Canvas, it doesn't seem to have a fontname 
parameter, nor a catchall keyword parameter.  So I don't understand your 
comment "It can be passed in"... is that just a possibility in a 
parallel universe?

> I did some experiments with the technique blessed by GvR here
>
> http://stackoverflow.com/questions/2447353/getattr-on-a-module

The technique you referenced is mind-blowing!

> def canvas_basefontname():
>     from reportlab.pdfbase.ttfonts import TTFont
>     from reportlab.pdfbase.pdfmetrics import registerFont, 
> registerFontFamily
>     registerFont(TTFont('arial','arial.ttf'),)
>     registerFont(TTFont('arial-bold','arialbd.ttf'),)
>     registerFont(TTFont('arial-italic','ariali.ttf'),)
>     registerFont(TTFont('arial-bolditalic','arialbi.ttf'),)
>     registerFontFamily('arial',
>             normal='arial',
>             bold='arial-bold',
>             italic='arial-italic',
>             boldItalic='arial-bolditalic',
>             )
>     return 'arial' 

but canvas.basefontname is a property or variable, not a function. 
Wouldn't this result in self._fontname being a reference to a function, 
instead of the string 'arial'? Or is that one of the side-effects of the 
__getattr__ stuff, that the function is called when the property is 
referenced? (maybe my mind didn't get blown far enough apart)

> This avoids circular importing which happens otherwise. 

I don't understand this comment.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.