
    Q?hS              	          S r SrSSKJr  SSKJrJrJrJrJ	r	J
r
Jr  SSKJrJr  SSKJr  SSKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  SSKrSSK J!r!  S r" \#  S"S jr%S\-  r&S\-  r'\" S\SSS\'S9/r(\" / SQ5      r) " S S\5      r*S r+ " S S\5      r,\,r-S r. " S  S!\5      r/g!    " S S\$5      r# N^= f)#z4.2.1.1a  Experimental class to generate Tables of Contents easily

This module defines a single TableOfContents() class that can be used to
create automatically a table of tontents for Platypus documents like
this:

    story = []
    toc = TableOfContents()
    story.append(toc)
    # some heading paragraphs here...
    doc = MyTemplate(path)
    doc.multiBuild(story)

The data needed to create the table is a list of (level, text, pageNum)
triplets, plus some paragraph styles for each level of the table itself.
The triplets will usually be created in a document template's method
like afterFlowable(), making notification calls using the notify()
method with appropriate data like this:

    (level, text, pageNum) = ...
    self.notify('TOCEntry', (level, text, pageNum))

Optionally the list can contain four items in which case the last item
is a destination key which the entry should point to. A bookmark
with this key needs to be created first like this:

    key = 'ch%s' % self.seq.nextf('chapter')
    self.canv.bookmarkPage(key)
    self.notify('TOCEntry', (level, text, pageNum, key))

As the table of contents need at least two passes over the Platypus
story which is why the multiBuild() method must be called.

The level<NUMBER>ParaStyle variables are the paragraph styles used
to format the entries in the table of contents. Their indentation
is calculated like this: each entry starts at a multiple of some
constant named delta. If one entry spans more than one line, all
lines after the first are indented by the same constant named
epsilon.
    )cm)
