[reportlab-users] Line numbers in Platypus

Andy Robinson andy at reportlab.com
Thu Mar 20 03:58:35 EDT 2008


On 20/03/2008, Jonathan Claggett <jonathan at claggett.org> wrote:

>

> > One of the requirements of these bills is that the body has line numbers

> and I'm not sure how or even if line numbering can occur with variable

> height objects like the Paragraph. My initial reaction after reading the

> user manual is 'probably'.


This would be useful if we get it right - not just for lawyers, but
for printing chunks of source code too. But I think this approach may
not work as the XML tags are used to create a tree of objects by the
time it is line-wrapped, and I don't think you can use them in the
wrapped lines . Here's what I suggest:

1. suggest subclassing or extending Paragraph to have some new attributes:
initialLineNumber (default 1) and finalLineNumber (starts at None)

2. Your afterFlowable and beforeFlowable can remember this between
calls and set the start line number for each para before it is drawn.

3. As it draws, your subclass can use canvas.drawString easily to do
some numbers to the left of the paragraph. There is nothing to stop
you using a negative X coordinate to draw in the marging. Or, if it's
easier, remember the y coordinates of each line in a little array and
draw them afterwards.

Get this right and we could possibly check it in - at least the counting part.

Paragraphs are a bit of a mess due to incessant unrolling of loops,
special optimised cases and low-level trickery to get the performance
we need, and due to features being added over the years. BUT, we
could probably have them remembering stuff about how they were laid
out, so a user subclass could easily do stuff like numbering after
they were wrapped.

Best Regards,

--
Andy Robinson
CEO/Chief Architect
ReportLab Europe Ltd.
165 The Broadway, Wimbledon, London SW19 1NE, UK
Tel +44-20-8544-8049


More information about the reportlab-users mailing list