[reportlab-users] Font Helvetica always used?
Glenn Linderman
v+python at g.nevcal.com
Thu Jun 18 15:32:37 EDT 2015
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20150618/f327bf36/attachment.html>
More information about the reportlab-users
mailing list