try to limit table style cell ranges; version --> 3.5.47
authorrobin
Fri, 07 Aug 2020 08:20:29 +0100
changeset 4595 0fea122fc259
parent 4594 1c5305546b9d
child 4596 4c56a5750bd1
try to limit table style cell ranges; version --> 3.5.47
CHANGES.md
src/reportlab/__init__.py
src/reportlab/platypus/tables.py
--- a/CHANGES.md	Wed Jul 22 08:52:20 2020 +0100
+++ b/CHANGES.md	Fri Aug 07 08:20:29 2020 +0100
@@ -11,6 +11,10 @@
 The contributors lists are in no order and apologies to those accidentally not
 mentioned. If we missed you, please let us know!
 
+RELEASE 3.5.47	  7/08/2020
+---------------------------
+	* try to limit table style cell ranges
+
 RELEASE 3.5.46	 22/07/2020
 ---------------------------
 	* fix style-data mismatch in LinePlot found by Anshika Sahay
--- a/src/reportlab/__init__.py	Wed Jul 22 08:52:20 2020 +0100
+++ b/src/reportlab/__init__.py	Fri Aug 07 08:20:29 2020 +0100
@@ -1,9 +1,9 @@
 #Copyright ReportLab Europe Ltd. 2000-2018
 #see license.txt for license details
 __doc__="""The Reportlab PDF generation library."""
-Version = "3.5.46"
+Version = "3.5.47"
 __version__=Version
-__date__='20200722'
+__date__='20200807'
 
 import sys, os
 
--- a/src/reportlab/platypus/tables.py	Wed Jul 22 08:52:20 2020 +0100
+++ b/src/reportlab/platypus/tables.py	Fri Aug 07 08:20:29 2020 +0100
@@ -1035,6 +1035,14 @@
             if not hasattr(self,a) and hasattr(tblstyle,a):
                 setattr(self,a,getattr(tblstyle,a))
 
+    def normCellRange(self, sc, ec, sr, er):
+        '''ensure cell range ends are with the table bounds'''
+        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
+        return max(0,sc), min(self._ncols-1,ec), max(0,sr), min(self._nrows-1,er)
+
     def _addCommand(self,cmd):
         if cmd[0] in ('BACKGROUND','ROWBACKGROUNDS','COLBACKGROUNDS'):
             self._bkgrndcmds.append(cmd)
@@ -1088,12 +1096,10 @@
             if sr in ('splitfirst','splitlast'):
                 self._srflcmds.append(cmd)
             else:
-                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
+                sc, ec, sr, er = self.normCellRange(sc,ec,sr,er)
+                ec += 1
                 for i in xrange(sr, er+1):
-                    for j in xrange(sc, ec+1):
+                    for j in xrange(sc, ec):
                         _setCellStyle(self._cellStyles, i, j, op, values)
 
     def _drawLines(self):
@@ -1101,10 +1107,6 @@
         self.canv.saveState()
         for op, (sc,sr), (ec,er), weight, color, cap, dash, join, count, space in self._linecmds:
             if isinstance(sr,strTypes) and sr.startswith('split'): continue
-            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 cap!=None and ccap!=cap:
                 self.canv.setLineCap(cap)
                 ccap = cap
@@ -1118,6 +1120,7 @@
             if join is not None and cjoin!=join:
                 self.canv.setLineJoin(join)
                 cjoin = join
+            sc, ec, sr, er = self.normCellRange(sc,ec,sr,er)
             getattr(self,_LineOpMap.get(op, '_drawUnknown' ))( (sc, sr), (ec, er), weight, color, count, space)
         self.canv.restoreState()
         self._curcolor = None