
    OAiH?                       S r SSKJr  SSK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JrJrJrJr   " S	 S
\5      r\R*                  S\R,                  S\R.                  S\R0                  S\R2                  S\R4                  S0r\" \R:                  " \R=                  5       5      5      r SSSSSSS.                 SS jjjr  S       SS jjr! " S S\"5      r# " S S5      r$ " S S5      r%g)z7Support for document outlines (e.g. table of contents).    )annotations)Iterable)Enum)chain)cast)PagePdf)Array
DictionaryNameObjectStringc                  8    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrg)PageLocation   z.Page view location definitions, from PDF spec.                         N)__name__
__module____qualname____firstlineno____doc__XYZFitFitHFitVFitRFitBFitBHFitBV__static_attributes__r       S/var/www/html/land-ocr/venv/lib/python3.13/site-packages/pikepdf/models/outlines.pyr   r      s-    8
C
CDDDDEEr)   r   )lefttopzoom)r,   )r+   )r+   bottomrightr,   Nr+   r,   r/   r.   r-   c               "    [        U UUUUUUUS9$ )aE  Create a destination ``Array`` with reference to a Pdf document's page number.

Arguments:
    pdf: PDF document object.
    page_num: Page number (zero-based).
    page_location: Optional page location, as a string or :enum:`PageLocation`.
    left: Specify page viewport rectangle.
    top: Specify page viewport rectangle.
    right: Specify page viewport rectangle.
    bottom: Specify page viewport rectangle.
    zoom: Specify page viewport rectangle's zoom level.

