[reportlab-users] Table sizing algorithms - comments welcome
Andy Robinson
reportlab-users@reportlab.com
Sat, 19 Apr 2003 11:12:31 +0100
I'm working on a change to table sizing algorithms,
driven by some urgent requirements at a customer site.
The current algorithm for determinng column widths i
like this:
1. if they are all given, use them
2. if any column has a width of None, or if you
did not give any widths, try to 'size' each
table cell. Strings (multiline or single line)
can always be sized).
3. if a column has a width of None, and any cell
in it contains a flowable or list of flowables
(e.g. a Paragraph), raise an exception.
The problem with paragraphs is that the height and
width cannot be known; one is a function of the
other. Some much smarter algorithm would be needed
to work out the sizes. Do you pick widths to make
I suggest to fix (3) by doing this:
1. as before
2. as before
3. classify all columns inro 3 groups:
- size given by user
- size computable
- size not computable
Take the width of the containing frame,
subtract the widths we know, and divide
the rest evenly between the noncumptable
columns.
A second wrinkle is to correctly work out widths
within spanned row and column ranges.
This is fairly dumb but it means you will
at least get a table out and not a traceback,
and it will not be a significant slowdown.
IMHO it's reasonable to say that if you don't
specify the space, we'll divide it up evenly.
Note that it introduces a dependency betweenm tables
and their ontainers. Until now tables have had
a "known size" which is nothing to do with the
frame - they make themselves big enough for the
content and that's all. If you have a table
with paragraphs and no column widths, it will
now attempt to "fill the frame" - except for the
(user-settable) 6 point margin down the sides.
I won't check in for a day or two as I want
to be very careful that existing stuff is not
affected and write more test cases.
But if anyone has thoughts on a 'smart' way
to assign a width to a paragraph cheaply,
please let me know!
- Andy
p.s. the "guiding principle" on tables is
basically still the same and can be summed
up as follows:
1. if you possibly can, specify all the widths
explicitly
2. only set the row heights if the standard
algorithm does not do what you want.