
    Kwg                        d Z dZdZddl ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZmZ dd
lZddlmZ ddlmZmZmZmZmZ 	 e dd
lZdd
lZ ej<                  d      Z G d de       Z!d Z"d Z# G d de$      Z% G d de&      Z' G d de&      Z( G d de(      Z) G d de(      Z* G d de(      Z+ G d d e*      Z, G d! de(      Z) G d" d#e*      Z- e-d$      Z. e*d%      Z/d& Z0 G d' d(e&      Z1 G d) d*e1      Z2 G d+ d,e1      Z3 G d- d.e(      Z4 G d/ d0      Z5d1 Z6 G d2 d3e7      Z8 G d4 d5      Z9d6 Z: G d7 d8      Z; G d9 d:e;      Z<d; Z=e>d<k(  rdd=l?m@Z@mAZA d> ZBd? ZCd@ ZD eD        y
y
# e$ r
 ddlmZ Y 7w xY w)A)ActionFlowableBaseDocTemplateCurrentFrameFlowableFrameActionFlowable
FrameBreakIndenterIndexingFlowableLayoutErrorLCActionFlowableNextFrameFlowableNextPageTemplateNotAtTopPageBreakNullActionFlowablePageAccumulator	PageBeginPageTemplateSimpleDocTemplatez3.5.20a>  
This module contains the core structure of platypus.

rlatypus constructs documents.  Document styles are determined by DocumentTemplates.

Each DocumentTemplate contains one or more PageTemplates which defines the look of the
pages of the document.

Each PageTemplate has a procedure for drawing the "non-flowing" part of the page
(for example the header, footer, page number, fixed logo graphic, watermark, etcetera) and
a set of Frames which enclose the flowing part of the page (for example the paragraphs,
tables, or non-fixed diagrams of the text).

A document is built when a DocumentTemplate is fed a sequence of Flowables.
The action of the build consumes the flowables in order and places them onto
frames on pages as space allows.  When a frame runs out of space the next frame
of the page is used.  If no frame remains a new page is created.  A new page
can also be created if a page break is forced.

The special invisible flowable NextPageTemplate can be used to specify
the page template for the next page (which by default is the one being used
for the current frame).
    )*)_ContainerSpace)inch)	Paragraph)Frame)defaultPageSizeverboseN)canvas)isSeqencode_labeldecode_labelannotateExceptionstrTypes)Setzreportlab.platypusc                       e Zd Zy)r	   N)__name__
__module____qualname__     U/var/www/horilla/myenv/lib/python3.12/site-packages/reportlab/platypus/doctemplate.pyr	   r	   D   s    r'   r	   c                     t        | dd       }|t        | dd       }t        | dd       }|t        | dd       }t        | d      rd| j                         z  }nd}|||d}|d}d	|d
|d|S y)Nwidth_widthheight_height_culpritz, %s,  z???(z x ))getattrhasattrr.   )fwhcs       r(   _fSizeStringr8   G   s    aAy
!HT
"aAy
!Id
#q*qzz|#}9a9a !!A&&r'   c                      y)zDummy callback for onPageNr&   )r   docs     r(   
_doNothingr;   [   s    r'   c                   2    e Zd Zd Zed        Zed        Zy)PTCyclec                 T    t        j                  | g|i |}d|_        d|_        |S Nr   )list__new___restart_idx)clsargskwdsselfs       r(   rA   zPTCycle.__new__`   s-    ||C---	r'   c                     | | j                      }| xj                   dz  c_         | j                   t        |       k\  r| j                  | _         |S N   )rC   lenrB   )rG   vs     r(   
next_valuezPTCycle.next_valuef   s<    O		Q	99c$iDIr'   c                      | | j                      S N)rC   rG   s    r(   peekzPTCycle.peekn   s    DIIr'   N)r#   r$   r%   rA   propertyrM   rQ   r&   r'   r(   r=   r=   _   s/        r'   r=   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)r   zAbstract interface definition for flowables which might
    hold references to other pages or themselves be targets
    of cross-references.  XRefStart, XRefDest, Table of Contents,
    Indexes etc.c                      yrI   r&   rP   s    r(   
isIndexingzIndexingFlowable.isIndexingw       r'   c                      yrI   r&   rP   s    r(   isSatisfiedzIndexingFlowable.isSatisfiedz   rV   r'   c                      y)zThis will be called by the framework wherever 'stuff' happens.
        'kind' will be a value that can be used to decide whether to
        pay attention or not.Nr&   )rG   kindstuffs      r(   notifyzIndexingFlowable.notify}        	r'   c                      y)zMCalled by multiBuild before it starts; use this to clear
        old contentsNr&   rP   s    r(   beforeBuildzIndexingFlowable.beforeBuild        	r'   c                      y)z.Called after build ends but before isSatisfiedNr&   rP   s    r(   
afterBuildzIndexingFlowable.afterBuild       r'   N)	r#   r$   r%   __doc__rU   rX   r\   r_   rb   r&   r'   r(   r   r   r   s     
r'   r   c                   ,    e Zd ZdZddZd Zd ZddZy)	r   zThis Flowable is never drawn, it can be used for data driven controls
       For example to change a page template (from one column to two, for example)
       use NextPageTemplate which creates an ActionFlowable.
    c                 j    t         j                  |        t        |      s|f}t        |      | _        y rO   )Flowable__init__r   tupleaction)rG   rj   s     r(   rh   zActionFlowable.__init__   s+     	$V}YFFmr'   c           	      4   | j                   d   }t        | j                   dd       }d|z   }|dk(  r	|d   dk(  r	 	  t        ||      |  y# t        $ r&}|j                  d   |k(  rt        d|z         d}~w t        d|d	t        |             Y yxY w)
zu
        This is called by the doc.build processing to allow the instance to
        implement its behaviour
        r   rJ   Nhandle_handle_nextPageTemplatemainzCan't handle ActionFlowable(%s)z
handle_z args=)rj   ri   r2   AttributeErrorrE   NotImplementedErrorr   ascii)rG   r:   rj   rE   arnaerrs         r(   applyzActionFlowable.apply   s    
 QT[[_%))d1gvo	JGCd# 	yy|S )*Kf*TUU	JVE$KHIs   A 	B!A66Bc                     | S rO   r&   rP   s    r(   __call__zActionFlowable.__call__   s    r'   Nc                 R    dt        | j                        | j                         S )NzActionFlowable: )strrj   
_frameName)rG   maxLens     r(   identityzActionFlowable.identity   s    ),T[[)9$//:KLLr'   )r&   rO   )r#   r$   r%   rd   rh   rt   rv   r{   r&   r'   r(   r   r      s    $J(Mr'   r   c                       e Zd ZdZd Zy)r   z#an ActionFlowable that does nothingc                      y rO   r&   rG   r:   s     r(   rt   zNullActionFlowable.apply       r'   N)r#   r$   r%   rd   rt   r&   r'   r(   r   r      s
    -r'   r   c                       e Zd ZdZd Zd Zy)r
   rJ   c                 F    t        d| j                  j                  z        )Should never be called.z%s.wrap should never be calledrp   	__class__r#   )rG   
