reportlab/platypus/doctemplate.py
changeset 1440 243d35446390
parent 1428 13a13044e9a8
child 1502 125b52eb0a8e
equal deleted inserted replaced
1439:13fe2f565cf5 1440:243d35446390
     1 #copyright ReportLab Inc. 2000
     1 #copyright ReportLab Inc. 2000
     2 #see license.txt for license details
     2 #see license.txt for license details
     3 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/doctemplate.py?cvsroot=reportlab
     3 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/doctemplate.py?cvsroot=reportlab
     4 #$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.48 2001/11/19 11:33:19 rgbecker Exp $
     4 #$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.49 2001/11/26 21:49:01 andy_robinson Exp $
     5 
     5 
     6 __version__=''' $Id: doctemplate.py,v 1.48 2001/11/19 11:33:19 rgbecker Exp $ '''
     6 __version__=''' $Id: doctemplate.py,v 1.49 2001/11/26 21:49:01 andy_robinson Exp $ '''
     7 
     7 
     8 __doc__="""
     8 __doc__="""
     9 This module contains the core structure of platypus.
     9 This module contains the core structure of platypus.
    10 
    10 
    11 Platypus constructs documents.	Document styles are determined by DocumentTemplates.
    11 Platypus constructs documents.	Document styles are determined by DocumentTemplates.
    42 def _doNothing(canvas, doc):
    42 def _doNothing(canvas, doc):
    43 	"Dummy callback for onPage"
    43 	"Dummy callback for onPage"
    44 	pass
    44 	pass
    45 
    45 
    46 
    46 
    47 class IndexingFlowable0(Flowable):
    47 class IndexingFlowable(Flowable):
    48 	"""Abstract interface definition for flowables which might
    48 	"""Abstract interface definition for flowables which might
    49 	hold references to other pages or themselves be targets
    49 	hold references to other pages or themselves be targets
    50 	of cross-references.  XRefStart, XRefDest, Table of Contents,
    50 	of cross-references.  XRefStart, XRefDest, Table of Contents,
    51 	Indexes etc."""
    51 	Indexes etc."""
    52 	def isIndexing(self):
    52 	def isIndexing(self):
   560 			self.clean_hanging()
   560 			self.clean_hanging()
   561 			self.handle_flowable(flowables)
   561 			self.handle_flowable(flowables)
   562 
   562 
   563 		self._endBuild()
   563 		self._endBuild()
   564 
   564 
   565 	def _allSatisfied0(self):
   565 	def _allSatisfied(self):
   566 		"""Called by multi-build - are all cross-references resolved?"""
   566 		"""Called by multi-build - are all cross-references resolved?"""
   567 		allHappy = 1
   567 		allHappy = 1
   568 		for f in self._indexingFlowables:
   568 		for f in self._indexingFlowables:
   569 			if not f.isSatisfied():
   569 			if not f.isSatisfied():
   570 				allHappy = 0
   570 				allHappy = 0
   571 				break
   571 				break
   572 		return allHappy
   572 		return allHappy
   573 
   573 
   574 	def notify0(self, kind, stuff):
   574 	def notify(self, kind, stuff):
   575 		""""Forward to any listeners"""
   575 		""""Forward to any listeners"""
   576 		for l in self._indexingFlowables:
   576 		for l in self._indexingFlowables:
   577 			l.notify(kind, stuff)
   577 			l.notify(kind, stuff)
   578 
   578 
   579 	def pageRef0(self, label):
   579 	def pageRef(self, label):
   580 		"""hook to register a page number"""
   580 		"""hook to register a page number"""
   581 		if _verbose: print "pageRef called with label '%s' on page %d" % (
   581 		if _verbose: print "pageRef called with label '%s' on page %d" % (
   582 			label, self.page)
   582 			label, self.page)
   583 		self._pageRefs[label] = self.page
   583 		self._pageRefs[label] = self.page
   584 
   584 
   585 	def multiBuild0(self, story,
   585 	def multiBuild(self, story,
   586 				   filename=None,
   586 				   filename=None,
   587 				   canvasmaker=canvas.Canvas,
   587 				   canvasmaker=canvas.Canvas,
   588 				   maxPasses = 10):
   588 				   maxPasses = 10):
   589 		"""Makes multiple passes until all indexing flowables
   589 		"""Makes multiple passes until all indexing flowables
   590 		are happy."""
   590 		are happy."""
   593 		for thing in story:
   593 		for thing in story:
   594 			if thing.isIndexing():
   594 			if thing.isIndexing():
   595 				self._indexingFlowables.append(thing)
   595 				self._indexingFlowables.append(thing)
   596 		#print 'scanned story, found these indexing flowables:\n'
   596 		#print 'scanned story, found these indexing flowables:\n'
   597 		#print self._indexingFlowables
   597 		#print self._indexingFlowables
   598 
   598 		
   599 		passes = 0
   599 		passes = 0
   600 		while 1:
   600 		while 1:
   601 			passes = passes + 1
   601 			passes = passes + 1
   602 			if _verbose: print 'building pass '+str(passes) + '...',
   602 			if _verbose: print 'building pass '+str(passes) + '...',
   603 
   603 
   605 				fl.beforeBuild()
   605 				fl.beforeBuild()
   606 
   606 
   607 			# work with a copy of the story, since it is consumed
   607 			# work with a copy of the story, since it is consumed
   608 			tempStory = story[:]
   608 			tempStory = story[:]
   609 			self.build(tempStory, filename, canvasmaker)
   609 			self.build(tempStory, filename, canvasmaker)
   610 			#self.notify0('debug',None)
   610 			#self.notify('debug',None)
   611 
   611 
   612 			#clean up so multi-build does not go wrong - the frame
   612 			#clean up so multi-build does not go wrong - the frame
   613 			#packer might have tacked an attribute onto some
   613 			#packer might have tacked an attribute onto some
   614 			#paragraphs
   614 			#paragraphs
   615 			for elem in story:
   615 			for elem in story:
   619 					del elem._postponed
   619 					del elem._postponed
   620 
   620 
   621 			for fl in self._indexingFlowables:
   621 			for fl in self._indexingFlowables:
   622 				fl.afterBuild()
   622 				fl.afterBuild()
   623 
   623 
   624 			happy = self._allSatisfied0()
   624 			happy = self._allSatisfied()
   625 
   625 
   626 			if happy:
   626 			if happy:
   627 				## print 'OK'
   627 				## print 'OK'
   628 				break
   628 				break
   629 			## else:
   629 			## else: