Removed usage of spaceBefore/After in wrap methods
authorrgbecker
Thu, 11 May 2000 14:04:34 +0000
changeset 191 c4907a8ee681
parent 190 74df7a489c81
child 192 256091132520
Removed usage of spaceBefore/After in wrap methods
reportlab/platypus/layout.py
reportlab/platypus/paragraph.py
--- a/reportlab/platypus/layout.py	Thu May 11 13:58:11 2000 +0000
+++ b/reportlab/platypus/layout.py	Thu May 11 14:04:34 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: layout.py,v $
+#	Revision 1.23  2000/05/11 14:02:14  rgbecker
+#	Removed usage of spaceBefore/After in wrap methods
+#
 #	Revision 1.22  2000/05/10 13:04:35  rgbecker
 #	Added softspace handling
-#
+#	
 #	Revision 1.21  2000/05/10 09:54:40  rgbecker
 #	Flowable.split should return list
 #	
@@ -95,7 +98,7 @@
 #	Revision 1.2  2000/02/15 15:47:09  rgbecker
 #	Added license, __version__ and Logi comment
 #	
-__version__=''' $Id: layout.py,v 1.22 2000/05/10 13:04:35 rgbecker Exp $ '''
+__version__=''' $Id: layout.py,v 1.23 2000/05/11 14:02:14 rgbecker Exp $ '''
 __doc__="""
 Page Layout And TYPography Using Scripts
 a page layout API on top of PDFgen
@@ -156,25 +159,15 @@
 		should split themselves and return a list of flowables"""
 		return []
 
-	def restoreSpace(self):
-		if hasattr(self,'_spaceBefore'):
-			self.style.spaceBefore = self._spaceBefore
-			del self._spaceBefore
-		if hasattr(self,'_spaceAfter'):
-			self.style.spaceAfter = self._spaceAfter
-			del self._spaceAfter
-		
-	def saveSpace(self,atTop=0):
-		'''eliminate unwanted space'''
-		R = [0,0]
-		if hasattr(self,'style'):
-			if atTop and hasattr(self.style,'spaceBefore'):
-				R[0] = self._spaceBefore = self.style.spaceBefore
-				self.style.spaceBefore = 0
-			if hasattr(self.style,'spaceAfter'):
-				R[1] = self._spaceAfter = self.style.spaceAfter
-				self.style.spaceAfter = 0
-		return R
+	def getSpaceAfter(self):
+		if hasattr(self,'spaceAfter'): return self.spaceAfter
+		elif hasattr(self,'style') and hasattr(self.style,'spaceAfter'): return self.style.spaceAfter
+		else: return 0
+
+	def getSpaceBefore(self):
+		if hasattr(self,'spaceBefore'): return self.spaceBefore
+		elif hasattr(self,'style') and hasattr(self.style,'spaceBefore'): return self.style.spaceBefore
+		else: return 0
 
 class XBox(Flowable):
 	"""Example flowable - a box with an x through it and a caption.
@@ -219,9 +212,7 @@
 
 	def wrap(self, availWidth, availHeight):
 		self.width = availWidth
-		self.height = (self.style.spaceBefore +
-					  self.style.leading * len(self.lines) +
-					  self.style.spaceAfter)
+		self.height = self.style.leading*len(self.lines)
 		return (self.width, self.height)
 
 	def draw(self):
@@ -230,7 +221,7 @@
 		#so not doing it here makes it easier to switch.
 
 		cur_x = self.style.leftIndent
-		cur_y = self.height - self.style.spaceBefore - self.style.fontSize
+		cur_y = self.height - self.style.fontSize
 		self.canv.addLiteral('%PreformattedPara')
 
 		tx = self.canv.beginText(cur_x, cur_y)
@@ -345,6 +336,9 @@
 		self.rightPadding = rightPadding
 		self.topPadding = topPadding
 
+		#efficiency
+		self.y1p = self.y1 + bottomPadding
+
 		# if we want a boundary to be shown
 		self.showBoundary = showBoundary
 
@@ -366,29 +360,34 @@
 		or if it is too high for a totally empty frame,
 		to avoid infinite loops"""
 		y = self.y
