tables.py: fixes to split + spans
authorrgbecker
Tue, 12 Apr 2005 17:23:17 +0000
changeset 2475 24a8e6ffc36a
parent 2474 5462fb8b792d
child 2476 19fb0900fba1
tables.py: fixes to split + spans
reportlab/platypus/tables.py
reportlab/test/test_platypus_tables.py
--- a/reportlab/platypus/tables.py	Fri Apr 01 09:38:18 2005 +0000
+++ b/reportlab/platypus/tables.py	Tue Apr 12 17:23:17 2005 +0000
@@ -1035,6 +1035,7 @@
 
         R0._cr_0(n,A)
         R0._cr_0(n,self._bkgrndcmds)
+        R0._cr_0(n,self._spanCmds)
 
         if repeatRows:
             #R1 = slelf.__class__(data[:repeatRows]+data[n:],self._argW,
@@ -1045,6 +1046,7 @@
             R1._cellStyles = self._cellStyles[:repeatRows]+self._cellStyles[n:]
             R1._cr_1_1(n,repeatRows,A)
             R1._cr_1_1(n,repeatRows,self._bkgrndcmds)
+            R1._cr_1_1(n,repeatRows,self._spanCmds)
         else:
             #R1 = slelf.__class__(data[n:], self._argW, self._argH[n:],
             R1 = self.__class__(data[n:], self._colWidths, self._argH[n:],
@@ -1053,11 +1055,11 @@
             R1._cellStyles = self._cellStyles[n:]
             R1._cr_1_0(n,A)
             R1._cr_1_0(n,self._bkgrndcmds)
+            R1._cr_1_0(n,self._spanCmds)
 
 
         R0.hAlign = R1.hAlign = self.hAlign
         R0.vAlign = R1.vAlign = self.vAlign
-        if self._spanCmds: R0._spanCmds, R1._spanCmds=self._cloneSpanCommands(n)
         self.onSplit(R0)
         self.onSplit(R1)
         return [R0,R1]
@@ -1091,19 +1093,6 @@
             n=n+1
         return split_at
 
-    def _cloneSpanCommands(self,n):
-        spans0=[]
-        spans1=[]
-        for rng in self._spanRanges.values():
-            if rng:
-                if rng[0:2]!=rng[2:4]:
-                    x1,y1,x2,y2=rng
-                    assert (x1<=x2) and (y1<=y2), "_spanRanges does contain unexpected values!"
-                    assert not (y1<n and y2>=n) , "Something got wrong with _getFirstPossibleSplitRowPosition! %r" % [ys,ye,n]
-                    if y1< n and y2< n: spans0.append(("SPAN",(x1,y1  ),(x2,y2  )))
-                    if y1>=n and y2>=n: spans1.append(("SPAN",(x1,y1-n),(x2,y2-n)))
-        return spans0,spans1
-
     def split(self, availWidth, availHeight):
         self._calc(availWidth, availHeight)
         if self.splitByRow:
@@ -1155,7 +1144,6 @@
                 #might be already colours, or convertible to colors, or
                 # None, or the string 'None'.
                 #It's very common to alternate a pale shade with None.
-                #print 'rowHeights=', self._rowHeights
                 colorCycle = map(colors.toColorOrNone, arg)
                 count = len(colorCycle)
                 rowCount = er - sr + 1
@@ -1165,7 +1153,6 @@
                     if color:
                         canv.setFillColor(color)
                         canv.rect(x0, y0, w, -h, stroke=0,fill=1)
-                    #print '    draw %0.0f, %0.0f, %0.0f, %0.0f' % (x0,y0,w,-h)
                     y0 = y0 - h
 
             elif cmd == 'COLBACKGROUNDS':
--- a/reportlab/test/test_platypus_tables.py	Fri Apr 01 09:38:18 2005 +0000
+++ b/reportlab/test/test_platypus_tables.py	Tue Apr 12 17:23:17 2005 +0000
@@ -434,7 +434,7 @@
             ['', '11', '12', '13', '14'],
             ['20', '21', '22', '23', '24'],
             ['30', '31', '', '33', '34']]
-    t=Table(data,style=[
+    sty=[
                     ('GRID',(0,0),(-1,-1),0.5,colors.grey),
                     ('GRID',(1,1),(-2,-2),1,colors.green),
                     ('BOX',(0,0),(1,-1),2,colors.red),
@@ -445,7 +445,8 @@
                     ('SPAN',(0,0),(0,1)),
                     ('BACKGROUND', (2, 2), (2, 3), colors.orange),
                     ('SPAN',(2,2),(2,3)),
-                    ])
+                    ]
+    t=Table(data,style=sty)
     lst.append(Paragraph("Illustrating splits with spans: nosplit", styleSheet['BodyText']))
     lst.append(t)
     lst.append(Spacer(0,6))
@@ -464,6 +465,49 @@
         lst.append(s)
         lst.append(Spacer(0,6))
 
+    data=  [['00', '01', '02', '03', '04'],
+            ['', '11', '12', '13', ''],
+            ['20', '21', '22', '23', '24'],
+            ['30', '31', '', '33', ''],
+            ['40', '41', '', '43', '44']]
+    sty=[
+        ('GRID',(0,0),(-1,-1),0.5,colors.grey),
+        ('GRID',(1,1),(-2,-2),1,colors.green),
+        ('BOX',(0,0),(1,-1),2,colors.red),
+        ('BOX',(0,0),(-1,-1),2,colors.black),
+        ('LINEABOVE',(1,2),(-2,2),1,colors.blue),
+        ('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
+        ('BACKGROUND', (0, 0), (0, 1), colors.pink),
+        ('SPAN',(0,0),(0,1)),
+        ('BACKGROUND',(-2,1),(-1,1),colors.palegreen),
+        ('SPAN',(-2,1),(-1,1)),
+        ('BACKGROUND',(-2,3),(-1,3),colors.yellow),
+        ('SPAN',(-2,3),(-1,3)),
+        ('BACKGROUND', (2, 3), (2, 4), colors.orange),
+        ('SPAN',(2,3),(2,4)),
+        ]
+
+    t=Table(data,style=sty,repeatRows=2)
+    lst.append(Paragraph("Illustrating splits with spans and repeatRows: nosplit", styleSheet['BodyText']))
+    lst.append(t)
+    lst.append(Spacer(0,6))
+    if  0:
+        lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,30)", styleSheet['BodyText']))
+        for s in t.split(4*inch,30):
+            lst.append(s)
+            lst.append(Spacer(0,6))
+        lst.append(Spacer(0,6))
+        lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,36)", styleSheet['BodyText']))
+        for s in t.split(4*inch,36):
+            lst.append(s)
+            lst.append(Spacer(0,6))
+    lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,56)", styleSheet['BodyText']))
+    lst.append(Spacer(0,6))
+    t=Table(data,style=sty,repeatRows=2)
+    for s in t.split(4*inch,56):
+        lst.append(s)
+        lst.append(Spacer(0,6))
+
     lst.append(PageBreak())
     import os, reportlab.platypus
     I = Image(os.path.join(os.path.dirname(reportlab.platypus.__file__),'..','tools','pythonpoint','demos','leftlogo.gif'))