[reportlab-users] Handling of too long entries in Table

Robin Becker reportlab-users@reportlab.com
Tue, 15 Oct 2002 15:47:40 +0100

In article <200210151555.54908.w.richert@gmx.net>, Willi Richert <w.richert@gmx.net> writes
>I tried the following solution:
>- data is a 2-dim array with strings in it
>- For each data-element I generate a Paragraph object and see which size it 
>- Paragraph has the member getActualLineWidths0() which shall return a list of 
>the line widths.
>But: When I try to do this I get:
>raceback (most recent call last):
>  File "movatisreport.py", line 135, in ?
>    t = tf.getTable(data)
>  File "movatisreport.py", line 85, in getTable
>    w=p.getActualLineWidths0()
>  File "/usr/lib/python2.2/site-packages/reportlab/platypus/paragraph.py", 
>line 737, in getActualLineWidths0
>    w.append(self.width - frag.extraSpace)
>AttributeError: 'tuple' object has no attribute 'extraSpace'
>The frag contains. e.g. the following at runtime:
>(177.11000000000001, ['Customer']),
>which of course has no extraSpace member.
>Is this a bug? If not, is it possible to get the width of the splitted 
>paragraph differently?
>This problem can't be so difficult.
well this is an experimental method as is indicated by the 0 at the end of the name also whoever
wrote it didn't appreciate that we have two forms of broken line.

try this

        def getActualLineWidths0(self):
                """Convenience function; tells you how wide each line
                actually is.  For justified styles, this will be
                the same as the wrap width; for others it might be
                useful for seeing if paragraphs will fit in spaces."""
                assert hasattr(self, 'width'), "Cannot call this method before wrap()"
                if self.blPara.kind:
                        func = lambda frag, w=self.width: w - frag.extraSpace
                        func = lambda frag, w=self.width: w - frag[0]
                return map(func,self.blPara.lines)

Robin Becker