-		p = self.y1 + self.bottomPadding
-		S = flowable.saveSpace(self.atTop)
-		y_p = y-p
-		w, h = flowable.wrap(self.width, y_p )
+		p = self.y1p
+		s = self.atTop and 0 or flowable.getSpaceBefore()
+		w, h = flowable.wrap(self.width, y-p-s)
+		h = h + s
 
 		y = y - h
 		if y < p:
-			flowable.restoreSpace()
 			if ((h > self.height and not trySplit) or w > self.width):
 				raise "LayoutError", "Flowable (%dx%d points) too large for frame (%dx%d points)." % (w,h, self.width,self.height)
-			self._availHeight = y_p
 			return 0
 		else:
 			#now we can draw it, and update the current point.
 			flowable.drawOn(canv, self.x, y)
-			flowable.restoreSpace()
-			y = y - S[1]	#space after
+			y = y - flowable.getSpaceAfter()
 			self.atTop = 0
 			self.y = y
 			return 1
 
+
 	add = _add
 
+	def split(self,flowable):
+		'''calls split on the flowable'''
+		y = self.y
+		p = self.y1p
+		s = self.atTop and 0 or flowable.getSpaceBefore()
+		return flowable.wrap(self.width, y-p-s)
+
 
 #############################################################
 #	A Frame, and a Document Model
--- a/reportlab/platypus/paragraph.py	Thu May 11 13:58:11 2000 +0000
+++ b/reportlab/platypus/paragraph.py	Thu May 11 14:04:34 2000 +0000
@@ -31,13 +31,16 @@
 #
 ###############################################################################
 #	$Log: paragraph.py,v $
+#	Revision 1.3  2000/05/11 14:04:34  rgbecker
+#	Removed usage of spaceBefore/After in wrap methods
+#
 #	Revision 1.2  2000/04/19 13:14:06  rgbecker
 #	Fixed repeated breaklines bug
-#
+#	
 #	Revision 1.1  2000/04/14 13:21:52  rgbecker
 #	Removed from layout.py
 #	
-__version__=''' $Id: paragraph.py,v 1.2 2000/04/19 13:14:06 rgbecker Exp $ '''
+__version__=''' $Id: paragraph.py,v 1.3 2000/05/11 14:04:34 rgbecker Exp $ '''
 import string
 import types
 from reportlab.pdfbase.pdfmetrics import stringWidth
@@ -253,7 +256,7 @@
 				#..then it overruns, and we have less space available on line 1
 				maxwidths[0] = maxwidths[0] - (bulletRight - style.firstLineIndent)
 
-		self.height = style.spaceBefore + style.spaceAfter
+		self.height = 0
 		frags = self.frags
 		nFrags= len(frags)
 		if nFrags==1:
@@ -384,8 +387,6 @@
 			canvas.rect(self.width - style.rightIndent, 0, style.rightIndent, self.height)
 			# shade above and below
 			canvas.setFillColor(Color(1.0,1.0,0.0))
-			canvas.rect(0, self.height - style.spaceBefore, self.width,  style.spaceBefore)
-			canvas.rect(0, 0, self.width, style.spaceAfter)
 			canvas.restoreState()
 			#self.drawLine(x + style.leftIndent, y, x + style.leftIndent, cur_y)
 
@@ -408,7 +409,7 @@
 				elif self.style.alignment == TA_JUSTIFY:
 					dpl = _justifyDrawParaLine
 				f = bfrags
-				cur_y = self.height - f.fontSize - style.spaceBefore
+				cur_y = self.height - f.fontSize
 
 				if self.bulletText <> None:
 					tx2 = canvas.beginText(style.bulletIndent, cur_y)
@@ -432,7 +433,7 @@
 					dpl( tx, 0, lines[i][0], lines[i][1], i==lim)
 			else:
 				f = lines[0]
-				cur_y = self.height - f.fontSize - style.spaceBefore
+				cur_y = self.height - f.fontSize
 				if alignment == TA_LEFT:
 					dpl = _leftDrawParaLineX
 				elif alignment == TA_CENTER: