tables.py: fix inspired by Yuan Hong's bug report
authorrgbecker
Tue, 12 Jun 2007 10:56:44 +0000
changeset 2819 0af8d3e7dfc9
parent 2818 ccff6734b82b
child 2820 0c2989e46c6b
tables.py: fix inspired by Yuan Hong's bug report
reportlab/platypus/tables.py
reportlab/test/test_platypus_tables.py
--- a/reportlab/platypus/tables.py	Fri Jun 08 14:08:37 2007 +0000
+++ b/reportlab/platypus/tables.py	Tue Jun 12 10:56:44 2007 +0000
@@ -465,10 +465,10 @@
                 S = self._cellStyles[i] # styles for row i
                 h = 0
                 j = 0
-                for v, s, w in map(None, V, S, W): # value, style, width (lengths must match)
+                for j,(v, s, w) in enumerate(map(None, V, S, W)): # value, style, width (lengths must match)
                     ji = j,i
                     if ji in rowSpanCells:
-                        t = 0.0  # don't count it, it's either occluded or unreliable
+                        continue # don't count it, it's either occluded or unreliable
                     else:
                         if isinstance(v,(tuple,list,Flowable)):
                             if isinstance(v,Flowable): v = (v,)
@@ -477,6 +477,7 @@
                             if canv: canv._fontname, canv._fontsize, canv._leading = s.fontname, s.fontsize, s.leading or 1.2*s.fontsize
                             if ji in colSpanCells:
                                 t = spanRanges[ji]
+                                if not t: continue
                                 w = max(colpositions[t[2]+1]-colpositions[t[0]],w)
                             dW,t = self._listCellGeom(v,w or self._listValueWidth(v),s)
                             if canv: canv._fontname, canv._fontsize, canv._leading = saved
@@ -486,9 +487,8 @@
                         else:
                             v = (v is not None and str(v) or '').split("\n")
                             t = (s.leading or 1.2*s.fontSize)*len(v)
-                        t = t+s.bottomPadding+s.topPadding
+                        t += s.bottomPadding+s.topPadding
                     if t>h: h = t   #record a new maximum
-                    j = j + 1
                 H[i] = h
             if None not in H: hmax = lim
 
--- a/reportlab/test/test_platypus_tables.py	Fri Jun 08 14:08:37 2007 +0000
+++ b/reportlab/test/test_platypus_tables.py	Tue Jun 12 10:56:44 2007 +0000
@@ -692,6 +692,22 @@
     t=LongTable(data, style=sty, colWidths = [50,100,200])
     lst.append(t)
 
+    #Yuan Hong's bug tester
+    lst.append(PageBreak())
+    lst.append(Paragraph('Yian Hong\'s Bug Case (should not blow up)', styleSheet['Heading2']))
+    data = ([['Col1', 'Col2', 'Col3', 'Col4', 'Col5']]+
+                [['01', Paragraph('This is cell one that contains a paragraph.', styleSheet['Normal']), '02', '03', '04']
+                    for i in xrange(50)])
+
+    t = Table(data, ['20%']*5, repeatRows=1)
+    t.setStyle(TableStyle([
+        ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
+        ('BOX', (0,0), (-1,-1), 0.25, colors.black),
+        ('SPAN', (0,50), (-2,50)),
+        ]))
+
+    lst.append(t)
+
     SimpleDocTemplate(outputfile('tables.pdf'), showBoundary=1).build(lst)