[reportlab-users] Re: Problem with spanned columns when a platypus

Andre Reitz reitz at inworks.de
Wed Jan 12 05:47:04 EST 2005


Sorry, there was one little thing...


had to exchange y1<->ymin and y2<->ymax in _getFirstPossibleSplitRowPosition

Here the corrected patch...
Greetings, Andre'



Jean-Francois Gosset wrote:
> Message d'origine (22:51 11/01/2005 +0100) émis par (Andre Reitz) :
> 
>>Spans currently are ignored when Tables are split.
>>
>>I solved this with the following patch.
>>It would be very helpful for me and I think for other users if somebody
>>would apply the patch to the subversion tree, so that it is available in
>>the next release.
> 
> 
> 
> It works perfectly (tested with the little example I gave previously).
> Just a note : the patched tables.py don't work with the 1.20 reportlab version. We need the current SVN version.
> 
> Thank's Andre for the patch and if it could be applied to the subversion tree, it would be nice.
> 
> JF Gosset
> 
---------------------------------------------------------------------------------------------------------------------------
Index: reportlab/platypus/tables.py
===================================================================
--- reportlab/platypus/tables.py	(revision 2509)
+++ reportlab/platypus/tables.py	(working copy)
@@ -833,16 +833,38 @@
                 if er>=n: er = er-n
                 self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:])
 
+    def _getFirstPossibleSplitRowPosition(self,availHeight):
+        if self._spanCmds:
+            impossible={}
+            for xy in self._rowSpanCells:
+                r=self._spanRanges[xy]
+                if r!=None:
+                    y1,y2=r[1],r[3]
+                    if y1!=y2:
+                        ymin=min(y1,y2) #normalize
+                        ymax=max(y1,y2) #normalize
+                        y=ymin+1
+                        while 1:
+                            if y>ymax: break
+                            impossible[y]=None #split at position y is impossible because of overlapping rowspan
+                            y=y+1
+        else:
+            impossible={} # any split possible because table does *not* have rowspans
+      #------------------------------------------------------------------------        
+        h = 0
+        n = 1
+    	split_at = 0 # from this point of view 0 is the first position where the table may *always* be splitted
+        for rh in self._rowHeights:
+            if h+rh>availHeight:
+                break
+            if not impossible.has_key(n):
+                split_at=n
+            h=h+rh
+            n=n+1
+        return split_at
     def _splitRows(self,availHeight):
-        h = 0
-        n = 0
         lim = len(self._rowHeights)
-        while n<self._hmax:
-            hn = h + self._rowHeights[n]
-            if hn>availHeight: break
-            h = hn
-            n = n + 1
-
+        n=self._getFirstPossibleSplitRowPosition(availHeight)
         if n<=self.repeatRows:
             return []
 
@@ -931,9 +953,25 @@
 
         R0.hAlign = R1.hAlign = self.hAlign
         R0.vAlign = R1.vAlign = self.vAlign
+        if self._spanCmds:
+            spans0,spans1=self._cloneSpanCommands(n)
+            R0._spanCmds=spans0
+            R1._spanCmds=spans1
         self.onSplit(R0)
         self.onSplit(R1)
         return [R0,R1]
+    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)
---------------------------------------------------------------------------------------------------------------------------

-- 
__________________________________________________________________________

Als Technologieunternehmen konzipieren und entwickeln wir maßgeschneiderte Feedback- und
Monitoring-Systeme - wie beispielsweise Lösungen für Beschwerde- und Ideenmanagement.
Mit dem Inquery® Survey Server bieten wir eine der leistungsfähigsten Standardlösungen für
Online-Umfragen mit dem Schwerpunkt auf der Messung von Kundenzufriedenheit an.
__________________________________________________________________________


Inworks GmbH
Andre Reitz, Leiter Entwicklung
Hörvelsinger Weg 39, 89081 Ulm, Germany
Tel +49 (0) 731 / 93807-21
Fax +49(0)731/93807-18
Internet: http://www.inworks.de


-------------- next part --------------
Index: reportlab/platypus/tables.py
===================================================================
--- reportlab/platypus/tables.py	(revision 2509)
+++ reportlab/platypus/tables.py	(working copy)
@@ -833,16 +833,38 @@
                 if er>=n: er = er-n
                 self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:])
 
+    def _getFirstPossibleSplitRowPosition(self,availHeight):
+        if self._spanCmds:
+            impossible={}
+            for xy in self._rowSpanCells:
+                r=self._spanRanges[xy]
+                if r!=None:
+                    y1,y2=r[1],r[3]
+                    if y1!=y2:
+                        ymin=min(y1,y2) #normalize
+                        ymax=max(y1,y2) #normalize
+                        y=ymin+1
+                        while 1:
+                            if y>ymax: break
+                            impossible[y]=None #split at position y is impossible because of overlapping rowspan
+                            y=y+1
+        else:
+            impossible={} # any split possible because table does *not* have rowspans
+      #------------------------------------------------------------------------        
+        h = 0
+        n = 1
+    	split_at = 0 # from this point of view 0 is the first position where the table may *always* be splitted
+        for rh in self._rowHeights:
+            if h+rh>availHeight:
+                break
+            if not impossible.has_key(n):
+                split_at=n
+            h=h+rh
+            n=n+1
+        return split_at
     def _splitRows(self,availHeight):
-        h = 0
-        n = 0
         lim = len(self._rowHeights)
-        while n<self._hmax:
-            hn = h + self._rowHeights[n]
-            if hn>availHeight: break
-            h = hn
-            n = n + 1
-
+        n=self._getFirstPossibleSplitRowPosition(availHeight)
         if n<=self.repeatRows:
             return []
 
@@ -931,9 +953,25 @@
 
         R0.hAlign = R1.hAlign = self.hAlign
         R0.vAlign = R1.vAlign = self.vAlign
+        if self._spanCmds:
+            spans0,spans1=self._cloneSpanCommands(n)
+            R0._spanCmds=spans0
+            R1._spanCmds=spans1
         self.onSplit(R0)
         self.onSplit(R1)
         return [R0,R1]
+    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)


More information about the reportlab-users mailing list