[reportlab-users] best way to get fontname and fontsize

John Pywtorak reportlab-users@reportlab.com
Mon, 2 Aug 2004 12:58:19 -0700


On Monday 02 August 2004 11:59 am, Randall Smith wrote:
> Looking through the Canvas API, I do not see a clean way to get the
> fontname and fontsize.  I can use canvas._fontname, canvas._fontsize,
> but those are not in the API.  Is there a better way to get these
> attributes?
>
> Randall

I think I saw this on the list before, but can't remember a specific answer.  
So, here goes a stab.  The docs I think say it defaults to Times-Roman 12 
since that is available in pdf by default.    So from the ipython session 
below you can see that there is a getAvailableFonts, along with setFont 
methods.  You can see what yours defaults to, should be the same, then use 
setFont to change its name and size as you see fit.  rl_config.py may allow 
you to set the default.  At first I thought there may a pythonic way to get 
it using say __getitem__, but not so.  Hope this helps.

In [27]: c.getAvailableFonts()
Out[27]:
['Courier',
 'Courier-Bold',
 'Courier-BoldOblique',
 'Courier-Oblique',
 'Helvetica',
 'Helvetica-Bold',
 'Helvetica-BoldOblique',
 'Helvetica-Oblique',
 'Symbol',
 'Times-Bold',
 'Times-BoldItalic',
 'Times-Italic',
 'Times-Roman',
 'ZapfDingbats']

In [28]: c._fontname
Out[28]: 'Times-Roman'

In [29]: c._fontsize
Out[29]: 12


Johnny P

-- 
Windows
Start Here
Frustrating Hanging Crashing
Blue Screen of Death
Reboot