[reportlab-users] Getting the number of lines in a frame
Robin Becker
robin at reportlab.com
Mon Aug 21 09:11:31 EDT 2006
Saketh Bhamidipati wrote:
> I have a frame from which I want to get the number of lines of text.
> Checking for newlines does not work, because the frames wrap the text. I
> want to get the number of lines of text after the frame wraps them.
>
......
> I hope that there is a way for me to count the number of lines of text. I
> don't want to have to measure the width of the characters and calculate the
> lines of text manually.
>
> Thanks in advance,
> Saketh
>
Frames don't know anything about lines they just control space. You add
flowables to them and they either accept the flowable or complain. You can then
choose to split the flowable or jump to the next page etc etc (at least that is
what the doctemplate class attempts).
Frames do know about space so theoretically you can ask them how big they are
and how much space they have left. At present there's no api on frames to do
that. you could just say it is
f.y - f._y1p
but for paragraphs that won't usually help you very much as the vertical height
used by a paragraph depends on the available width
f._getAvailableWidth()
and the style specified leading for the paragraph as well as the text. Our line
breaking algorithm is very naive.
--
Robin Becker
More information about the reportlab-users
mailing list