left, top, right, bottom, zoom are used in conjunction with the page fit style
specified by *page_location*.
)page_locationr+   r,   r/   r.   r-   )_make_page_destination)pdfpage_numr2   r+   r,   r/   r.   r-   s           r*   make_page_destinationr6   *   s)    4 "#	 	r)   c                >  ^ TR                  5        VVs0 s H  u  pEUc  M
  XE_M     snnmU R                  U   R                  /nU(       a  [        U[        5      (       a  UnUR
                  nOUn [        U   nUR                  [        SU 35      5        [        R                  U5      n	U	(       a  UR                  U4S jU	 5       5        OUR                  [        R                  5        [        U5      $ s  snnf ! [         a    [        SU 35      S ef = f)Nz*Invalid or unsupported page location type /c              3  H   >#    U  H  nTR                  US 5      v   M     g7f)r   N)get).0kkwargss     r*   	<genexpr>)_make_page_destination.<locals>.<genexpr>h   s     @Avzz!Q''s   ")itemspagesobj
isinstancer   nameKeyError
ValueErrorappendr   PAGE_LOCATION_ARGSr:   extendr!   r
   )
r4   r5   r2   r=   r<   vresloc_keyloc_strdest_arg_namess
      `      r*   r3   r3   P   s      &||~?~tqdad~?F$'IIh$7$;$;#<Cm\22#GllG#G&w/
 	

4!G9&'+//8JJ@@@

488:+ @   @	Js   	C<C<4	D Dc                      \ rS rSrSrSrg)OutlineStructureErrorn   z1Indicates an error in the outline data structure.r   N)r   r   r   r   r   r(   r   r)   r*   rP   rP   n   s    ;r)   rP   c                      \ rS rSrSr    SSSSSSS.                   SS jjjrS rS r\SS j5       r	SSS	 jjr
S
rg)OutlineItemr   a=  Manage a single item in a PDF document outlines structure.

Includes nested items.

Arguments:
    title: Title of the outlines item.
    destination: Page number, destination name, or any other PDF object
        to be used as a reference when clicking on the outlines entry. Note
        this should be ``None`` if an action is used instead. If set to a
        page number, it will be resolved to a reference at the time of
        writing the outlines back to the document.
    page_location: Supplemental page location for a page number
        in ``destination``, e.g. ``PageLocation.Fit``. May also be
        a simple string such as ``'FitH'``.
    action: Action to perform when clicking on this item. Will be ignored
       during writing if ``destination`` is also set.
    obj: ``Dictionary`` object representing this outlines item in a ``Pdf``.
        May be ``None`` for creating a new object. If present, an existing
        object is modified in-place during writing and original attributes
        are retained.
    left, top, bottom, right, zoom: Describes the viewport position associated
        with a destination.

This object does not contain any information about higher-level or
neighboring elements.

Valid destination arrays:
    [page /XYZ left top zoom]
    generally
    [page, PageLocationEntry, 0 to 4 ints]
Nr0   c               4   Xl         X l        X0l        0 U l        X@l        U R                  b  U R                  b  [        S5      eXPl        [        XgXU
S9nUR                  5        VVs0 s H  u  pUc  M
  X_M     snnU l        SU l	        / U l
        gs  snnf )zInitialize OutlineItem.Nz-Only one of destination and action may be setr0   F)titledestinationr2   page_location_kwargsactionrF   rB   dictr@   	is_closedchildren)selfrV   rW   r2   rY   rB   r+   r,   r/   r.   r-   r=   r<   rJ   s                 r*   __init__OutlineItem.__init__   s     
&*$&!'DKK,CLMM44P6<lln$VndaTQTn$V!+- %Ws   )	B6Bc                H   U R                   (       a  U R                  (       a  SnOSnOSnU R                  b  [        U R                  [        5      (       a'  U R                  S   n[        U5      nUR                  nO[        U R                  [        5      (       a  SU R                   S3nOb[        U R                  [        5      (       a  SU R                   S3nO2[        U R                  [        5      (       a  SU R                   S3nOS	nU S
U R                   SW 3$ )Nz[+]z[-]z[ ]r   z7<Named Destination in document .Root.Names dictionary: >z7<Named Destination in document .Root.Dests dictionary: z<Page z<Action> z -> )r\   r[   rW   rC   r
   r   labelr   r   intrV   )r]   oc_indicatorraw_pagepagedests        r*   __str__OutlineItem.__str__   s   ==~~$$ L'$**E22  ++A.H~zzD,,f55 N''(+  D,,d33 N''(+  D,,c22 0 013DqD77r)   c                P    SU R                   R                   SU R                   S3$ )N	<pikepdf.z: "z">)	__class__r   rV   r]   s    r*   __repr__OutlineItem.__repr__   s&    4>>2233tzzl"EEr)   c                n   [        UR                  5      nUR                  [        R                  5      nUb2  [        U[        [        -  [        -  5      (       d  [        SU< 35      eUR                  [        R                  5      nUb$  [        U[        5      (       d  [        SU< 35      eU " X#XAS9$ )zCreate a ``OutlineItem`` from a ``Dictionary``.

Does not process nested items.

Arguments:
    obj: ``Dictionary`` object representing a single outline node.
z+Unexpected object type in Outline's /Dest: z(Unexpected object type in Outline's /A: )rW   rY   rB   )strTitler:   r   DestrC   r
   r   rP   Ar   )clsrB   rV   rW   rY   s        r*   from_dictionary_object"OutlineItem.from_dictionary_object   s     CIIggdii(":$.,
 ,
 (=k_M  j&D&D':6*E  5&JJr)   c                   U(       d  U R                   c!  UR                  [        5       5      =U l         nOU R                   nU R                  Ul        U R
                  by  [        U R
                  [        5      (       a1  [        UU R
                  U R                  40 U R                  D6U l        U R
                  Ul        [        R                  U;   a  U?U$ U R                  b'  U R                  Ul        [        R                  U;   a  U?U$ )a$  Create/update a ``Dictionary`` object from this outline node.

Page numbers are resolved to a page reference on the input
``Pdf`` object.

Arguments:
    pdf: PDF document object.
    create_new: If set to ``True``, creates a new object instead of
        modifying an existing one in-place.
)rB   make_indirectr   rV   rs   rW   rC   rd   r6   r2   rX   rt   r   ru   rY   )r]   r4   
create_newrB   s       r*   to_dictionary_object OutlineItem.to_dictionary_object   s     ) ..z|<<DHs((CJJ	'$**C00#8$$&&$ //	$  ''CHvv}E
 
	 [[$KKCEyyCH
r)   )rY   r\   rW   r[   rB   r2   rX   rV   )NNNN)rV   rr   rW   z"Array | String | Name | int | Noner2   PageLocation | str | NonerY   Dictionary | NonerB   r   r+   float | Noner,   r   r/   r   r.   r   r-   r   )rB   r   )F)r4   r	   r{   boolreturnr   )r   r   r   r   r   r^   ri   ro   classmethodrw   r|   r(   r   r)   r*   rS   rS   r   s    F ;?37$(!%. " "#!.. 8. 1	.
 ". . . . . . .8 8DF K K0 r)   rS   c                      \ rS rSrSrSSS jjrS rS rS rS r	S r
        SS	 jr        SS
 jrS rS rSS jr\SS j5       r\R$                  SS j5       rSrg)Outlinei  a  Maintains a intuitive interface for creating and editing PDF document outlines.

See {{ pdfrm }} section 12.3.

Arguments:
    pdf: PDF document object.
    max_depth: Maximum recursion depth to consider when reading the outline.
    strict: If set to ``False`` (default) silently ignores structural errors.
        Setting it to ``True`` raises a
        :class:`pikepdf.OutlineStructureError`
        if any object references re-occur while the outline is being read or
        written.

See Also:
    :meth:`pikepdf.Pdf.open_outline`
c                D    SU l         Xl        X l        X0l        SU l        g)zInitialize Outline.NF)_root_pdf
_max_depth_strict	_updating)r]   r4   	max_depthstricts       r*   r^   Outline.__init__!  s    /3
	#r)   c                ,    [        U R                  5      $ N)rr   rootrn   s    r*   ri   Outline.__str__)  s    499~r)   c                b    SU R                   R                   S[        U R                  5       S3$ )Nrl   z: z items>)rm   r   lenr   rn   s    r*   ro   Outline.__repr__,  s+    4>>2232c$))n5EWMMr)   c                    U(       a  UR                  S5        g UR                  SSS5         [        U R                  5       H/  u  p4UR	                  5         UR                  [        U5      5        M1     S S S 5        g ! , (       d  f       g = f)Nz...r   z!pikepdf.models.outlines.Outline<
z
>)textgroup	enumerater   	breakableprettyrr   )r]   pcycle_items        r*   _repr_pretty_Outline._repr_pretty_/  s\    FF5M@%H(3GAKKMHHSY'  4 IHHs   A	A??
Bc                    SU l         U $ )NT)r   rn   s    r*   	__enter__Outline.__enter__8  s    r)   c                d     Ub	   SU l         g U R                  5         SU l         g ! SU l         f = f)NF)r   _save)r]   exc_typeexc_valexc_tbs       r*   __exit__Outline.__exit__<  s3    	## #DN JJL"DNUDNs   & & 	/c                R   SnS nS nU GH6  nUR                  U R                  5      n	U	R                  n
X;   a;  U R                  (       a  [	        SU
 S35      eUR                  U R                  SS9n	OUR                  U
5        Xl        US-  nUb  Xl        Xil        OU	n[        R                  U	;   a  U	?U	nX0R                  :  a  UR                  nOSnU R                  XUS-   U5        UR                  (       a#  [        [        U	R                   5      * U	l        GM  U[        [        U	R                   5      -  nGM9     U(       a+  Ub  Uc   e[        R                  U;   a  U?Xql        Xal        O,[        R"                  U;   a  U?[        R$                  U;   a  U?XQl        g )Nr   Outline object  reoccurred in structureT)r{   r   r   )r|   r   objgenr   rP   addParentNextPrevr   r   r\   _save_level_outliner[   r   rd   CountFirstLast)r]   parentoutline_itemslevelvisited_objscountprevfirstr   out_objr   	sub_itemss               r*   r   Outline._save_level_outlineD  sz    "&#'!D//		:G^^F%<</)&1IJ  33DII$3O  (#NQJE#	#99'D&37==		$$WLQ~~!%c7==!9 9c7==11= "> #(999yyD I LKzzV#LyyF"Kr)   c                   UnU(       Gaa  UR                   nXd;   a!  U R                  (       a  [        SU S35      eg UR                  U5        [        R                  U5      nUR                  [        R                  5      n[        U[        5      (       ap  X0R                  :  aa  U R                  XR                  US-   U5        UR                  [        R                  5      n	[        U	[        5      (       a  U	S:  a  SUl        UR#                  U5        UR                  [        R$                  5      n
U
b  [        U
[        5      (       a  U
nO[        SU S35      eU(       a  GM`  g g )Nr   r   r   r   Tz points to non-dictionary)r   r   rP   r   rS   rw   r:   r   r   rC   r   r   _load_level_outliner\   r   rd   r[   rG   r   )r]   	first_objr   r   r   current_objr   r   first_childr   next_objs              r*   r   Outline._load_level_outlinez  s,    *3 ''F%<</)&1IJ  V$55kBD%//$**5K+z22u7N((	< $

3eS))eai%)DN  &"tyy1H:h
#C#C&+%fX-FG 1 kr)   c                   U R                   c  g [        R                  U R                  R                  ;   a!  U R                  R                  R                  nOKU R                  R                  [        [        R                  S95      =U R                  R                  l        nU R                  XR                   S[        5       5        g )N)Typer   )	r   r   Outlinesr   Rootrz   r   r   set)r]   outliness     r*   r   Outline._save  s    ::==DIINN*yy~~..H151H1H.2 DIINN#h 	  ::q#%@r)   c                >   / =U l         n[        R                  U R                  R                  ;  a  g U R                  R                  R                  =(       d    0 nUR                  [        R                  5      nU(       a  U R                  X1S[        5       5        g g )Nr   )	r   r   r   r   r   r:   r   r   r   )r]   r   r   r   s       r*   _loadOutline._load  sk    
T==		.99>>**0bLL,	$$Ya? r)   c                    U R                   c  U R                  5         [        X5      nU R                   c	  U/U l         OU R                   R                  U5        U R                  (       d  U R                  5         U$ )zAdd an item to the outline.

Arguments:
    title: Title of the outline item.
    destination: Destination to jump to when the item is selected.

Returns:
    The newly created :class:`OutlineItem`.
)r   r   rS   rG   r   r   )r]   rV   rW   r   s       r*   r   Outline.add  s[     ::JJL5.::DJJJd#~~JJLr)   c                ~    U R                   c  U R                  5         [        [        [           U R                   5      $ )z$Return the root node of the outline.)r   r   r   listrS   rn   s    r*   r   Outline.root  s-     ::JJLD%tzz22r)   c                    [        U[        5      (       d  [        S5      eU H#  n[        U[        5      (       a  M  [        S5      e   Xl        g)z!Set the root node of the outline.z+Root must be a list of OutlineItem objects.z)Each item in root must be an OutlineItem.N)rC   r   rF   rS   r   )r]   new_rootr   s      r*   r   r     sG     (D))JKKDdK00 !LMM  
r)   )r   r   r   r   r   N)   F)r4   r	   r   rd   r   r   )r   r   r   zIterable[OutlineItem]r   rd   r   set[tuple[int, int]])r   r   r   zlist[Object]r   rd   r   r   )rV   rr   rW   zArray | int | Noner   rS   )r   list[OutlineItem])r   r   )r   r   r   r   r   r^   ri   ro   r   r   r   r   r   r   r   r   propertyr   setterr(   r   r)   r*   r   r     s    "N(#44 -4 	4
 +4l"" $" 	"
 +"H	A@* 3 3 
[[ r)   r   r   )r4   r	   r5   rd   r2   r~   r+   r   r,   r   r/   r   r.   r   r-   r   r   r
   )r4   r	   r5   rd   r2   r~   r   r
   )&r   
__future__r   collections.abcr   enumr   	itertoolsr   typingr   pikepdf._corer   r	   pikepdf.objectsr
   r   r   r   r   r   r    r"   r#   r$   r&   r'   rH   r   from_iterablevaluesALL_PAGE_LOCATION_KWARGSr6   r3   	ExceptionrP   rS   r   r   r)   r*   <module>r      sh  
 > " $    # C C
4 
 -xy9	  u223E3L3L3NOP  04#
 #	## -#
 # 
# # # # #R 04	 -
 <<I <Z ZzH Hr)   