reportlab/platypus/doctemplate.py
changeset 2196 c04e09c8635e
parent 2193 e19196dc3942
child 2200 be0cfccc662a
equal deleted inserted replaced
2195:746193239ca1 2196:c04e09c8635e
     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.70 2004/01/08 23:45:14 andy_robinson Exp $
     4 #$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.71 2004/01/13 11:20:45 rgbecker Exp $
     5 
     5 
     6 __version__=''' $Id: doctemplate.py,v 1.70 2004/01/08 23:45:14 andy_robinson Exp $ '''
     6 __version__=''' $Id: doctemplate.py,v 1.71 2004/01/13 11:20:45 rgbecker 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.
   384         if self._curPageFlowableCount == 0:
   384         if self._curPageFlowableCount == 0:
   385             self._emptyPages = self._emptyPages + 1
   385             self._emptyPages = self._emptyPages + 1
   386         else:
   386         else:
   387             self._emptyPages = 0
   387             self._emptyPages = 0
   388         if self._emptyPages >= self._emptyPagesAllowed:
   388         if self._emptyPages >= self._emptyPagesAllowed:
   389             raise LayoutError("More than %d pages generated without content - halting layout.  Likely that a flowable is too large for any frame." % self._emptyPagesAllowed)
   389             if 1:
   390 
   390                 raise LayoutError("More than %d pages generated without content - halting layout.  Likely that a flowable is too large for any frame." % self._emptyPagesAllowed)
   391 
   391             else:
   392         if self._onProgress:
   392                 pass    #attempt to restore to good state
   393             self._onProgress('PAGE', self.canv.getPageNumber())
   393         else:
   394         self.pageTemplate.afterDrawPage(self.canv, self)
   394             if self._onProgress:
   395         self.pageTemplate.onPageEnd(self.canv, self)
   395                 self._onProgress('PAGE', self.canv.getPageNumber())
   396         self.afterPage()
   396             self.pageTemplate.afterDrawPage(self.canv, self)
   397         self.canv.showPage()
   397             self.pageTemplate.onPageEnd(self.canv, self)
   398         if hasattr(self,'_nextPageTemplateIndex'):
   398             self.afterPage()
   399             self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex]
   399             self.canv.showPage()
   400             del self._nextPageTemplateIndex
   400             if hasattr(self,'_nextPageTemplateIndex'):
       
   401                 self.pageTemplate = self.pageTemplates[self._nextPageTemplateIndex]
       
   402                 del self._nextPageTemplateIndex
       
   403             if self._emptyPages==0:
       
   404                 pass    #store good state here
   401         self._hanging.append(PageBegin)
   405         self._hanging.append(PageBegin)
   402 
   406 
   403     def handle_pageBreak(self):
   407     def handle_pageBreak(self):
   404         '''some might choose not to end all the frames'''
   408         '''some might choose not to end all the frames'''
   405         if self._pageBreakQuick:
   409         if self._pageBreakQuick:
   558                 if n:
   562                 if n:
   559                     if self.frame.add(S[0], self.canv, trySplit=0):
   563                     if self.frame.add(S[0], self.canv, trySplit=0):
   560                         self._curPageFlowableCount = self._curPageFlowableCount + 1
   564                         self._curPageFlowableCount = self._curPageFlowableCount + 1
   561                         self.afterFlowable(S[0])
   565                         self.afterFlowable(S[0])
   562                     else:
   566                     else:
   563                         print 'n = %d' % n
   567                         raise LayoutError("Splitting error(n==%d) on page %d in\n%s" % (n,self.page,f.identity(30)))
   564                         raise "LayoutError", "splitting error on page %d in\n%s" % (self.page,f.identity(30))
       
   565                     del S[0]
   568                     del S[0]
   566                     for f in xrange(n-1):
   569                     for f in xrange(n-1):
   567                         flowables.insert(f,S[f])    # put split flowables back on the list
   570                         flowables.insert(f,S[f])    # put split flowables back on the list
   568                 else:
   571                 else:
   569                     # this must be cleared when they are finally drawn!
       
   570 ##                  if hasattr(f,'postponed'):
       
   571                     if hasattr(f,'_postponed'):
   572                     if hasattr(f,'_postponed'):
   572                         message = "Flowable %s too large on page %d" % (f.identity(30), self.page)
   573                         raise LayoutError("Flowable %s too large on page %d" % (f.identity(30), self.page))
   573                         #print message
   574                     # this ought to be cleared when they are finally drawn!
   574                         #show us, it might be handy
       
   575                         #HACK = it seems within tables we sometimes
       
   576                         #get an empty paragraph that won't fit and this
       
   577                         #causes it to fall over.  FIXME FIXME FIXME
       
   578                         #raise "LayoutError", message
       
   579 ##                    f.postponed = 1
       
   580                     f._postponed = 1
   575                     f._postponed = 1
   581                     flowables.insert(0,f)           # put the flowable back
   576                     flowables.insert(0,f)           # put the flowable back
   582                     self.handle_frameEnd()
   577                     self.handle_frameEnd()
   583 
   578 
   584     #these are provided so that deriving classes can refer to them
   579     #these are provided so that deriving classes can refer to them
   706             tempStory = story[:]
   701             tempStory = story[:]
   707             self.build(tempStory, filename, canvasmaker)
   702             self.build(tempStory, filename, canvasmaker)
   708             #self.notify('debug',None)
   703             #self.notify('debug',None)
   709 
   704 
   710             #clean up so multi-build does not go wrong - the frame
   705             #clean up so multi-build does not go wrong - the frame
   711             #packer might have tacked an attribute onto some
   706             #packer might have tacked an attribute onto some flowables
   712             #paragraphs
       
   713             for elem in story:
   707             for elem in story:
   714 ##              if hasattr(elem, 'postponed'):
       
   715 ##                  del elem.postponed
       
   716                 if hasattr(elem, '_postponed'):
   708                 if hasattr(elem, '_postponed'):
   717                     del elem._postponed
   709                     del elem._postponed
   718 
   710 
   719             for fl in self._indexingFlowables:
   711             for fl in self._indexingFlowables:
   720                 fl.afterBuild()
   712                 fl.afterBuild()