commasplit
escapeOnceencode_labeldecode_labelstrTypes	asUnicodeasNative)ParagraphStyle_baseFontName)	sequencer)	Paragraph)IndexingFlowable)
TableStyleTable)Spacer)stringWidthcanvasN)literal_evalc                 &    SSK Jn  U" U SSS.5      $ )Nr   )unescape'")z&apos;z&quot;)xml.sax.saxutilsr   )txtr   s     T/var/www/html/env/lib/python3.13/site-packages/reportlab/platypus/tableofcontents.pyunquoter   <   s    )CC3788    c                       \ rS rSrS rSrg)setC   c                 :    X;  a  [         R                  X5        g g N)listappend)selfxs     r   addset.addD   s    }D# r    N)__name__
__module____qualname____firstlineno__r)   __static_attributes__r+   r   r   r!   r!   C   s    	$r   r!   c           
      "   SR                  U VVs/ s H  u  px[        U5      PM     snn5      n	U R                  S   U R                  S   pUR                  n[	        XR
                  U5      nX:-
  nX:  a.  US:  a(  SU-  n[	        XR
                  U5      nX:  a  US:  a  M(  [        U[        5      (       aP  U(       a*  [	        XQR
                  U5      n[        X:-
  U-
  U-  5      nOS=nnUU-  < U	< 3nUUU-  -
  U-
  nX=-
  nOUc
  SU	-   nU
nUnO[        S	5      eU R                  " UU5      nUR                  UR
                  U5        UR                  UR                  5        UR                  U5        U R                  " U5        [	        SUR
                  U5      nU H]  u  nnU(       d  M  [	        [        U5      UR
                  U5      nU R                   " S
UUUUU-   XR"                  -   4SS9  UUU-   -  nM_     gs  snnf )z
Draws pagestr on the canvas using the given style.
If dot is None, pagestr is drawn at the current position in the canvas.
If dot is a string, pagestr is drawn right-aligned. If the string is not empty,
the gap is filled with it.
, cur_xcur_yg      ?g?r   Nz,  z@Argument dot should either be None or an instance of basestring.    )relative)joinstr_curr_tx_infofontSizer   fontName
isinstancer   int	TypeError	beginTextsetFontsetFillColor	textColortextLinedrawTextlinkRectleading)r   stylepages
availWidthavailHeightdot	formatterp_pagestrr(   yr;   pagestrw	freeWidthdotwdotsntextnewxpagextxcommawkeyws                           r   drawPageNumbersr]   H   s    iiE2EDAQE23G(&*>*>w*Gq~~H7NNH=H I

8s?>wA 
8s?
 #x  sNNH=Dh.45EEDg.E$J&1%	wZ[[			$	"BJJu~~x(OOEOO$KK
OOBu~~x8F3A9C%E!GQ}}_!EPQRV Q 3s   H
r6   g      ?zLevel 0
      )namer<   r;   rG   firstLineIndent
leftIndent))VALIGNr   r   rf   TOP)RIGHTPADDINGrd   re   r   )LEFTPADDINGrd   re   r   c                   h    \ rS rSrSrS rS rS rS rS r	S r
S	 rSS jrS rS rS rSS jrSrg
)TableOfContents   a  This creates a formatted table of contents.

It presumes a correct block of data is passed in.
The data block contains a list of (level, text, pageNumber)
triplets.  You can supply a paragraph style for each level
(starting at zero).
Set dotsMinLevel to determine from which level on a line of
dots should be drawn between the text and the page number.
If dotsMinLevel is set to a negative value, no dotted lines are drawn.
c                    UR                  SS5      U l        UR                  S[        5      U l        UR                  S[        5      U l        UR                  SS5      U l        UR                  SS 5      U l        UR                  SS	5      U l        U(       a+  [        S
SR                  UR                  5       5      -  5      eS U l        / U l        / U l        g )NrightColumnWidthH   levelStyles
tableStyledotsMinLevelr6   rM   
notifyKindTOCEntryzunexpected keyword arguments %sr2   )poprn   defaultLevelStylesrp   defaultTableStylerq   rr   rM   _notifyKind
ValueErrorr8   keys_table_entries_lastEntries)r'   kwdss     r   __init__TableOfContents.__init__   s     $);B ?88M2DE((<0AB HH^A6+d388L<z"CdiiPTPYPYP[F\"\]]r   c                 L    U R                   S S  U l        U R                  5         g r$   )r|   r}   clearEntriesr'   s    r   beforeBuildTableOfContents.beforeBuild   s     MM!,r   c                     gNr6   r+   r   s    r   
isIndexingTableOfContents.isIndexing       r   c                 4    U R                   U R                  :H  $ r$   r|   r}   r   s    r   isSatisfiedTableOfContents.isSatisfied       !2!223r   c                 B    XR                   :X  a  U R                  " U6   gg)zThe notification hook called to register all kinds of events.

Here we are interested in self._notifyKind (default TOCEntry) events only.
N)rx   addEntry)r'   kindstuffs      r   notifyTableOfContents.notify   s!    
 ###MM5! $r   c                     / U l         g r$   r|   r   s    r   r   TableOfContents.clearEntries   	    r   c           
      4    U R                   U   $ ! [         a|    U R                  US-
  5      nU R                   R                  [	        SUR
                  U4-  UUR                  [        -   UR                  [        -   S95        U R                   U   s $ f = f)VReturns the style for level n, generating and caching styles on demand if not present.r6   %s-%d-indentedr`   parentra   rb   )	rp   
IndexErrorgetLevelStyler&   r   r`   ra   deltarb   r'   n	prevstyles      r   r   TableOfContents.getLevelStyle   s    		'##A&& 	'**1Q3/I##N)Y^^Q,??$&/&?&?&E!*!5!5e!;	%= >
 ##A&&	's    BBBNc                 |    [        U5      [        S5      :X  d   S5       eU R                  R                  XX445        g)zAdds one entry to the table of contents.

This allows incremental buildup by a doctemplate.
Requires that enough styles are defined.r6   zLevel must be an integerN)typer|   r&   )r'   levelrV   pageNumr[   s        r   r   TableOfContents.addEntry   s7     E{d1g%A'AA%e789r   c                 4    U H  nU R                   " U6   M     g)zBulk creation of entries in the table of contents.

If you knew the titles but not the page numbers, you could
supply them to get sensible output on the first run.N)r   )r'   listOfEntries	entryargss      r   
addEntriesTableOfContents.addEntries   s     'IMM9% 'r   c                   ^ ^^ [        T R                  5      S:X  a  S/nOT R                  nUUU 4S jnUT R                  l        / nU H  u  pgpT R	                  U5      n
U	(       a7  SU	< SU< S3n[        U	5      R                  SS5      R                  S	S5      nOS
n[        SXxXk4-  U
5      nU
R                  (       a&  UR                  [        SU
R                  5      /5        UR                  U/5        M     [        UT4T R                  S9T l        T R                  R                  T R                  TT5      u  T l        T l        T R                  T R                   4$ ),All table properties should be known by now.r   )r   z!Placeholder for table of contentsr   Nc                 L  > UR                  S5      n[        US   5      [        US   5      [        US   5      pTnT
R                  U5      nT
R                  S:  a  UT
R                  :  a  SnOSnT
R
                  (       a  T
R                  U5      n[        XX54/T	TU5        g)8Callback to draw dots and page numbers after each entry.,r   r6       . r5   N)splitr>   r   r   rr   rM   r]   )r   r   labelpager   r[   rH   rL   rK   rJ   r'   s           r   drawTOCEntryEnd-TableOfContents.wrap.<locals>.drawTOCEntryEnd   s    KK$E"58}c%(m\%PQ(=SD&&u-E  A%%43D3D*D~~dnnT&:tFTK=*kSVWr   z
<a href="#z">z</a>r   z\x2cr   Nz3%s<onDraw name="drawTOCEntryEnd" label="%d,%d,%s"/>r6   	colWidthsrH   )lenr}   canvr   r   reprreplacer   spaceBeforer&   r   r   rq   r{   wrapOnwidthheight)r'   rJ   rK   _tempEntriesr   	tableDatar   rV   r   r[   rH   keyValparas   ```          r   wrapTableOfContents.wrap   s9    t  !Q&JKL,,L
	X %4		!	+7'U'&&u-E14d;c**3w7??GLRVZejUssuz{D    &E,=,=">!@AdW% ,8 I*dooV"&++"4"4TYYz;"W
DK

DKK((r   c                 N    U R                   R                  U R                  X5      $ zAt this stage we do not care about splitting the entries,
we will just return a list of platypus tables.  Presumably the
calling app has a pointer to the original TableOfContents object;
Platypus just sees tables.
)r{   splitOnr   r'   rJ   rK   s      r   r   TableOfContents.split  s     {{""499ZEEr   c                 <    U R                   R                  XX45        gzDon't do this at home!  The standard calls for implementing
draw(); we are hooking this in order to delegate ALL the drawing
work to the embedded table object.
N)r{   drawOnr'   r   r(   rQ   _sWs        r   r   TableOfContents.drawOn  s    
 	6a-r   )r|   r}   rx   r{   rr   rM   r   rp   rn   rq   r   r$   r   )r,   r-   r.   r/   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r0   r+   r   r   rk   rk      sE    	

4"':&))XF.r   rk   c                 T    [        U [        [        45      (       a  [        U 5      $ U 4$ r$   )r=   r%   tuple)r(   s    r   	makeTupler   !  s#    !T%L!!Qx4Kr   c                       \ rS rSrSrS rS rSS jrS r\	R                  4S jrS	 rS
 rS rS rS rSS jrS rS/\" S5      4/4S jrS rS rSS jrS rS rSrg)SimpleIndexi&  zdCreates multi level indexes.
The styling can be cutomized and alphabetic headers turned on and off.
c                     0 U l         0 U l        SU l        UR                  SS5      U l        U R
                  " S0 UD6  g)zM
Constructor of SimpleIndex.
Accepts the same arguments as the setup method.
Nrs   
IndexEntryr+   )r|   r}   	_flowableru   rx   setup)r'   kwargss     r   r   SimpleIndex.__init__+  s<     !::l<@

Vr   c                 b     [        [        SU-  5      $ ! [         a    [        SU-  5      ef = f)Nz
_format_%szUnknown sequencer format %r)getattrrl_sequencerImportErrorry   )r'   
formatNames     r   getFormatFuncSimpleIndex.getFormatFunc7  s<    	I<z(ABB 	I:ZGHH	Is    .Nc                     Uc  [        S[        SS9nXl        U=(       d    [        U l        X l        X@l        Uc  SSKJn  XPl	        U R                  U5      U l        Xpl        g)a!  
This method makes it possible to change styling and other parameters on an existing object.

style is the paragraph style to use for index entries.
dot can either be None or a string. If it's None, entries are immediatly followed by their
    corresponding page numbers. If it's a string, page numbers are aligned on the right side
    of the document and the gap filled with a repeating sequence of the string.
tableStyle is the style used by the table which the index uses to draw itself. Use this to
    change properties like spacing between elements.
headers is a boolean. If it is True, alphabetic headers are displayed in the Index when the first
letter changes. If False, we just output some extra space before the next item
name makes it possible to use several indexes in one document. If you want this use this
    parameter to give each index a unique name. You can then index a term by refering to the
    name of the index which it should appear in:

        <index item="term" name="myindex" />

format can be 'I', 'i', '123',  'ABC', 'abc'
Nindexr_   )r`   r<   r;   r   )DEFAULT_INDEX_NAME)r   r   	textStylerw   rq   rL   headersreportlab.platypus.paraparserr   r`   r   
formatFuncoffset)r'   rH   rL   rq   r   r`   formatr   s           r   r   SimpleIndex.setup=  s]    * ="1>135E $9(9<P	,,V4r   c                    [        US5      n [        U5      u  pEnUc  U R                  nOU R                  U5      nUc  U R                  n[        U5      nUR                  5       nU" X-
  5      n	SU R                  < SU< SU	< 3n
UR                  nUR                  XS   US   US   -   5        U R                  XHU	4U
5        g !   UnS =pV N= f)Nlatin1ix_rO   _p_r3   r4   rG   )r
   r   r   r   r   r   getPageNumberr`   r:   bookmarkHorizontalr   )r'   r   r   r   termsr   r   r   cPNpnsr[   infos               r   __call__SimpleIndex.__call__`  s    x(	#$0$7!E6 >J++F3J>[[F5!  "$!%E37!!']DMDO4STe#Y,#	#E""FVs   C Cc                    ^ ^ UU 4S jnU$ )Nc                  R   > SSK Jn  T" U 0 UD6n[        UTR                  T5        U$ )Nr   r   )reportlab.pdfgenr   setattrr`   )argsr   r   ccanvasmakerr'   s       r   newcanvasmaker2SimpleIndex.getCanvasMaker.<locals>.newcanvasmakery  s*    /T,V,AAdii%Hr   r+   )r'   r  r  s   `` r   getCanvasMakerSimpleIndex.getCanvasMakerw  s    	 r   c                     gr   r+   r   s    r   r   SimpleIndex.isIndexing  r   r   c                 4    U R                   U R                  :H  $ r$   r   r   s    r   r   SimpleIndex.isSatisfied  r   r   c                 b    U R                   R                  5       U l        U R                  5         g r$   )r|   copyr}   r   r   s    r   r   SimpleIndex.beforeBuild  s#     MM..0r   c                     0 U l         g r$   r   r   s    r   r   SimpleIndex.clearEntries  r   r   c                     XR                   :X  a0  Uu  p4U R                  X0R                  R                  5       U45        gg)zThe notification hook called to register all kinds of events.

Here we are interested in self._notifyKind (default IndexEntry) events only.
N)rx   r   _canvr   )r'   r   r   rV   r   s        r   r   SimpleIndex.notify  s:    
 ###!MDMM$!9!9!;G DE $r   c                     U R                   R                  [        U5      [        / 5      5      R	                  X#45        g)zAllows incremental buildupN)r|   
setdefaultr   r!   r)   )r'   rV   r   r[   s       r   r   SimpleIndex.addEntry  s+      4R9==wnMr   c                 N    U R                   R                  U R                  X5      $ r   )r   r   r   r   s      r   r   SimpleIndex.split  s     ~~%%dii
HHr   zPlaceholder for index)NNNc                     U R                   =(       d    U R                  nU(       d  U$ [        [        UR	                  5       5      5      $ )zAReturn the last run's entries!  If there are none, returns dummy.)r}   r|   r%   sorteditems)r'   dummylEs      r   _getlastEntriesSimpleIndex._getlastEntries  s4    /$--LF288:&''r   c           	        ^ ^^^ T R                  5        VVs/ s H  u  p4[        S U 5       5      U4PM     nnnS nUR                  US9  T R                  =(       a    S=(       d    SmUUUU 4S jnUT R                  l        Sn/ n	/ n
T R                  S5      nU GH  u  p4[        U5      nSR                  S [        R                  " S	US   S   R                  5       5       5       5      nX:w  a  UnT R                  (       a  UnOS
nU	R                  [        SUR                  5      /5        U	R                  [        X5      /5        U	R                  [        SUR                   5      /5        [#        X5      u  pU(       a  Un
X>S  n[%        [        U5      5      nUS   < SU< S3US'   U H|  n['        U5      nT R                  UT-   5      n[        UU5      nUR                  (       a&  U	R                  [        SUR                  5      /5        U	R                  U/5        US-  nM~     GM     [)        U	T/T R*                  S9T l        g s  snnf )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr$   )r	   ).0ts     r   	<genexpr>%SimpleIndex._build.<locals>.<genexpr>  s     ;Uy||Us   c                     U S    Vs/ s H>  nSR                  S [        R                  " SUR                  5       5       5       5      PM@     sn$ s  snf )Nr   r5   c              3   ^   #    U  H#  n[         R                  " U5      S :w  d  M  Uv   M%     g7fMnNunicodedatacategoryr&  r  s     r   r(  5SimpleIndex._build.<locals>.getkey.<locals>.<genexpr>  s)     s(O1S^SgSghiSjnrSrQQ(O   -	-NFD)r8   r/  	normalizeupper)seqr(   s     r   getkey"SimpleIndex._build.<locals>.getkey  se     B  CD  E  F  EyzBGGs(=(=eQWWY(Ost  E  F  F  Fs   AA)r[   r6   r   c                    > T
R                  T	5      n[        [        U5      5       VVs/ s H  u  pEUS   U4PM     nnn[        XUTTT
R                  5        gs  snnf )r   r6   N)r   r  r   r]   rL   )r   r   r   rH   rN   krI   rK   rJ   leveloffsetr'   s          r   drawIndexEntryEnd-SimpleIndex._build.<locals>.drawIndexEntryEnd  sW    &&{3E)/U0C)DE)D#!ad1X)DEEF5*k488T Fs   Ar5   c              3   ^   #    U  H#  n[         R                  " U5      S :w  d  M  Uv   M%     g7fr,  r.  r1  s     r   r(  r)    s)     ~)ZA^i^r^rst^uy}^}aa)Zr3  r4   rf   z(<onDraw name="drawIndexEntryEnd" label="z"/>r   )r"  r   sortr   r   r=  r   r%   r8   r/  r5  r6  r&   r   r   r   
spaceAfterlistdiffr   r   r   rq   r   )r'   rJ   rK   textspageNumbersr   r8  r=  alphar   	lastTexts
alphaStylenalphaheaderidiffr   rV   rH   r   r<  s   ```                 @r   _buildSimpleIndex._build  s3   6:6J6J6LN6L 2 ;U;;KH6L 	 N	Ff%ll(q-A	U 	U
 '8		#		''*
".EKE WW~)>)>ueAhqkFWFWFY)Z~F<<"F F  &J,B,B"C!EF  )F"?!AB  &J,A,A"B!DE y0GA!	b	 k!23EMRSUYX]^E"I "$'**1[=9 u-$$$$fQ0A0A&B%DE  $)Q / #/H yZLXmNs    Ic                     U R                  X5        U R                  R                  U R                  X5      u  U l        U l        U R                  U R
                  4$ )r   )rM  r   r   r   r   r   r   s      r   r   SimpleIndex.wrap  sD    J+"&.."7"7		*"Z
DKzz4;;&&r   c                 <    U R                   R                  XX45        gr   )r   r   r   s        r   r   SimpleIndex.drawOn  s    
 	f0r   c                     U R                   n[        USS 5      nU(       d  U R                  Ul         UR                  5         U(       d  U?g g ! U(       d  U?f f = f)Nr   )r   r   r   draw)r'   r'  ocanvs      r   rT  SimpleIndex.draw  sP    NN&&YYAF	FFHF 5F s   A Ac                    [        U R                  S5      (       d  U R                  /U l         U R                  U   $ ! [         a    [        U R                  5      U l        U R	                  US-
  5      nU R                  R                  [        SUR                  U4-  UUR                  S[        -  -   UR                  S[        -  -   S95        U R                  U   s $ f = f)r   __iter__r6   r   g?r   )hasattrr   r   r%   r   r&   r   r`   ra   r   rb   r   s      r   r   SimpleIndex.getLevelStyle  s    t~~z22"nn-DN
	%>>!$$ 	%!$..1DN**1Q3/INN!!.)Y^^Q,??$&/&?&?2&E!*!5!5be!;	#= >
 >>!$$	%s   > B#C$#C$)r|   r   r}   rx   rL   r   r   r   r`   r   rq   r   r   )NNNTN123r   r$   r   )r,   r-   r.   r/   r   r   r   r   r   r   Canvasr
  r   r   r   r   r   r   r   	enumerater"  rM  r   r   rT  r   r0   r+   r   r   r   r   &  s    
I!F-. *0 4
FNI (?&?	)@T%U$V (7Yr'1	%r   r   c                     [        [        U 5      [        U5      5      n[        U5       H  nX   X   :w  d  M  X1US  4s  $    X!US  4$ r$   )minr   range)l1l2mrK  s       r   rC  rC    sM    CGSWA1X5BE>f9  f9r   c                   :    \ rS rSrSrS rS rS rS rS
S jr	Sr
g	)ReferenceTexti  zRFakery to illustrate how a reference would work if we could
put it in a paragraph.c                 f    Xl         X l        [        S5      U l        S U l        SU l        S U l        g )Ntmpi)textPatterntargetr   	paraStyle_lastPageNum_pageNum_para)r'   rh  	targetKeys      r   r   ReferenceText.__init__  s/    &'. 
r   c                 &    U R                   U l        g r$   )rl  rk  r   s    r   r   ReferenceText.beforeBuild   s     MMr   c                 F    US:X  a  Uu  p4X0R                   :X  a  X@l        g g g )NTarget)ri  rl  )r'   r   r   r[   r   s        r   r   ReferenceText.notify#  s*    8"NSkk! ' " r   c                     U R                   U R                  -  n[        X0R                  5      U l        U R                  R                  X5      $ r$   )rh  rk  r   rj  rm  r   )r'   rJ   rK   rV   s       r   r   ReferenceText.wrap)  s;    $"3"33t^^4
zzz77r   c                 <    U R                   R                  XX45        g r$   )rm  r   r   s        r   r   ReferenceText.drawOn.  s    

&Q,r   )rk  rl  rm  rj  ri  rh  Nr   )r,   r-   r.   r/   r   r   r   r   r   r   r0   r+   r   r   re  re    s     *(8
-r   re  )r   N)0__version__r   reportlab.lib.unitsr   reportlab.lib.utilsr   r   r   r   r   r	   r
   reportlab.lib.stylesr   r   reportlab.libr   r   reportlab.platypus.paragraphr   reportlab.platypus.doctemplater   reportlab.platypus.tablesr   r   reportlab.platypus.flowablesr   reportlab.pdfbase.pdfmetricsr   r  r   r/  astr   r   r!   r%   r]   r   epsilonrv   rw   rk   r   r   AlphabeticIndexrC  re  r+   r   r   <module>r     s   
 '	R # q q q > 3 2 ; 7 / 4 #  9$4v 	
"
b&      I.& I.V
d%" d%L -$ -g$$d $s   B0 0B?