availWidthavailHeights      r(   wrapzLCActionFlowable.wrap       !"BT^^E\E\"\]]r'   c                 F    t        d| j                  j                  z        )r   z%s.draw should never be calledr   rP   s    r(   drawzLCActionFlowable.draw   r   r'   N)r#   r$   r%   
locChangerr   r   r&   r'   r(   r
   r
      s    J^^r'   r
   c                       e Zd ZdZddZy)r   rJ   c                 6    t         j                  | d||f       y )N	nextFramer   rh   rG   ixresumes      r(   rh   zNextFrameFlowable.__init__   s    k"V%<=r'   Nr   r#   r$   r%   r   rh   r&   r'   r(   r   r      s    J>r'   r   c                       e Zd ZddZy)r   c                 6    t         j                  | d||f       y )NcurrentFramer   r   s      r(   rh   zCurrentFrameFlowable.__init__   s    nR%?@r'   Nr   )r#   r$   r%   rh   r&   r'   r(   r   r      s    Ar'   r   c                       e Zd Zd Zy)r   c                      y rO   r&   r~   s     r(   rt   zNullActionFlowable.apply   r   r'   N)r#   r$   r%   rt   r&   r'   r(   r   r      s    r'   c                       e Zd ZdZddZd Zy)_FrameBreakz}
    A special ActionFlowable that allows setting doc._nextFrameIndex

    eg story.append(FrameBreak('mySpecialFrame'))
    Nc                 R    | j                  | j                  |fz         }||_        |S rO   )r   rj   _ix)rG   r   r   rs       r(   rv   z_FrameBreak.__call__   s'    NN4;;y01r'   c                     t        | dd       r|j                  | j                         t        j	                  | |       y )Nr   )r2   handle_nextFramer   r   rt   r~   s     r(   rt   z_FrameBreak.apply   s0    4d#  *T#&r'   r?   )r#   r$   r%   rd   rv   rt   r&   r'   r(   r   r      s    

'r'   r   frameEnd	pageBeginc                 b    t        | t              rddlm}  ||       } t	        |       r| d   } | S )Nr   )_numrJ   )
isinstancerx   reportlab.platypus.paraparserr   r   )nr   s     r(   _evalMeasurementr      s,    !C6G81QHr'   c                        e Zd ZdxZZd Zd Zy)r   rJ   c                 F    t        d| j                  j                  z        )Nz5%s.__init__ should never be called for abstract Classr   )rG   argkws      r(   rh   zFrameActionFlowable.__init__   s     !"YZ^ZhZhZqZq"qrrr'   c                 F    t        d| j                  j                  z        )Nz8%s.frameAction should never be called for abstract Classr   rG   frames     r(   frameActionzFrameActionFlowable.frameAction   s     !"\]a]k]k]t]t"tuur'   N)r#   r$   r%   _fixedWidth_fixedHeightrh   r   r&   r'   r(   r   r      s    !""K,svr'   r   c                   *    e Zd ZdZdZdZdZddZd Zy)r   zIncreases or decreases left and right margins of frame.

    This allows one to have a 'context-sensitive' indentation
    and makes nested lists way easier.
    Tr   c                 D    t        |      | _        t        |      | _        y rO   )r   leftright)rG   r   r   s      r(   rh   zIndenter.__init__   s    $T*	%e,
r'   c                     |xj                   | j                  z  c_         |xj                  | j                  z  c_        y rO   )_leftExtraIndentr   _rightExtraIndentr   r   s     r(   r   zIndenter.frameAction   s,    $))+4::-r'   N)r   r   )	r#   r$   r%   rd   	_ZEROSIZEr*   r,   rh   r   r&   r'   r(   r   r      s"    
 I
EF-.r'   r   c                       e Zd ZdZddZd Zy)r   rJ   Nc                     || _         y rO   nextTemplate)rG   r   s     r(   rh   zNotAtTopPageBreak.__init__  s
    (r'   c                 h    |j                   s&|j                  t        | j                               y y )Nr   )_atTopadd_generated_content	PageBreakr   r   s     r(   r   zNotAtTopPageBreak.frameAction  s'    ||''	t?P?P(QR r'   rO   )r#   r$   r%   r   rh   r   r&   r'   r(   r   r     s    J)Sr'   r   c                       e Zd ZdZ	 d Zy)r   rJ   c                 4    t         j                  | d|f       y )NnextPageTemplater   )rG   pts     r(   rh   zNextPageTemplate.__init__  s    &8%<=r'   Nr   r&   r'   r(   r   r     s    Ji>r'   r   c            
       >    e Zd ZdZdg eeddddddf
dZd Zd Zd Zy)r   z
    essentially a list of Frames and an onPage routine to call at the start
    of a page when this is selected. onPageEnd gets called at the end.
    derived classes can also implement beforeDrawPage and afterDrawPage if they want
    Nc                    |xs g }t        |      s|g}|D cg c]  }t        |t              r| c}g k(  sJ d       || _        || _        || _        || _        || _        || _        || _	        || _
        |	| _        |
| _        y c c}w )Nzframes argument error)r   r   r   idframesonPage	onPageEndpagesizeautoNextPageTemplatecropBoxartBoxtrimBoxbleedBox)rG   r   r   r   r   r   r   r   r   r   r   xs               r(   rh   zPageTemplate.__init__  s     2V}xf!=aAe)<=rAZCZZA" $8!  >s
   BBc                      y)zOverride this if you want additional functionality or prefer
        a class based page routine.  Called before any flowables for
        this page are processed.Nr&   rG   canvr:   s      r(   beforeDrawPagezPageTemplate.beforeDrawPage-  r]   r'   c                 
   d}d}d}|j                   r#t        t        t        |j                               }| j                  r#t        t        t        | j                              }|j                  r#t        t        t        |j                              }||k7  r>|r|j                  | j                         n ||k7  r|j                  |j                         dD ](  }t        | |dz   d      }|s|j                  ||       * y)zThis gets called by the template framework
        If canv size != template size then the canv size is set to
        the template size or if that's not available to the
        doc size.
        N)croparttrimbleedBox)name)	_pagesizer@   mapintr   setPageSizer2   
