Semantic Name changes
authorrgbecker
Wed, 29 Nov 2000 17:28:50 +0000
changeset 518 5be3fcb26c78
parent 517 dffd258916bc
child 519 0452f833153c
Semantic Name changes
reportlab/platypus/__init__.py
reportlab/platypus/paragraph.py
reportlab/platypus/paraparser.py
reportlab/platypus/xpreformatted.py
--- a/reportlab/platypus/__init__.py	Wed Nov 29 16:16:33 2000 +0000
+++ b/reportlab/platypus/__init__.py	Wed Nov 29 17:28:50 2000 +0000
@@ -1,12 +1,12 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/__init__.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/__init__.py,v 1.11 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: __init__.py,v 1.11 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/__init__.py,v 1.12 2000/11/29 17:28:50 rgbecker Exp $
+__version__=''' $Id: __init__.py,v 1.12 2000/11/29 17:28:50 rgbecker Exp $ '''
 __doc__=''
 from reportlab.platypus.flowables import Flowable, Image, Macro, PageBreak, Preformatted, Spacer, XBox, \
 						CondPageBreak, KeepTogether
-from reportlab.platypus.paragraph import Paragraph, cleanBlockQuotedText
+from reportlab.platypus.paragraph import Paragraph, cleanBlockQuotedText, ParaLines
 from reportlab.platypus.paraparser import ParaFrag
 from reportlab.platypus.tables import Table, TableStyle, CellStyle
 from reportlab.platypus.frames import Frame
--- a/reportlab/platypus/paragraph.py	Wed Nov 29 16:16:33 2000 +0000
+++ b/reportlab/platypus/paragraph.py	Wed Nov 29 17:28:50 2000 +0000
@@ -1,17 +1,21 @@
 #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.32 2000/11/24 12:37:13 rgbecker Exp $
-__version__=''' $Id: paragraph.py,v 1.32 2000/11/24 12:37:13 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/paragraph.py,v 1.33 2000/11/29 17:28:50 rgbecker Exp $
+__version__=''' $Id: paragraph.py,v 1.33 2000/11/29 17:28:50 rgbecker Exp $ '''
 import string
 from types import StringType, ListType
 from reportlab.pdfbase.pdfmetrics import stringWidth
-from reportlab.platypus.paraparser import ParaParser, ParaFrag
+from reportlab.platypus.paraparser import ParaParser
 from reportlab.platypus.flowables import Flowable
 from reportlab.lib.colors import Color
 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
 from reportlab.lib.utils import _className
 from copy import deepcopy
+from reportlab.lib.abag import ABag
+class ParaLines(ABag):
+	"""class ParaLines contains the broken into lines representation of Paragraphs
+	"""
 
 #our one and only parser
 # XXXXX if the parser has any internal state using only one is probably a BAD idea!
@@ -96,14 +100,14 @@
 		tx.setWordSpace(0)
 
 def	_sameFrag(f,g):
-	'returns 1 if two frags map out the same'
+	'returns 1 if two ParaFrags map out the same'
 	if hasattr(f,'cbDefn') or hasattr(g,'cbDefn'): return 0
 	for a in ('fontName', 'fontSize', 'textColor', 'rise'):
 		if getattr(f,a)!=getattr(g,a): return 0
 	return 1
 
 def _getFragWords(frags):
-	'''	given a fragment list return a list of lists
+	'''	given a Parafrag list return a list of lists
 		[[size, (f00,w00), ..., (f0n,w0n)],....,[size, (fm0,wm0), ..., (f0n,wmn)]]
 		each pair f,w represents a style and some string
 		each sublist represents a word
@@ -154,20 +158,20 @@
 
 	return R
 
-def	_split_bfragSimple(bfrag,start,stop):
-	f = bfrag.clone()
+def	_split_blParaSimple(blPara,start,stop):
+	f = blPara.clone()
 	for a in ('lines', 'kind', 'text'):
 		if hasattr(f,a): delattr(f,a)
 
 	f.words = []
-	for l in bfrag.lines[start:stop]:
+	for l in blPara.lines[start:stop]:
 		for w in l[1]:
 			f.words.append(w)
 	return [f]
 
-def	_split_bfragHard(bfrag,start,stop):
+def	_split_blParaHard(blPara,start,stop):
 	f = []
-	lines = bfrag.lines[start:stop]
+	lines = blPara.lines[start:stop]
 	for l in lines:
 		for w in l.words:
 			f.append(w)
@@ -238,11 +242,11 @@
 	def _setup(self, text, style, bulletText, frags, cleaner):
 		if frags is None:
 			text = cleaner(text)
-			style, frags, bFrags = _parser.parse(text,style)
+			style, frags, bulletTextFrags = _parser.parse(text,style)
 			if frags is None:
 				raise "xml parser error (%s) in paragraph beginning\n'%s'"\
 					% (_parser.errors[0],text[:min(30,len(text))])
-			if bFrags: bulletText = bFrags
+			if bulletTextFrags: bulletText = bulletTextFrags
 
 		#AR hack
 		self.text = text
@@ -256,37 +260,37 @@
 		self.width = availWidth
 		first_line_width = availWidth - self.style.firstLineIndent - self.style.rightIndent
 		later_widths = availWidth - self.style.leftIndent - self.style.rightIndent
-		self.bfrags = self.breakLines([first_line_width, later_widths])
-		self.height = len(self.bfrags.lines) * self.style.leading
+		self.blPara = self.breakLines([first_line_width, later_widths])
+		self.height = len(self.blPara.lines) * self.style.leading
 
 		#estimate the size
 		return (self.width, self.height)
 
-	def _get_split_bFragFunc(self):
-		return self.bfrags.kind==0 and _split_bfragSimple or _split_bfragHard
+	def _get_split_blParaFunc(self):
+		return self.blPara.kind==0 and _split_blParaSimple or _split_blParaHard
 
 	def split(self,availWidth, availHeight):
 		if len(self.frags)<=0: return []
 
-		#the split information is all inside self.bfrags
-		if not hasattr(self,'bfrags'):
+		#the split information is all inside self.blPara
+		if not hasattr(self,'blPara'):
 			self.wrap(availWidth,availHeight)
-		bfrags = self.bfrags
+		blPara = self.blPara
 		style = self.style
 		leading = style.leading
-		lines = bfrags.lines
+		lines = blPara.lines
 		n = len(lines)
 		s = int(availHeight/leading)
 		if s<=1: return []
 		if n<=s: return [self]
-		func = self._get_split_bFragFunc()
+		func = self._get_split_blParaFunc()
 
-		P1=self.__class__(None,style,bulletText=self.bulletText,frags=func(bfrags,0,s))
+		P1=self.__class__(None,style,bulletText=self.bulletText,frags=func(blPara,0,s))
 		P1._JustifyLast = 1
 		if style.firstLineIndent != style.leftIndent:
 			style = deepcopy(style)
 			style.firstLineIndent = style.leftIndent
-		P2=self.__class__(None,style,bulletText=None,frags=func(bfrags,s,n))
+		P2=self.__class__(None,style,bulletText=None,frags=func(blPara,s,n))
 		return [P1,P2]
 
 	def draw(self):
@@ -372,7 +376,7 @@
 
 			return f.clone(kind=0, lines=lines)
 		elif nFrags<=0:
-			return ParaFrag(kind=0, fontSize=style.fontSize, fontName=style.fontName,
+			return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
 							textColor=style.textColor, lines=[])
 		else:
 			n = 0
@@ -414,7 +418,7 @@
 				else:
 					if currentWidth>self.width: self.width = currentWidth
 					#end of line
-					lines.append(ParaFrag(extraSpace=(maxWidth - currentWidth),wordCount=n,
+					lines.append(ParaLines(extraSpace=(maxWidth - currentWidth),wordCount=n,
 										words=words, fontSize=maxSize))
 
 					#start new line
@@ -438,9 +442,9 @@
 			#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,
+				lines.append(ParaLines(extraSpace=(maxWidth - currentWidth),wordCount=n,
 									words=words, fontSize=maxSize))
-			return ParaFrag(kind=1, lines=lines)
+			return ParaLines(kind=1, lines=lines)
 
 		return lines
 
@@ -453,8 +457,8 @@
 		#stash the key facts locally for speed
 		canvas = self.canv
 		style = self.style
-		bfrags = self.bfrags
-		lines = bfrags.lines
+		blPara = self.blPara
+		lines = blPara.lines
 
 		#work out the origin for line 1
 		cur_x = style.leftIndent
@@ -487,7 +491,7 @@
 			lim = nLines-1
 			noJustifyLast = not (hasattr(self,'_JustifyLast') and self._JustifyLast)
 
-			if bfrags.kind==0:
+			if blPara.kind==0:
 				if alignment == TA_LEFT:
 					dpl = _leftDrawParaLine
 				elif alignment == TA_CENTER:
@@ -496,7 +500,7 @@
 					dpl = _rightDrawParaLine
 				elif self.style.alignment == TA_JUSTIFY:
 					dpl = _justifyDrawParaLine
-				f = bfrags
+				f = blPara
 				cur_y = self.height - f.fontSize
 				if bulletText <> None:
 					offset = _drawBullet(canvas,offset,cur_y,bulletText,style)
@@ -529,7 +533,7 @@
 
 				#set up the font etc.
 				tx = canvas.beginText(cur_x, cur_y)
-				tx.XtraState=ParaFrag()
+				tx.XtraState=ABag()
 				tx.XtraState.textColor=None
 				tx.XtraState.rise=0
 				tx.setLeading(style.leading)
@@ -561,14 +565,14 @@
 		useful for seeing if paragraphs will fit in spaces."""
 		assert hasattr(self, 'width'), "Cannot call this method before wrap()"
 		w = []
-		for frag in self.bfrags.lines:
+		for frag in self.blPara.lines:
 			w.append(self.width - frag.extraSpace)
 		return w
 
 if __name__=='__main__':	#NORUNTESTS
 	def dumpParagraphLines(P):
 		print 'dumpParagraphLines(%s)' % str(P)
-		lines = P.bfrags.lines
+		lines = P.blPara.lines
 		n =len(lines)
 		for l in range(n):
 			line = lines[l]
--- a/reportlab/platypus/paraparser.py	Wed Nov 29 16:16:33 2000 +0000
+++ b/reportlab/platypus/paraparser.py	Wed Nov 29 17:28:50 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/paraparser.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/paraparser.py,v 1.32 2000/11/23 16:54:48 rgbecker Exp $
-__version__=''' $Id: paraparser.py,v 1.32 2000/11/23 16:54:48 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/paraparser.py,v 1.33 2000/11/29 17:28:50 rgbecker Exp $
+__version__=''' $Id: paraparser.py,v 1.33 2000/11/29 17:28:50 rgbecker Exp $ '''
 import string
 import re
 from types import TupleType
