[reportlab-users] Getting the number of lines in a frame

Saketh Bhamidipati saketh.bhamidipati at gmail.com
Mon Aug 21 09:39:11 EDT 2006


On 8/21/06, Robin Becker <robin at reportlab.com> wrote:
>
> 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
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
Is there any way that I can get the text which is written to the frame with
all breaks returned as if they were newlines? That would be enough to solve
my problem.

Let us say that a frame breaks a line of text. Is there some way that I can
get the frame's text with the line break returned as a newline? Then I could
count the number of newlines before breaking, count the number of newlines
after breaking, and the difference is the number of lines.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20060821/010d9f32/attachment.html


More information about the reportlab-users mailing list