setCropBox)rG   r   r:   cpdpspboxsizes           r(   checkPageSizezPageTemplate.checkPageSize3  s     >>Sdnn%= >2==tCT]]$;<"<<d3sCLL#9:r6  /R  .. 	/C4E	$/D#.	/r'   c                      y)zThis is called after the last flowable for the page has
        been processed.  You might use this if the page header or
        footer needed knowledge of what flowables were drawn on
        this page.Nr&   r   s      r(   afterDrawPagezPageTemplate.afterDrawPageL      
 	r'   )	r#   r$   r%   rd   r;   rh   r   r   r   r&   r'   r(   r   r     s7    
 RzZT!*/2r'   r   c                 2    t        |dd       }|r|| dd |`y y )N_generated_contentr   )r2   r   )	flowablesr   Ss      r(   _addGeneratedContentr   S  s*    *40A	!A$ 	r'   c                       e Zd ZddZd Zy)	onDrawStrNc                 \    t         j                  | |      }||_        ||_        ||_        |S rO   )rx   rA   onDrawrZ   label)rD   valuer   r   rZ   rG   s         r(   rA   zonDrawStr.__new__Z  s,    {{3u%	
r'   c                 \    t        |       | j                  | j                  | j                  fS rO   )rx   r   r   rZ   rP   s    r(   __getnewargs__zonDrawStr.__getnewargs__a  s!    4yTZZ		99r'   rO   )r#   r$   r%   rA   r   r&   r'   r(   r   r   Y  s    :r'   r   c                   R    e Zd ZdZdZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)r   zngadget to accumulate information in a page
    and then allow it to be interrogated at the end
    of the pager   Nc                     |U| j                   j                  t        | j                   j                        z   }| j                   xj                  dz  c_        || _        g | _        y rI   )r   r#   rx   _countr   data)rG   r   s     r(   rh   zPageAccumulator.__init__i  sM    <>>**3t~~/D/D+EEDNN!!Q&!		r'   c                 "    g | j                   d d  y rO   )r   rP   s    r(   resetzPageAccumulator.resetp  s    		!r'   c                 :    | j                   j                  |       y rO   )r   appendrG   rE   s     r(   addzPageAccumulator.adds  s    		r'   c                 :    d| j                   dt        |      dS )Nz<onDraw name="z	" label="z" />)r   r   r  s     r(   
