Layout error fixes
authorrgbecker
Thu, 26 Oct 2000 11:21:38 +0000
changeset 496 bb47cf5c2739
parent 495 13cb53ed7fdf
child 497 63f575fc1170
Layout error fixes
reportlab/platypus/flowables.py
reportlab/platypus/paragraph.py
reportlab/platypus/tables.py
--- a/reportlab/platypus/flowables.py	Thu Oct 26 11:20:04 2000 +0000
+++ b/reportlab/platypus/flowables.py	Thu Oct 26 11:21:38 2000 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/flowables.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/flowables.py,v 1.10 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: flowables.py,v 1.10 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/flowables.py,v 1.11 2000/10/26 11:21:38 rgbecker Exp $
+__version__=''' $Id: flowables.py,v 1.11 2000/10/26 11:21:38 rgbecker Exp $ '''
 __doc__="""
 A flowable is a "floating element" in a document whose exact position is determined by the
 other elements that precede it, such as a paragraph, a diagram interspersed between paragraphs,
@@ -22,10 +22,6 @@
 flow into a document from top to bottom (with column and page breaks controlled by
 higher level components).
 """
-
-# 200-10-13 gmcm
-#	packagizing
-#	rewrote grid stuff - now in tables.py
 import os
 import string
 from copy import deepcopy
--- a/reportlab/platypus/paragraph.py	Thu Oct 26 11:20:04 2000 +0000
+++ b/reportlab/platypus/paragraph.py	Thu Oct 26 11:21:38 2000 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/paragraph.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/paragraph.py,v 1.25 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: paragraph.py,v 1.25 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/paragraph.py,v 1.26 2000/10/26 11:21:38 rgbecker Exp $
+__version__=''' $Id: paragraph.py,v 1.26 2000/10/26 11:21:38 rgbecker Exp $ '''
 import string
 from types import StringType, ListType
 from reportlab.pdfbase.pdfmetrics import stringWidth
@@ -333,11 +333,12 @@
 			for word in words:
 				wordWidth = stringWidth(word, fontName, fontSize)
 				space_available = maxWidth - (currentWidth + spaceWidth + wordWidth)
-				if	space_available > 0:
+				if space_available > 0 or len(cLine)==0:
 					# fit one more on this line
 					cLine.append(word)
 					currentWidth = currentWidth + spaceWidth + wordWidth
 				else:
+					if currentWidth>self.width: self.width = currentWidth
 					#end of line
 					lines.append((maxWidth - currentWidth, cLine))
 					cLine = [word]
@@ -349,7 +350,10 @@
 						maxWidth = maxWidths[-1]  # use the last one
 
 			#deal with any leftovers on the final line
-			if cLine!=[]: lines.append((maxWidth - currentWidth, cLine))
+			if cLine!=[]:
+				if currentWidth>self.width: self.width = currentWidth
+				lines.append((maxWidth - currentWidth, cLine))
+
 			return f.clone(kind=0, lines=lines)
 		elif nFrags<=0:
 			return ParaFrag(kind=0, fontSize=style.fontSize, fontName=style.fontName,
@@ -367,7 +371,7 @@
 				wordWidth = w[0]
 				f = w[1][0]
 				space_available = maxWidth - (currentWidth + spaceWidth + wordWidth)
-				if	space_available > 0:
+				if space_available > 0 or n==0:
 					# fit one more on this line
 					n = n + 1
 					maxSize = max(maxSize,f.fontSize)
@@ -392,6 +396,7 @@
 						
 					currentWidth = currentWidth + spaceWidth + wordWidth
 				else:
+					if currentWidth>self.width: self.width = currentWidth
 					#end of line
 					lines.append(ParaFrag(extraSpace=(maxWidth - currentWidth),wordCount=n,
 										words=words, fontSize=maxSize))
@@ -416,6 +421,7 @@
 
 			#deal with any leftovers on the final line
 			if words<>[]:
+				if currentWidth>self.width: self.width = currentWidth
 				lines.append(ParaFrag(extraSpace=(maxWidth - currentWidth),wordCount=n,
 									words=words, fontSize=maxSize))
 			return ParaFrag(kind=1, lines=lines)
@@ -511,8 +517,9 @@
 				tx.XtraState.textColor=None
 				tx.XtraState.rise=0
 				tx.setLeading(style.leading)
-				f = lines[0].words[0]
-				tx._setFont(f.fontName, f.fontSize)
+				#f = lines[0].words[0]
+				#tx._setFont(f.fontName, f.fontSize)
+				tx._fontname,tx._fontsize = None, None
 				dpl( tx, offset, lines[0], noJustifyLast and nLines==1)
 
 				#now the middle of the paragraph, aligned with the left margin which is our origin.
--- a/reportlab/platypus/tables.py	Thu Oct 26 11:20:04 2000 +0000
+++ b/reportlab/platypus/tables.py	Thu Oct 26 11:21:38 2000 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/tables.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/tables.py,v 1.31 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: tables.py,v 1.31 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/tables.py,v 1.32 2000/10/26 11:21:38 rgbecker Exp $
+__version__=''' $Id: tables.py,v 1.32 2000/10/26 11:21:38 rgbecker Exp $ '''
 __doc__="""
 Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
 row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
@@ -129,7 +129,10 @@
 						if not t in _SeqTypes: v = (v,)
 						if w is None:
 							raise ValueError, "Flowables cell can't have auto width"
-						dummy,t = _listCellGeom(v,w,s)
+						dW,t = _listCellGeom(v,w,s)
+						dW = dW + s.leftPadding + s.rightPadding
+						if dW>w:
+							raise "LayoutError", "Flowable (%sx%s points) too wide for frame (%sx* points)." % (dW,t,w)
 					else:
 						if t is not StringType:
 							v = v is None and '' or str(v)