fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
authorrobin
Mon, 15 Feb 2016 14:59:35 +0000
changeset 4250 3ed1ea9c1fc4
parent 4249 8fc7d11bdee0
child 4251 00972564460a
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
src/reportlab/__init__.py
src/reportlab/platypus/tables.py
tests/test_platypus_tables.py
--- a/src/reportlab/__init__.py	Wed Feb 10 14:01:29 2016 +0000
+++ b/src/reportlab/__init__.py	Mon Feb 15 14:59:35 2016 +0000
@@ -1,9 +1,9 @@
 #Copyright ReportLab Europe Ltd. 2000-2015
 #see license.txt for license details
 __doc__="""The Reportlab PDF generation library."""
-Version = "3.2.17"
+Version = "3.2.18"
 __version__=Version
-__date__='20160112'
+__date__='20160215'
 
 import sys, os, imp
 
--- a/src/reportlab/platypus/tables.py	Wed Feb 10 14:01:29 2016 +0000
+++ b/src/reportlab/platypus/tables.py	Mon Feb 15 14:59:35 2016 +0000
@@ -1190,11 +1190,13 @@
         '''
         pass
 
-    def _cr_0(self,n,cmds):
+    def _cr_0(self,n,cmds,nr0):
         for c in cmds:
             c = tuple(c)
             (sc,sr), (ec,er) = c[1:3]
-            if isinstance(sr,strTypes) or sr>=n: continue
+            if isinstance(sr,strTypes): continue
+            if sr<0: sr += nr0
+            if sr>=n: continue
             if er>=n: er = n-1
             self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:])
 
@@ -1230,8 +1232,8 @@
             else:
                 if er>=0 and er<n: continue
                 if sr>=0 and sr<n: sr=0
-                if sr>=n: sr = sr-n
-                if er>=n: er = er-n
+                if sr>=n: sr -= n
+                if er>=n: er -= n
                 self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:])
 
     def _splitRows(self,availHeight):
@@ -1264,8 +1266,9 @@
                 ident=ident,
                 spaceBefore=getattr(self,'spaceBefore',None))
 
+        nrows = self._nrows
+        ncols = self._ncols
         #copy the commands
-
         A = []
         # hack up the line commands
         for op, (sc,sr), (ec,er), weight, color, cap, dash, join, count, space in self._linecmds:
@@ -1277,10 +1280,10 @@
                     sr = n
                     er = n
 
-            if sc < 0: sc = sc + self._ncols
-            if ec < 0: ec = ec + self._ncols
-            if sr < 0: sr = sr + self._nrows
-            if er < 0: er = er + self._nrows
+            if sc < 0: sc += ncols
+            if ec < 0: ec += ncols
+            if sr < 0: sr += nrows
+            if er < 0: er += nrows
 
             if op in ('BOX','OUTLINE','GRID'):
                 if sr<n and er>=n:
@@ -1311,10 +1314,10 @@
             else:
                 A.append((op,(sc,sr), (ec,er), weight, color, cap, dash, join, count, space))
 
-        R0._cr_0(n,A)
-        R0._cr_0(n,self._bkgrndcmds)
-        R0._cr_0(n,self._spanCmds)
-        R0._cr_0(n,self._nosplitCmds)
+        R0._cr_0(n,A,nrows)
+        R0._cr_0(n,self._bkgrndcmds,nrows)
+        R0._cr_0(n,self._spanCmds,nrows)
+        R0._cr_0(n,self._nosplitCmds,nrows)
 
         if ident: ident = IdentStr(ident)
         if repeatRows:
--- a/tests/test_platypus_tables.py	Wed Feb 10 14:01:29 2016 +0000
+++ b/tests/test_platypus_tables.py	Mon Feb 15 14:59:35 2016 +0000
@@ -848,6 +848,73 @@
         "Make a document full of tables"
         old_tables_test()
 
+    def test2(self):
+        '''buggy table example from Lele Gaifax https://bitbucket.org/lele/
+        should split to two pages with the blue box on page 1 complete
+        '''
+        from reportlab.lib.pagesizes import A4, landscape
+
+        data = [
+            ['Date', '08 AM', '', '', '', '09 AM', '', '', '', '10 AM', '', '', '', '11 AM', '', '', '', '12 PM', '', '', '', '01 PM', '', '', '', '02 PM', '', '', '', '03 PM', '', '', '', '04 PM', '', '', '', '05 PM', '', '', '', '06 PM', '', '', '', '07 PM', '', '', '', '08 PM', '', '', '', '09 PM', '', '', '', '10 PM', '', '', '', '11 PM', '', '', ''],
+            ['04-30-2015', '', '', '', '', '09:00 AM\n:\n01:00 PM\nSupervision\nReception', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
+            ['05-01-2015', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '01:00 PM\n:\n04:00 PM\nSupervision\nInfo point 1', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
+            ['05-03-2015', '', '', '', '', '09:00 AM\n:\n01:00 PM\nSupervision\nReception', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
+            ['05-04-2015', '', '', '', '', '', '', '', '', '10:00 AM\n:\n01:00 PM\nSupervision\nInfo point 2', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '03:00 PM\n:\n05:30 PM\nSupervision\nInfo point 3', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
+            ['05-05-2015', '', '', '', '', '09:00 AM\n:\n01:00 PM\nSupervision\nReception', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
+            ['05-08-2015', '', '', '', '', '', '', '', '', '10:00 AM\n:\n01:00 PM\nSupervision\nInfo point 2', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '02:30 PM\n:\n05:30 PM\nSupervision\nInfo point 3', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
+            ['05-10-2015', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '04:00 PM\n:\n08:00 PM\nSupervision\nInfo point 2', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
+         ]
+
+        style = [
+            ('SPAN', (1, 0), (4, 0)),
+            ('SPAN', (5, 0), (8, 0)),
+            ('SPAN', (9, 0), (12, 0)),
+            ('SPAN', (13, 0), (16, 0)),
+            ('SPAN', (17, 0), (20, 0)),
+            ('SPAN', (21, 0), (24, 0)),
+            ('SPAN', (25, 0), (28, 0)),
+            ('SPAN', (29, 0), (32, 0)),
+            ('SPAN', (33, 0), (36, 0)),
+            ('SPAN', (37, 0), (40, 0)),
+            ('SPAN', (41, 0), (44, 0)),
+            ('SPAN', (45, 0), (48, 0)),
+            ('SPAN', (49, 0), (52, 0)),
+            ('SPAN', (53, 0), (56, 0)),
+            ('SPAN', (57, 0), (60, 0)),
+            ('SPAN', (61, 0), (64, 0)),
+            ('SPAN', (1, -1), (4, -1)),
+            ('SPAN', (5, -1), (8, -1)),
+            ('SPAN', (9, -1), (12, -1)),
+            ('SPAN', (13, -1), (16, -1)),
+            ('SPAN', (17, -1), (20, -1)),
+            ('SPAN', (21, -1), (24, -1)),
+            ('SPAN', (25, -1), (28, -1)),
+            ('SPAN', (29, -1), (32, -1)),
+            ('SPAN', (33, -1), (36, -1)),
+            ('SPAN', (37, -1), (40, -1)),
+            ('SPAN', (41, -1), (44, -1)),
+            ('SPAN', (45, -1), (48, -1)),
+            ('SPAN', (49, -1), (52, -1)),
+            ('SPAN', (53, -1), (56, -1)),
+            ('SPAN', (57, -1), (60, -1)),
+            ('SPAN', (61, -1), (64, -1)),
+            ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
+            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
+            ('SIZE', (0, 1), (0, -1), 8),
+            ('SIZE', (1, 1), (-1, -1), 6),
+            ('BOX', (5, 1), (20, 1), 1, colors.black), ('SPAN', (5, 1), (20, 1)),
+            ('BOX', (21, 2), (32, 2), 1, colors.black), ('SPAN', (21, 2), (32, 2)),
+            ('BOX', (5, 3), (20, 3), 1, colors.black), ('SPAN', (5, 3), (20, 3)),
+            ('BOX', (9, 4), (20, 4), 1, colors.black), ('SPAN', (9, 4), (20, 4)),
+            ('BOX', (29, 4), (38, 4), 1, colors.black), ('SPAN', (29, 4), (38, 4)),
+            ('BOX', (5, 5), (20, 5), 1, colors.green), ('SPAN', (5, 5), (20, 5)),
+            ('BOX', (9, 6), (20, 6), 1, colors.red), ('SPAN', (9, 6), (20, 6)),
+            ('BOX', (27, 6), (38, 6), 1, colors.blue),('SPAN', (27, 6), (38, 6)),
+            ('BOX', (33, 7), (48, 7), 1, colors.black),('SPAN', (33, 7), (48, 7)),
+            ]
+        t = Table(data, colWidths=None, rowHeights=None, style=style, repeatRows=1)
+        doc = SimpleDocTemplate(outputfile('test_platypus_tables_issue74.pdf'), showBoundary=0, pagesize=landscape(A4))
+        doc.build([t])
 
 def makeSuite():
     return makeSuiteForClasses(TablesTestCase)