onDrawTextzPageAccumulator.onDrawTextv  s    48IIl4>PQQr'   c                 4     | j                   t        |        y rO   )r  r   )rG   r   rZ   r   s       r(   rv   zPageAccumulator.__call__y  s    ,u%&r'   c                      |j                   r|j                   f fd	}n fd}||_         |j                  r|j                  f fd	}||_        y  fd}||_        y )Nc                 <    j                  | |        || |       y rO   r   r   r:   ooprG   s      r(   r   z4PageAccumulator.attachToPageTemplate.<locals>.onPage~  s    D%Dr'   c                 *    j                  | |       y rO   r	  r   r:   rG   s     r(   r   z4PageAccumulator.attachToPageTemplate.<locals>.onPage  s    D%r'   c                 <    j                  | |        || |       y rO   r   r
  s      r(   r   z7PageAccumulator.attachToPageTemplate.<locals>.onPageEnd  s    tC(Dr'   c                 *    j                  | |       y rO   r  r  s     r(   r   z7PageAccumulator.attachToPageTemplate.<locals>.onPageEnd  s    tC(r'   )r   r   )rG   r   r   r   s   `   r(   attachToPageTemplatez$PageAccumulator.attachToPageTemplate|  sJ    99$&II &	<<')||  !) r'   c                 R    t        || j                  |        | j                          y)z,this will be called at the start of the pageN)setattrr   r   r   s      r(   r   zPageAccumulator.onPage  s    TYYt$

r'   c                     | j                  ||       	 t        || j                         | j                          y#  Y xY w)z(this will be called at the end of a pageN)pageEndActiondelattrr   r   r   s      r(   r   zPageAccumulator.onPageEnd  s:    4$	D# 	

	s   ; ?c                      y)z0this should be overridden to do something usefulNr&   r   s      r(   r  zPageAccumulator.pageEndAction  rc   r'   c                 .    t        || t        |            S rO   )r   r   )rG   r   rE   s      r(   r   zPageAccumulator.onDrawStr  s    tL$677r'   rO   )r#   r$   r%   rd   r   rh   r   r  r  rv   r  r   r   r  r   r&   r'   r(   r   r   d  sA     FR'!$
8r'   r   c                 X    t        | t        t        t        f      xs t	        | dd       S )z6return true if allowed in containers like KeepTogetherr   F)r   r   DocIfDocWhiler2   )r4   s    r(   _ktAllowr    s(    1oeH=>_'!LY^B_``r'   c                      e Zd ZdZi dedg dddededed	ed
ddddddddddddg ddddddi ddddddddddddddddddddd dd!dd"dd#dd$ed%dd&ddddddddddddd'Zd(ZdZ	d) Z
d* Zd+ Zd, Zd- Zd. Zd/ Zd0 Zd1 Zd2 Zd3 ZdTd4ZdUd5ZdVd6Zd7 Zd8 Zd9 ZdVd:ZdVd;Zd< Zd= ZdWd>Zd? Z eZ!eZ"eZ#eZ$eZ%e Z&eZ'eZ(eZ)de*jV                  fd@Z,de*jV                  fdAZ-dB Z.de*jV                  fdCZ/dD Z0dE Z1dF Z2	 dXdGZ3dH Z4dI Z5dJ Z6dK Z7dL Z8dM Z9dNZ:dO Z;dP Z<dQ Z=dR Z>dS Z?y)Yr   a	  
    First attempt at defining a document template class.

    The basic idea is simple.

    1)  The document has a list of data associated with it
        this data should derive from flowables. We'll have
        special classes like PageBreak, FrameBreak to do things
        like forcing a page end etc.

    2)  The document has one or more page templates.

    3)  Each page template has one or more frames.

    4)  The document class provides base methods for handling the
        story events and some reasonable methods for getting the
        story flowables into the frames.

    5)  The document instances can override the base handler routines.

    Most of the methods for this class are not called directly by the user,
    but in some advanced usages they may need to be overridden via subclassing.

    EXCEPTION: doctemplate.build(...) must be called for most reasonable uses
    since it builds a document using the page template.

    Each document template builds exactly one document into a file specified
    by the filename argument on initialization.

    Possible keyword arguments for the initialization:

    - pageTemplates: A list of templates.  Must be nonempty.  Names
      assigned to the templates are used for referring to them so no two used
      templates should have the same name.  For example you might want one template
      for a title page, one for a section first page, one for a first page of
      a chapter and two more for the interior of a chapter on odd and even pages.
      If this argument is omitted then at least one pageTemplate should be provided
      using the addPageTemplates method before the document is built.
    - pageSize: a 2-tuple or a size constant from reportlab/lib/pagesizes.pu.
      Used by the SimpleDocTemplate subclass which does NOT accept a list of
      pageTemplates but makes one for you; ignored when using pageTemplates.

    - showBoundary: if set draw a box around the frame boundaries.
    - leftMargin:
    - rightMargin:
    - topMargin:
    - bottomMargin:  Margin sizes in points (default 1 inch).  These margins may be
      overridden by the pageTemplates.  They are primarily of interest for the
      SimpleDocumentTemplate subclass.

    - allowSplitting:  If set flowables (eg, paragraphs) may be split across frames or pages
      (default: 1)
    - title: Internal title for document (does not automatically display on any page)
    - author: Internal author for document (does not automatically display on any page)
    r   pageTemplatesshowBoundaryr   
leftMarginrightMargin	topMarginbottomMarginallowSplittingrJ   titleNauthorsubjectcreatorproducerkeywords	invariantpageCompression_pageBreakQuickrotation_debugencrypt	cropMarksenforceColorSpacedisplayDocTitlelanginitialFontNameinitialFontSizeinitialLeadingr   r   r   r   keepTogetherClasshideToolbarhideMenubar)hideWindowUI	fitWindowcenterWindownonFullScreenPageMode	directionviewAreaviewClip	printArea	printClipprintScalingduplexr&   c                 B   || _         t        |       | _        i | _        | j                  j                         D ]D  }||vr| j                  |   }n!|| j                  v rt        d|z        ||   }t        | ||       F | j                  }g | _	        | j                  |       i | _        g | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        g | _        g | _        g | _        | j1                          | j3                          y)z^create a document template bound to a filename (see class documentation for keyword arguments))r:   zInvalid argument %sNr   
   g        )filenamedict
_nameSpace
_lifetimes	_initArgskeys_invalidInitArgs
ValueErrorr  r  addPageTemplates	_pageRefs_indexingFlowables_onPage_onProgress_flowableCount_curPageFlowableCount_emptyPages_emptyPagesAllowedr   r   _topFlowables_pageTopFlowables	_frameBGs_calc	afterInit)rG   rH  r   krL   ps         r(   rh   zBaseDocTemplate.__init__  s#    4.$$& 	A{NN1%---$%:Q%>??qED1	 a  "$  &'""$ !$!$!#

r'   c                     | j                   d   | j                  z
  | _        | j                   d   | j                  z
  | _        | j                  | j
                  z
  | _        | j                  | j                  z
  | _        y )Nr   rJ   )	r   r!  _rightMarginr"  
_topMarginr   r*   r#  r,   rP   s    r(   r\  zBaseDocTemplate._calc>  sc     MM!,t/?/??--*T^^;&&8
oo(9(99r'   c                     || _         y)z>Simple progress monitor - func(pageNo) called on each new pageN)rS  rG   funcs     r(   setPageCallBackzBaseDocTemplate.setPageCallBackD  s	    r'   c                     || _         y)z=Cleverer progress monitor - func(typ, value) called regularlyN)rT  rd  s     r(   setProgressCallBackz#BaseDocTemplate.setProgressCallBackH  s
    r'   c                     t        | j                        r2| j                  | j                         t        | j                        r1yy)z!handle internal postponed actionsN)rK   _hanginghandle_flowablerP   s    r(   clean_hangingzBaseDocTemplate.clean_hangingL  s.    $--   / $-- r'   c                 d    t        |      s|g}|D ]  }| j                  j                  |        y)z&add one or a sequence of pageTemplatesN)r   r  r  )rG   r  ts      r(   rP  z BaseDocTemplate.addPageTemplatesQ  s6    ]#*OM  	)A%%a(	)r'   c                    t         g| _        t        | j                  t              r,| j                  | j                         | j                          n| j                  | j                     | _        d| _	        | j                          y)z*implement actions at beginning of documentr   N)r   rj  r   _firstPageTemplateIndexr@   rm   _setPageTemplater  pageTemplatepagebeforeDocumentrP   s    r(   handle_documentBeginz$BaseDocTemplate.handle_documentBeginZ  sg    "d2248(()E)EF!!# $ 2 243O3O PD	r'   c                    | xj                   dz  c_         | j                  r"t        j                  d| j                   z         | j                  j                  | j                  |        | j                  j                  | j                  |        | j                  j                  | j                  |        | j                  j                  D ]  }|j                           | j                          d| _        t        | d      r| `| j                  j                  d   | _        | j                  | j                  _        | j!                  | j"                         y)z\Perform actions required at beginning of page.
        shouldn't normally be called directlyrJ   zbeginning page %dr   _nextFrameIndex)pageTopFlowablesN)rs  r/  loggerdebugrr  r   r   r   r   r   _reset
beforePagerV  r3   rw  r   handle_frameBeginrZ  )rG   r4   s     r(   handle_pageBeginz BaseDocTemplate.handle_pageBegine  s     			Q	;;%8499%DE((48''		$7  40""))5A188:5%&"4)*$&&--a0
 KK

0F0FGr'   c                 b   t        | d      r| j                  j                  | _        y t        | d      r!| j                  | j
                     | _        | `y | j                  j                  rD| j                  | j                  j                         | j                  | j
                     | _        y y )N_nextPageTemplateCycle_nextPageTemplateIndex)r3   r  rM   rr  r  r  r   rm   rP   s    r(   rq  z BaseDocTemplate._setPageTemplatew  s    401 $ ; ; F FDT23 $ 2 243N3N OD+33(():):)O)OP $ 2 243N3N OD 4r'   c                    t        |      rt        | dg       S t        |t              rJ|t	        | d      r%| j
                  | j                     j                  k(  S | j                  j                  k(  S t        |t              red|cxk  rt        | j
                        k  rFn y t	        | d      r|| j                  k(  S || j
                  j                  | j                        k(  S y y )Nr  r  r   )r   r2   r   r    r3   r  r  r   rr  r   rK   find)rG   npts     r(   _samePTzBaseDocTemplate._samePT  s    :4 8<<c(#QXY]^vQw4--d.I.IJMM  S  S  ~B  ~O  ~O  ~R  ~R  S  Sc#1c#A#d.@.@*A#At45D7777**//0A0ABBB $Br'   c                 .   | j                  d       | j                  j                  | _        | j                  j                  | _        | j                  j                  | _        | j
                  dk(  r| xj                  dz  c_        nd| _        | j                  | j                  k\  r	 d| j                  z  }t        |      | j                  r*| j                  d| j                  j                                | j                  j                  | j                  |        | j                  j                  | j                  |        | j                          | j                   r"t"        j%                  d| j&                  z         | j                  j)                  t+        | j                  d| j,                               | j                  j/                          | j1                          | j                  dk(  r	 | j2                  j5                  t6               y)	zf show the current page
            check the next page template
            hang a page begin
        )rs  r   r   rJ   zrMore than %d pages generated without content - halting layout.  Likely that a flowable is too large for any frame.PAGEzending page %dr.  N)_removeVarsr   r   r   r[  rV  rW  rX  r	   rT  r   getPageNumberrr  r   r   	afterPager/  ry  rz  rs  setPageRotationr2   r.  showPagerq  rj  r  r   )rG   idents     r(   handle_pageEndzBaseDocTemplate.handle_pageEnd  s   
 	)* $

 ; ;!%!=!=--%%*! Dt666 M  PT  Pg  Pg  g!%((   )@)@)BC++DIIt<''		48NN{{FLL)9DII)EFII%%gd.?.?
4==&YZII !!#"Y'r'   c                     | j                   r|s| j                          yt        | j                        }t        | j                        |k(  r*| j	                          t        | j                        |k(  r)yy)z+some might choose not to end all the framesN)r-  r  rK   rj  handle_frameEnd)rG   slowr   s      r(   handle_pageBreakz BaseDocTemplate.handle_pageBreak  sW    !DMM"Admm$a'$$& dmm$a'r'   c                    | j                   }|j                  rL| j                   j                  xs | j                  }|r&| j                   j                  | j                  |       | j
                  |_        | j                  |_        | j                  |_        |r| j                  j                  |       | j                  r&| j                  j                  | j                         yy)z&What to do at the beginning of a frameN)r   r   r  drawBoundaryr   r   r   r[  rj  extendrY  )rG   r   rx  r4   boundarys        r(   r}  z!BaseDocTemplate.handle_frameBegin  s    JJ88zz..C$2C2CH

''		(;!22"44nnMM  !12MM  !3!34 r'   c                    | j                  d       | j                  j                  | _        | j                  j                  | _        | j                  j                  | _        t        | d      rW| j                  j                  | j                     | _        | j                  | j                  _	        | `| j                  |       y| j                  }t        |d      s|| j                  j                  d   u r| j                          d| _        y| j                  j                  | j                  j                  j                  |      dz      | _        | j                  | j                  _	        | j                          y)z Handles the semantics of the end of a frame. This includes the selection of
            the next frame or if this is the last frame then invoke pageEnd.
        )r   rw  	lastFrameNrJ   )r  r   r   r   r[  r3   rr  r   rw  r/  r}  r  index)rG   r   r4   s      r(   r  zBaseDocTemplate.handle_frameEnd  s$    	$ $

 ; ;!%!=!=--4)***11$2F2FGDJ $DJJ$""6*

