[reportlab-users] Text scaling and finding out how much space
text will take up
Tim Roberts
timr at probo.com
Wed Nov 1 12:30:52 EST 2006
Chris Withers wrote:
> pier carteri wrote:
>
>> Hi,
>> you can obtain the width of a string using the canvas method
>> stringwidth(text, font_name, font_size, encoding)
>
>
> Cool :-)
>
> How will this interact with TrueType fonts?
With few exceptions, all fonts are the same in ReportLab. Note that the
"font_name" here is the registered name, not the TTF file name.
Usually, what you want is the "current font":
w = canvas.stringWidth( "measure this", canvas._fontname,
canvas._fontsize )
I'm not sure where Pier got his code; the canvas.stringWidth method does
not take an "encoding" parameter.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list