tables.py: extend span line blocking to multi lines
authorrgbecker
Thu, 25 Nov 2004 14:18:03 +0000
changeset 2414 81be267fa92c
parent 2413 5147c8ce65d1
child 2415 450d2bc05119
tables.py: extend span line blocking to multi lines
reportlab/platypus/tables.py
reportlab/test/test_platypus_tables.py
--- a/reportlab/platypus/tables.py	Wed Nov 24 18:29:57 2004 +0000
+++ b/reportlab/platypus/tables.py	Thu Nov 25 14:18:03 2004 +0000
@@ -171,6 +171,13 @@
             scp = i1
         if scp<ecp-FUZZ: canvLine(scp,y,ecp,y)
 
+def _multiLine(scp,ecp,y,canvLine,ws,count):
+    offset = 0.5*(count-1)*ws
+    y += offset
+    for idx in xrange(count):
+        canvLine(scp, y, ecp, y)
+        y -= ws
+
 class Table(Flowable):
     def __init__(self, data, colWidths=None, rowHeights=None, style=None,
                 repeatRows=0, repeatCols=0, splitByRow=1, emptyTableAction=None):
@@ -648,9 +655,9 @@
 
             #determine line cap value at position 5. This can be string or numeric.
             if len(cmd)<6:
-                cmd = cmd+(1,)  
+                cmd = cmd+(1,)
             else:
-                cap = cmd[5]  
+                cap = cmd[5]
                 try:
                     if type(cap) is not type(int):
                         cap = LINECAPS[cap]
@@ -687,7 +694,7 @@
             if len(cmd)<10: cmd = cmd + (cmd[3],)
 
             assert len(cmd) == 10
-            
+
             self._linecmds.append(cmd)
         else:
             (op, (sc, sr), (ec, er)), values = cmd[:3] , cmd[3:]
@@ -708,7 +715,7 @@
             if ec < 0: ec = ec + self._ncols
             if sr < 0: sr = sr + self._nrows
             if er < 0: er = er + self._nrows
-            if ccap!=cap:
+            if cap!=None and ccap!=cap:
                 self.canv.setLineCap(cap)
                 ccap = cap
             getattr(self,_LineOpMap.get(op, '_drawUnknown' ))( (sc, sr), (ec, er), weight, color, count, space)
@@ -753,14 +760,9 @@
             for y in rp:
                 _hLine(canvLine, scp, ecp, y, hBlocks)
         else:
-            #multi-lines; position so count==1 and no space gives origin
-            ws = weight+space
-            offset = 0.5*(count-1)*ws
+            lf = lambda x0,y0,x1,y1,canvLine=canvLine, ws=weight+space, count=count: _multiLine(x0,x1,y0,canvLine,ws,count)
             for y in rp:
-                y += offset
-                for idx in xrange(count):
-                    _hLine(canvLine, scp, ecp, y, hBlocks)
-                    y -= ws
+                _hLine(lf, scp, ecp, y, hBlocks)
 
     def _drawHLinesB(self, (sc, sr), (ec, er), weight, color, count, space):
         self._drawHLines((sc, sr+1), (ec, er+1), weight, color, count, space)
@@ -778,13 +780,9 @@
             for x in cp:
                 _hLine(canvLine, erp, srp, x, vBlocks)
         else:
-            ws = weight + space
-            offset = 0.5*(count-1)*ws
+            lf = lambda x0,y0,x1,y1,canvLine=canvLine, ws=weight+space, count=count: _multiLine(x0,x1,y0,canvLine,ws,count)
             for x in cp:
-                x += offset
-                for i in xrange(count):
-                    _vLine(canvLine, erp, srp, x, vBlocks)
-                    x -= ws
+                _hLine(lf, erp, srp, x, vBlocks)
 
     def _drawVLinesA(self, (sc, sr), (ec, er), weight, color, count, space):
         self._drawVLines((sc+1, sr), (ec+1, er), weight, color, count, space)
--- a/reportlab/test/test_platypus_tables.py	Wed Nov 24 18:29:57 2004 +0000
+++ b/reportlab/test/test_platypus_tables.py	Thu Nov 25 14:18:03 2004 +0000
@@ -569,7 +569,8 @@
     lst.append(t)
 
     lst.append(PageBreak())
-    lst.append(Paragraph("This spanning example illustrates automatic grid removal!", styleSheet['BodyText']))
+    lst.append(Paragraph("This spanning example illustrates automatic remova of grids and lines in spanned cells!", styleSheet['BodyText']))
+    lst.append(Spacer(0,6))
     data=  [['Top\nLeft', '', '02', '03', '04', '05', '06', '07'],
             ['', '', '12', 'Span (3,1) (6,2)', '','','','17'],
             ['20', '21', '22', '', '','','','27'],
@@ -589,6 +590,8 @@
             ('SPAN',(3,1),(6,2)),
             ('BACKGROUND',(3,1),(6,2), colors.peachpuff),
             ('VALIGN',(3,1),(6,2),'TOP'),
+            ('LINEABOVE', (0,2),(-1,2), 1, colors.black, 0, None, None, 2, 2),
+            ('LINEBEFORE', (3,0),(3,-1), 1, colors.black, 0, None, None, 2, 2),
             ])
     lst.append(t)