Aq%d.?.?.F.Fr.J)J##%!
!..55d6G6G6N6N6T6TUV6WZ[6[\
$(KK

!&&(r'   c                    t        |t              r^t        | d      r| `| j                  D ]3  }|j
                  |k(  s| j                  j                  |      | _         y t        d|z        t        |t              rt        | d      r| `|| _        yt        |      rt               }|D ]^  }d}|dk(  rt        |      |_        | j                  D ]%  }|j
                  |k(  s|j                  |       d}' |rRt        d|z         |st        d      |j                  t        |      kD  rt        d	      || _        yt        d
      )z<On endPage change to the page template with name or index ptr  Ncan't find template('%s')r   r   rJ   #Cannot find page template called %s No valid page templates in cycleInvalid cycle restart position/argument pt should be string or integer or list)r   r    r3   r  r  r   r  r  rO  r   r   r=   rK   rB   r  	TypeErrorrG   r   rn  r7   ptnfounds         r(   rm   z'BaseDocTemplate.handle_nextPageTemplate  sQ   b"t56D<W'' 442:262D2D2J2J12MD/ 8;<<3t56D<W*,D'2Y 	A 
R8!$QAJ++ "Atts{ !" $%JS%PQQ
R  !CDDCF" !ABB +,D'MNNr'   c                 D   t        |t              r2| j                  D ]  }|j                  |k(  s|c S  t	        d|z        t        |t
              r| j                  |    y t        |      rt               }|D ]^  }d}|dk(  rt        |      |_	        | j                  D ]%  }|j                  |k(  s|j                  |       d}' |rRt	        d|z         |st	        d      |j                  t        |      kD  rt	        d      |j                  S t        d      )	Nr  r   r   rJ   r  r  r  r  )r   r    r  r   rO  r   r   r=   rK   rB   r  rQ   r  r  s         r(   _peekNextPageTemplatez%BaseDocTemplate._peekNextPageTemplate  s   b"'' 442:H 8;<<3r"2Y 	A 
R8!$QAJ++ "Atts{ !" $%JS%PQQ
R  !CDDCF" !ABB66MMNNr'   c                    t        | d      r#| j                  j                  | j                     S | j                  }t        |d      s|| j                  j                  d   u rt        | d      r| j
                  j                  }nnt        | d      r| j                  | j                     }nH| j                  j                  r&| j                  | j                  j                        }n| j                  }|j                  d   S | j                  j                  | j                  j                  j                  |      dz      S )z(intended to be used by extreme flowablesrw  r  r  r  r  r   rJ   )r3   rr  r   rw  r   r  rQ   r  r  r   r  r  )rG   r4   rr  s      r(   _peekNextFramezBaseDocTemplate._peekNextFrame#  s   4)*$$++D,@,@AAJJ1[!Q$*;*;*B*B2*F%Ft45#::??67#11$2M2MN""77#99$:K:K:`:`a#00&&q))$$++D,=,=,D,D,J,J1,MPQ,QRRr'   c                    t        |t              r| j                  j                  D ]=  }|j                  |k(  s| j                  j                  j                  |      | _         y t        d|d| j                  d| j                  j                  d| j                  j                  D cg c]  }||j                  f c}      t        |t              r|| _        yt        d      c c}w )z5On endFrame change to the frame with name or index fxNzcan't find frame('z') in r0   z) which has frames z'argument fx should be string or integer)
r   r    rr  r   r   r  rw  rO  r   r  )rG   fxr   r4   s       r(   r   z BaseDocTemplate.handle_nextFrame6  s   b"&&-- 442:+/+<+<+C+C+I+I!+LD( UWX\XiXijnj{j{j~j~  SW  Sd  Sd  Sk  Sk  @l  NO  BC  DE  DH  DH  AI  @l  m  n  n3#%D EFF	 @ls   ,C-c                 J    | j                  ||       | j                  |       y)z)change to the frame with name or index fxN)r   r  )rG   r  r   s      r(   handle_currentFramez#BaseDocTemplate.handle_currentFrameC  s     b(V$r'   c                    |d   }t        |d      rt        |d       yt        |d      r1|j                  dk(  r"d|_        |j	                  dt                      yt        |d      rQt        |j                  d      r;|j                  j                  dk(  r"d|_        |j	                  dt                      yt        |d      r1|j                  dk(  r"d|_        |j	                  dt                      yt        |d      rSt        |j                  d      r<|j                  j                  dk(  r"d|_        |j	                  dt                      yyyy)zKpreprocessing step to allow pageBreakBefore and frameBreakBefore attributesr   _skipMeNextTimeNpageBreakBeforerJ   styleframeBreakBefore)	r3   r  r  r  insertr   r  r  r   )rG   r   firsts      r(   handle_breakBeforez"BaseDocTemplate.handle_breakBeforeH  s1   ! 5+,E,- 5*+0E0E0J$%E!LLIK(5!gekk;L&MRWR]R]RmRmqrRr$%E!Q	,5+,1G1G11L$%E!Q
-5!gekk;M&NSXS^S^SoSostSt$%E!Q
- Tu&N!r'   c                 f   d}t        |      }||k  rM||   j                         r:t        ||         r,|dz  }||k  r"||   j                         rt        ||         r,|r||k  rt        ||         r|dz  }| j                  |d|       }t	        | dd      }|rZ|j
                  dd D ]G  }t        |d      r |t        |d|j                  f       n |t        |df       d|j                  d<   I n#|j
                  dd D ]  }d|j                  d<    |d|= |j                  d|       yy)zimplements keepWithNextr   rJ   N_multiBuildEditsr  keepWithNext)rK   getKeepWithNextr  r8  r2   _contentr3   r  r  r  __dict__r  )rG   r   ir   Kmber4   s          r(   handle_keepWithNextz#BaseDocTemplate.handle_keepWithNextd  s@   	Ncil224)A,9OQRVWQWQRacil224)A,9Osx	!-qAvq&&y!}5A$1$7CCR 3Aq0WQ~annEFWQ~6712AJJ~.3 CR 3A12AJJ~.3"1"Qq! r'   c                 V    |r||_         	 |j                  |      |r|` S S # |r|` w w xY wrO   )_framer{   )rG   r4   rz   r   s       r(   _fIdentzBaseDocTemplate._fIdentz  s/    U!(	#::f%!(uu!(us   ! (c           	         | j                  |       |d   }|r'| j                  |       | j                  |       |d   }|d= |yt        |t              r|j
                  }|r>| j                  |      s-t        |      }|j                  |        | j                  |       t        |t              r| j                  d       n| j                          | j                  |       yt        |t              r#|j                  |        | j                  |       y| j                  }| j                  }|j                  ||| j                         rCt        |t"              s&| xj$                  dz  c_        | j                  |       t'        ||       y| j                   r|j)                  ||      }t+        |      }nd}|rt        d   t        t        t        t,        f      s|j                  |d   |d      sCd|| j.                  | j1                  |d|      | j1                  |d   d|      fz  }t3        |      | xj$                  dz  c_        | j                  |d          |dd |dd t'        ||       y||dd yt5        |d      rzd	| j1                  |d|      t7        |      | j.                  | j                  j8                  | j                  j;                         | j<                  j8                  fz  }t3        |      d|_        tA        | d
d      }	|	r |	tB        |df       |jE                  d|       | jG                          y)z<try to handle one flowable from the front of list flowables.r   NrJ   )r  )trySplitz/Splitting error(n==%d) on page %d in
%s
S[0]=%s<   
_postponedz?Flowable %s%s too large on page %d in frame %r%s of template %rr  )$filterFlowablesr  r  r   r   r   r  r   rt   afterFlowableSlowPageBreakr  r   r   r   r  r$  r   rV  r   splitrK   
DDIndenterrs  r  r	   r3   r8   r   _aSpaceStringrr  r  r2   r  r  r  )
rG   r   r4   r  r   r   r   r   r  r  s
             r(   rk  zBaseDocTemplate.handle_flowable  s   
 	Y'aL##I.$$Y/!AaL9a	"..C4<<,$S)		$""3'!M*%%1%-%%'q!.)GGDMq!JJE99DyyD4+>+>y?!!$78..!3.&&q)$Yu5&&Ad+AAAA%adImNS]+^_$yy1tay@$W[\]a]f]fgkgsgstuvxy~g  AE  AM  AM  NO  PQ  NR  SU  V[  A\  []  %]E"-e"4422a72**1Q40)*12	!A,Yu=)*	!Aq. a!%a5!9,q/$))UYU_U_UbUb(,

(@(@(BDDUDUDXDX!Z!Z *%00#$AL!$'9$?CWQ|45$$Qq)((*r'   c                 b   t         j                  j                  j                         | _         ||xs | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                        } t%        |dd       | j&                         | j(                  |_        |j-                  | j.                         |j1                  | j2                         |j5                  | j6                         |j9                  | j:                         |j=                  | j>                         |jA                  | jB                         ddl"m#}m$} |jJ                  jM                         D ]I  \  }}t%        | |d   jO                         |dd z   d      }|-||u rdd	g|   }|jQ                  ||       K | jR                  r|jU                  | jR                         |S )
a  make and return a sample canvas. As suggested by 
        Chris Jerdonek cjerdonek @ bitbucket this allows testing of stringWidths
        etc.

        *NB* only the canvases created in self._startBuild will actually be used
        in the build process.
        )r   r+  r,  r2  r5  r6  r7  r   r   r   r   r4  
setEncryptc                      y rO   r&   )r   s    r(   <lambda>z-BaseDocTemplate._makeCanvas.<locals>.<lambda>  s    r'   r   )ViewerPreferencesPDFDictionarycheckPDFBooleanrJ   Nfalsetrue)+	reportlablib	sequencer	SequencerseqrH  r   r+  r,  r2  r5  r6  r7  r   r   r   r   r4  r2   r0  r1  
_cropMarks	setAuthorr&  setTitler%  
setSubjectr'  
setCreatorr(  setProducerr)  setKeywordsr*  reportlab.pdfbase.pdfdocr  r  validateitemslowersetViewerPreferencerS  rf  )	rG   rH  canvasmakerr   VPDcPDFBr^  vfrL   s	            r(   _makeCanvaszBaseDocTemplate._makeCanvas  s    ==**44684t}}%)]]&*nn,0,@,@.2.D.D.2.B.B.2.B.B-1-@-@&*ll%)[[&*ll'+}}#'99 	2\.1$,,?..t{{#djj!%%''	 LL&&( 	.DAbQqTZZ\!AB%/5A}; (+A((1-	. <<  .r'   c                 t    | j                          | j                  ||      | _        | j                          y )N)rH  r  )r\  r  r   ru  )rG   rH  r  s      r(   _startBuildzBaseDocTemplate._startBuild  s.    

$$h;$O	!!#r'   c                    | j                  d       | j                  g k7  r3| j                  d   t        u r| j                  d= | j                          n | j                          | j	                          t        | dd      r| j                  j                          | j                  r| j                  j                  d        y y )N)buildrs  r   r  _doSaverJ   )
r  rj  r   rl  r  r2   r   saverS  rf  rP   s    r(   	_endBuildzBaseDocTemplate._endBuild
  s    12=="r!2i!?b!  !!#4	!$diinn&6<<2248<r'   c           
         t        |      }| j                  r-| j                  dd       | j                  dt        |             | j                  ||       | j                  }|j                  j
                  | _        d}	 | |_        t        |      r| j                  ry| j                  d   t        u rdt        |d   t              rQ|d   j                  }|r=| j                  |      s,t        |      }|j                  |        | j!                          |d= | j#                          	 |d   }| j%                  |       |dz  }| j                  r| j                  d|t        |      z
         t        |      r|`| j                  |j                  _        | j?                          | j                  r| j                  d	d       y
y
#  t'        d      r|j(                  rt+        j,                         d   }	t/        |	j0                        }
|j(                  }|
dxx   d|j2                  |j4                  |j6                  |j8                  |j:                  fz  z  cc<   t=        |
      |	_         xY w# |`w xY w)a  Build the document from a list of flowables.
           If the filename argument is provided then that filename is used
           rather than the one provided upon initialization.
           If the canvasmaker argument is provided then it will be used
           instead of the default.  For example a slideshow might use
           an alternate canvas which places 6 slides on a page (by
           doing translations, scalings and redefining the page break
           operations).
        STARTEDr   SIZE_ESTr  rJ   