@@ -11,6 +11,7 @@
 import copy
 
 import reportlab.lib.sequencer
+from reportlab.lib.abag import ABag
 #try:
 #	from xml.parsers import xmllib
 #	_xmllib_newStyle = 1
@@ -149,18 +150,10 @@
 }
 
 #------------------------------------------------------------------------
-class ParaFrag:
+class ParaFrag(ABag):
 	"""class ParaFrag contains the intermediate representation of string
 	segments as they are being parsed by the XMLParser.
 	"""
-	def __init__(self,**attr):
-		for k,v in attr.items():
-			setattr(self,k,v)
-
-	def clone(self,**attr):
-		n = apply(ParaFrag,(),self.__dict__)
-		if attr != {}: apply(ParaFrag.__init__,(n,),attr)
-		return n
 
 #------------------------------------------------------------------
 # !!! NOTE !!! THIS TEXT IS NOW REPLICATED IN PARAGRAPH.PY !!!
--- a/reportlab/platypus/xpreformatted.py	Wed Nov 29 16:16:33 2000 +0000
+++ b/reportlab/platypus/xpreformatted.py	Wed Nov 29 17:28:50 2000 +0000
@@ -1,11 +1,11 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/xpreformatted.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/xpreformatted.py,v 1.11 2000/10/25 08:57:45 rgbecker Exp $
-__version__=''' $Id: xpreformatted.py,v 1.11 2000/10/25 08:57:45 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/xpreformatted.py,v 1.12 2000/11/29 17:28:50 rgbecker Exp $
+__version__=''' $Id: xpreformatted.py,v 1.12 2000/11/29 17:28:50 rgbecker Exp $ '''
 import string
 from types import StringType, ListType
-from paragraph import Paragraph, cleanBlockQuotedText, _handleBulletWidth, ParaFrag, _getFragWords, \
+from paragraph import Paragraph, cleanBlockQuotedText, _handleBulletWidth, ParaLines, _getFragWords, \
 	stringWidth, _sameFrag
 from flowables import _dedenter
 
@@ -31,11 +31,11 @@
 		lines.append(cline)
 	return lines
 
-def	_split_bfrag(bfrag,start,stop):
-	f = bfrag.clone()
+def	_split_blPara(blPara,start,stop):
+	f = blPara.clone()
 	for a in ('lines', 'text'):
 		if hasattr(f,a): delattr(f,a)
-	f.lines = bfrag.lines[start:stop]
+	f.lines = blPara.lines[start:stop]
 	return [f]
 
 def _countSpaces(text):
@@ -140,7 +140,7 @@
 			self.width = max(self.width,requiredWidth)
 			return f.clone(kind=kind, lines=lines)
 		elif nFrags<=0:
-			return ParaFrag(kind=0, fontSize=style.fontSize, fontName=style.fontName,
+			return ParaLines(kind=0, fontSize=style.fontSize, fontName=style.fontName,
 							textColor=style.textColor, lines=[])
 		else:
 			for L in _getFragLines(frags):
@@ -160,21 +160,21 @@
 				maxWidth = lineno<len(maxWidths) and maxWidths[lineno] or maxWidths[-1]
 				requiredWidth = max(currentWidth,requiredWidth)
 				extraSpace = maxWidth - currentWidth
-				lines.append(ParaFrag(extraSpace=extraSpace,wordCount=n, words=words, fontSize=maxSize, currentWidth=currentWidth))
+				lines.append(ParaLines(extraSpace=extraSpace,wordCount=n, words=words, fontSize=maxSize, currentWidth=currentWidth))
 
 			self.width = max(self.width,requiredWidth)
-			return ParaFrag(kind=1, lines=lines)
+			return ParaLines(kind=1, lines=lines)
 
 		return lines
 
 	# we need this her to get the right splitter
-	def _get_split_bFragFunc(self):
-		return _split_bfrag
+	def _get_split_blParaFunc(self):
+		return _split_blPara
 
 if __name__=='__main__':	#NORUNTESTS
 	def dumpXPreformattedLines(P):
 		print '\n############dumpXPreforemattedLines(%s)' % str(P)
-		lines = P.bfrags.lines
+		lines = P.blPara.lines
 		n =len(lines)
 		for l in range(n):
 			line = lines[l]