_traceInfoz1
(srcFile %s, line %d char %d to line %d char %d)PROGRESSFINISHEDN) rK   rT  r  r   _docinfo
_savedInfo_doctemplaterj  r   r   PageBreakIfNotEmptyr   r  r   rt   rq  rl  rk  r3   r  sysexc_infor@   rE   srcFilestartLineNostartLinePos	endLineNo
endLinePosri   r  )rG   r   rH  r  flowableCountr   handledr  r  excrE   trs               r(   r  zBaseDocTemplate.build  s"    IYq)ZY8+. yy))..!	" $Di.==T]]2%6)%C
S\]^S_`sHt#A,33C4<<#4,S1		$--/!!""$%aLE((3qLG  ##$$ZI0NO; i.> ! 		Z* 3ul38H8H!llnQ/#CHH~"--Q#WJJNNOOLLMM[ $  $); !s&   B'I4 )G 5I4 B*I11I4 4I8c                 V    d}| j                   D ]  }|j                         rd} |S  |S )z:Called by multi-build - are all cross-references resolved?rJ   r   )rR  rX   )rG   allHappyr4   s      r(   _allSatisfiedzBaseDocTemplate._allSatisfiedX  s9    (( 	A==?		 r'   c                     | j                   D ]@  }t        |d|       }	 || k(  r| j                  |_        |j	                  ||       || k(  s?|`B y# || k(  r|`w w xY w)zForward to any listeners_canvN)rR  r2   r   r  r\   )rG   rZ   r[   lr  s        r(   r\   zBaseDocTemplate.notifya  sk    (( 	 AAgd+E $;"iiAGu%$;	  $; s   (A
Ac                 v    t         rt        d|| j                  fz         | j                  | j                  |<   y)zhook to register a page numberz)pageRef called with label '%s' on page %dN)r   printrs  rQ  )rG   r   s     r(   pageRefzBaseDocTemplate.pageRefm  s5    EE499I   $		ur'   c                    g | _         |D ].  }|j                         s| j                   j                  |       0 d| _        d}g }|j                  | _        	 |dz  }| j
                  r| j                  d|       t        r.t        j                  j                  dt        |      z   dz          | j                   D ]  }|j                           |dd } | j                  |fi | | j                   D ]  }|j                           | j                         }	|	r"d| _        | j                  j!                          n6||kD  rt#        d|z        |r|j%                  d      }
 |
d   |
dd   |r| `t        rt'        d       |S )	zgMakes multiple passes until all indexing flowables
        are happy.

        Returns number of passesr   rJ   PASSzbuilding pass z...Nz*Index entries not resolved after %d passessaved)rR  rU   r  r  r  rT  r   r  stdoutwriterx   r_   r  rb   r	  r   r  
IndexErrorpopr  )rG   story	maxPasses	buildKwdsthingpassesr  fl	tempStoryhappyes              r(   
multiBuildzBaseDocTemplate.multiBuilds  s    #% 	6E!''..u5	6
  #

aKF  0

(()9#f+)E)MN-- ! ! aIDJJy.I. --    &&(E 		 	! !MPY!YZZ GGAJ!ae 7 > !E'Nr'   c                      y)z6This is called after initialisation of the base class.Nr&   rP   s    r(   r]  zBaseDocTemplate.afterInit  rc   r'   c                      y)zEThis is called before any processing is
        done on the document.Nr&   rP   s    r(   rt  zBaseDocTemplate.beforeDocument  r`   r'   c                      y)zThis is called at the beginning of page
        processing, and immediately before the
        beforeDrawPage method of the current page
        template.Nr&   rP   s    r(   r|  zBaseDocTemplate.beforePage  r   r'   c                      y)zThis is called after page processing, and
        immediately after the afterDrawPage method
        of the current page template.Nr&   rP   s    r(   r  zBaseDocTemplate.afterPage  r]   r'   c                      y)zcalled to filter flowables at the start of the main handle_flowable method.
        Upon return if flowables[0] has been set to None it is discarded and the main
        method returns.
        Nr&   )rG   r   s     r(   r  zBaseDocTemplate.filterFlowables  r   r'   c                      y)z)called after a flowable has been renderedNr&   )rG   flowables     r(   r  zBaseDocTemplate.afterFlowable  rc   r'   )rs  r   r  foreverc                     t        |t              st        |      }|j                         }|j                         }| j	                  |j                         d|j                         d|       y )Nz=(r1   )r   r    rx   stripdocExec)rG   varexprlifetimes       r(   	docAssignzBaseDocTemplate.docAssign  sI    $x(s4y$ZZ\IIK		DJJL9(Cr'   c                    |j                         }| j                  }t        |j                               }	 || j                  vrt        d|d| j                        t        ||       | j                  |j                         D cg c]	  }||vs| c}|       y #  |D cg c]	  }||vs| nc c}w }}|D ]  }||=  t        d|d|d       Y nxY wc c}w )Nzbad lifetime z not in z	
docExec z
 lifetime=z	 failed!
)	r*  rJ  r@   rM  _allowedLifetimesrO  execr   _addVars)rG   stmtr.  NSK0r^  K1s          r(   r+  zBaseDocTemplate.docExec  s    ZZ\??	?	Vt555 htG]G]!^__rN 	"'');Qq{q;HE	V/1B;!//B/ qEd8TU;s)   5B  		CC C&	B50B54$Cc                     | j                   }|D ]W  }|j                         D ]  }||v s|j                  |        |j                  |t	        g             j                  |       Y y)z*add namespace variables to lifetimes listsN)rK  valuesremove
setdefaultsetr  )rG   varsr.  LTr,  rL   s         r(   r3  zBaseDocTemplate._addVars  s`    ?? 	5CYY[ "!8HHSM" MM(3r7+//4		5r'   c                     | j                   }| j                  }|D ]   }|j                  |g       D ]  }	 ||=  ||= " y# t        $ r Y w xY w)z9remove namespace variables for with lifetime in lifetimesN)rK  rJ  r;  KeyError)rG   	lifetimesr>  r5  r.  r^  s         r(   r  zBaseDocTemplate._removeVars  sf    ????! 	H]]8B/ 1
 8	   s   ?	A
Ac                 x    	 t        |j                         i | j                        S #  t        d|z         Y y xY w)Nz
docEval %s failed!
)evalr*  rJ  r   )rG   r-  s     r(   docEvalzBaseDocTemplate.docEval  s5    	?

R88	?6=>s   $' 9rO   )r   Nr   )NN)rG  )@r#   r$   r%   rd   r   r   KeepTogetherrL  rN  rp  rh   r\  rf  rh  rl  rP  ru  r~  rq  r  r  r  r}  r  rm   r  r  r   r  r  r  r  rk  _handle_documentBegin_handle_pageBegin_handle_pageEnd_handle_frameBegin_handle_frameEnd_handle_flowable_handle_nextPageTemplate_handle_currentFrame_handle_nextFramer   Canvasr  r  r  r  r	  r\   r  r   r]  rt  r|  r  r  r  r1  r/  r+  r3  r  rD  r&   r'   r(   r   r     s$   6n-J -#B-"1- !- "$	-
  - #4- %Q- D- T- d- d- t- r-  - &d-  &a!-" q#-$ Q%-& t'-(  )-* (+-, &t--. D/-0 &t1-2 &t3-4 %d5-6 t7-8 d9-: t;-< =-> (?-@ "4A-B "4C-D %)!%$(-1!% $ $!%!%$("Y-I\ ,\: 0
)	H$	PC!(F'5)0#OJO>S&G%
8",#G+T 1($O*&&6.(#'V]] .` $(V]] $

9 )-&-- @+D
 *  "4t
 9DF5
?r'   r   c                   <    e Zd ZdZdZd Zeeej                  fdZ	y)r   a  A special case document template that will handle many simple documents.
       See documentation for BaseDocTemplate.  No pageTemplates are required
       for this special case.   A page templates are inferred from the
       margin information and the onFirstPage, onLaterPages arguments to the build method.

       A document which has all pages with the same look except for the first
       page may can be built using this special approach.
    )r  c                 F    | j                          | j                  d       y)zSoverride base method to add a change of page template after the firstpage.
        LaterN)rG  rL  rP   s    r(   r~  z"SimpleDocTemplate.handle_pageBegin
  s     	 %%g.r'   c           	         | j                          t        | j                  | j                  | j                  | j
                  d      }| j                  t        d||| j                        t        d||| j                        g       |t        u r*t        | d      r| j                  | j                  d   _        |t        u r*t        | d      r| j                  | j                  d	   _        t        j!                  | ||
       y)a[  build the document using the flowables.  Annotate the first page using the onFirstPage
               function and later pages using the onLaterPages function.  The onXXX pages should follow
               the signature

                  def myOnFirstPage(canvas, document):
                      # do annotations and modify the document
                      ...

               The functions can do things like draw logos, page numbers,
               footers, etcetera. They can use external variables to vary
               the look (for example providing page numbering or section names).
        normal)r   First)r   r   r   r   rR  onFirstPager   onLaterPagesrJ   )r  N)r\  r   r   r#  r*   r,   rP  r   r   r;   r3   rV  r  r   rW  r   r  )rG   r   rV  rW  r  frameTs         r(   r  zSimpleDocTemplate.build  s     	

t(9(94::t{{W_`|wf[bfbobop$vl\`\i\ijl 	m*$m)D373C3CDq!0:%'$~*F373D3DDq!0d9+Fr'   N)
r#   r$   r%   rd   rN  r~  r;   r   rO  r  r&   r'   r(   r   r     s*     */ *4*Z`ZgZg Gr'   r   c                 $    t        d| |fz         y)aM  Example prototype for progress monitoring.

    This aims to provide info about what is going on
    during a big job.  It should enable, for example, a reasonably
    smooth progress bar to be drawn.  We design the argument
    signature to be predictable and conducive to programming in
    other (type safe) languages.  If set, this will be called
    repeatedly with pairs of values.  The first is a string
    indicating the type of call; the second is a numeric value.

    typ 'STARTING', value = 0
    typ 'SIZE_EST', value = numeric estimate of job size
    typ 'PASS', value = number of this rendering pass
    typ 'PROGRESS', value = number between 0 and SIZE_EST
    typ 'PAGE', value = page number of page
    type 'FINISHED', value = 0

    The sequence is
        STARTING - always called once
        SIZE_EST - always called once
        PROGRESS - called often
        PAGE - called often when page is emitted
        FINISHED - called when really, really finished

    some juggling is needed to accurately estimate numbers of
    pages in pageDrawing mode.

    NOTE: the SIZE_EST is a guess.  It is possible that the
    PROGRESS value may slightly exceed it, or may even step
    back a little on rare occasions.  The only way to be
    really accurate would be to do two passes, and I don't
    want to take that performance hit.
    zPROGRESS MONITOR:  %-10s   %dN)r  )typr   s     r(   
progressCBr[  '  s    D 

)S%L
89r'   __main__)_baseFontName_baseFontNameBc                    ddl m} | j                  d   } | j                           | j                  |        | j
                  d        | j                  ddd|dz
          | j                  t        d        | j                  d|dz
  d	        | j                  t        d
        | j                  dt        z  dt        z  d        | j                          y )Nr   redrJ      B   H      l   zTABLE OF CONTENTS DEMO            ?z
First Page)reportlab.lib.colorsra  r   	saveStatesetStrokeColorsetLineWidthlinesetFontr^  
drawStringr]  r   restoreStater   r:   ra  PAGE_HEIGHTs       r(   myFirstPagert  M  s    ,&&q)c"ABr"[^,~b)#{30HI}R(!d(D4K>r'   c                 v   ddl m} | j                  d   } | j                           | j                  |        | j
                  d        | j                  ddd|dz
          | j                  t        d        | j                  dt        z  d	t        z  d
|j                  z          | j                          y )Nr   r`  rJ   rb  rc  rd  rg  rh  ri  zPage %d)rj  ra  r   rk  rl  rm  rn  ro  r]  rp  r   rs  rq  rr  s       r(   myLaterPagesrv  Z  s    ,&&q)c"ABr"[^,}R(!d(D4KSXX1EFr'   c                     g } ddl m} ddlm}  |d      }d|_        d|_        ddlm} dd l}t        d      D ]i  }d	d
|j                         z  z   }t        dt        z  |t        z  d|z        }| j                  |       t         |       |      }	| j                  |	       k  |d      j                  | t        t                y )Nr   )ParagraphStyle)r   rT        )
randomText   g      ?   zBox Number %dzdoctemplate.pdf)rV  rW  )reportlab.lib.stylesrx  reportlab.platypus.doctemplater   firstLineIndentspaceBeforereportlab.lib.randomtextr{  randomrangeXBoxr   r  r   r  rt  rv  )
objects_to_drawrx  r   rT  r{  r  r  r,   r   paras
             r(   runr  e  s    7D  )!#7r 	)AAfmmo-.Fq4x$!0CDC""3'Z\62D""4(	) 	+,22?# 	3 	?r'   )E__all____version__rd   reportlab.platypus.flowablesr   reportlab.lib.unitsr   reportlab.platypus.paragraphr   reportlab.platypus.framesr   reportlab.rl_configr   r   reportlab.lib.sequencerr  reportlab.pdfgenr   reportlab.lib.utilsr   r   r   r   r    r<  	NameErrorsetsr!   r  logging	getLoggerry  	Exceptionr	   r8   r;   r@   r=   rg   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   rx   r   r   r  r   r   r[  r#   r~  r]  r^  rt  rv  r  r&   r'   r(   <module>r     s  
& 	0 + 8 $ 2 + 8  # ^ ^   			/	0	) 	(	d &x 4%MX %MN 
	^~ 	^> >
A+ A '" '  $
[)	v( v." ."S+ S>~ >? ?B%	: 	:=8 =8~aV? V?p&G &GP":H zB	?, Ea ](    s   E0 0E?>E?