o
    e                     @   s  d Z dZddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZmZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ 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$ ddl%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddlm1Z1m2Z2 e3e4Z5dZ6e7dZ8G dd de9e0Z:G dd de;e0Z<G dd de<Z=deddfddZ>G dd de<Z?G d d! d!e?Z@G d"d# d#e?ZAG d$d% d%e@ZB	d/d&ed'ed(edeCe
eC eeDeCf f dee0eDeCeBf fd)d*ZEG d+d, d,e=ZFG d-d. d.e=ZGdS )0zMathieu Fenniakzbiziqe@mathieu.fenniak.net    N)BytesIO)AnyDictIterableListOptionalTupleUnioncast   )	WHITESPACES
StreamTypeb_deprecate_with_replacementhex_strlogger_warningread_non_whitespaceread_until_regexskip_over_comment)CheckboxRadioButtonAttributesFieldDictionaryAttributes)FilterTypes)OutlineFontFlag)StreamAttributes)TypArguments)TypFitArguments)STREAM_TRUNCATED_PREMATURELYPdfReadErrorPdfStreamError   )BooleanObjectFloatObjectIndirectObject
NameObject
NullObjectNumberObject	PdfObject)read_hex_string_from_streamread_string_from_streams   +-s   [+-]?(\d+)\s+(\d+)\s+R[^a-zA-Z]c                   @   s   e Zd Zdee fddZdededee	f ddfddZ
dededee	f ddfd	d
Ze	ddedededeee eeef f dd fddZedededd fddZdS )ArrayObjectreturnc                 C   s   t | S )zS
        Emulate DictionaryObject.items for a list
        (index, object)
        )	enumerateself r.   OD:\Projects\ConvertPro\env\Lib\site-packages\PyPDF2/generic/_data_structures.pyitemsK   s   zArrayObject.itemsstreamencryption_keyNc                 C   s8   | d | D ]}| d ||| q| d d S )N   [    s    ])writewrite_to_stream)r-   r1   r2   datar.   r.   r/   r6   R   s
   

zArrayObject.write_to_streamc                 C      t dd | || d S NwriteToStreamr6   r   r6   r-   r1   r2   r.   r.   r/   r:   [      
zArrayObject.writeToStreampdfforced_encodingc                 C   s   t  }| d}|dkrtd	 | d}| r#| d}| s| dd | d}|dkr5	 |S | dd |t| || q)Nr   r3   zCould not read arrayT   ])r)   readr   isspaceseekappendread_object)r1   r>   r?   ZarrtmptokZ	peekaheadr.   r.   r/   read_from_streama   s"   



zArrayObject.read_from_streamc                 C      t dd t| |S NreadFromStreamrI   )r   r)   rI   r1   r>   r.   r.   r/   rL   z      
zArrayObject.readFromStreamN)__name__
__module____qualname__r   r   r0   r   r	   strbytesr6   r:   staticmethodr   r   intrI   rL   r.   r.   r.   r/   r)   J   sF    
	
r)   c                   @   s4  e Zd ZdedefddZdededefddZddedee defd	d
ZdedefddZ	e
dee fddZdee fddZe
dee fddZdededeef ddfddZdededeef ddfddZe	ddedededeee eeef f dd fddZedededd fddZdS ) DictionaryObjectkeyr*   c                 C   s   t | |S rO   )dict__getitem__r-   rX   r.   r.   r/   raw_get   s   zDictionaryObject.raw_getvaluec                 C   2   t |ts	tdt |tstdt| ||S Nzkey must be PdfObjectzvalue must be PdfObject)
isinstancer&   
ValueErrorrY   __setitem__r-   rX   r]   r.   r.   r/   rb      
   

zDictionaryObject.__setitem__Nc                 C   r^   r_   )r`   r&   ra   rY   
setdefaultrc   r.   r.   r/   re      rd   zDictionaryObject.setdefaultc                 C   s   t | | S rO   )rY   rZ   
get_objectr[   r.   r.   r/   rZ      s   zDictionaryObject.__getitem__c                 C   sN   ddl m} | dd}|du rdS | }t||s%||}|| td< |S )a  
        Retrieve XMP (Extensible Metadata Platform) data relevant to the
        this object, if available.

        Stability: Added in v1.12, will exist for all future v1.x releases.
        @return Returns a {@link #xmp.XmpInformation XmlInformation} instance
        that can be used to access XMP metadata from the document.  Can also
        return None if no metadata was found on the document root.
        r   )XmpInformationz	/MetadataN)Zxmprg   getrf   r`   r#   )r-   rg   metadatar.   r.   r/   xmp_metadata   s   
zDictionaryObject.xmp_metadatac                 C      t dd | jS )W
        .. deprecated:: 1.28.3

            Use :meth:`xmp_metadata` instead.
        getXmpMetadatarj   r   rj   r,   r.   r.   r/   rm      s   
zDictionaryObject.getXmpMetadatac                 C   rk   )rl   xmpMetadatarj   rn   r,   r.   r.   r/   ro         
zDictionaryObject.xmpMetadatar1   r2   c                 C   sZ   | d t|  D ]\}}||| | d ||| | d q| d d S )N   <<
r4      
   >>)r5   listr0   r6   )r-   r1   r2   rX   r]   r.   r.   r/   r6      s   

z DictionaryObject.write_to_streamc                 C   r8   r9   r;   r<   r.   r.   r/   r:      r=   zDictionaryObject.writeToStreamr>   r?   c              
      s~  dt dt dtt  dtdt f
 fdd dtdtdtf fd	d
}| d}|dkr5tdt|   di }	 t	| }|dkrAq7|dkrP| 
dd t|  q7|sVtt|dkr`| d nu| 
dd zt| |}t	| }| 
dd t| ||}W n0 ty }	 z$|d ur|jrt|	 t|	 t t }
|
| |
W  Y d }	~	S d }	~	ww ||s|||< ndt|   d| }|d ur|jrt|t|t q8|  }t	| }|dkr| ddkr| d}|dkr| d}|dks|dvrtd|dkr| ddkr| 
dd tj|vr"td|tj }t|tr<|  }||}| 
|d  |  }| ||d!< t	| }| d"}|| d#kr|  }| 
d$d | d%}|d#krv|d! d d |d!< n5|js| 
|d  || ||d!< |  }n| 
|d  td&t|   d'|d(|d)n| 
|d  d!|v rt|S t }
|
| |
S )*Npp1rem_gensr>   r*   c                    s^   |j |d  }|D ]}||| kr| || k r|| }q	t|dkr$|S  | ||dd  |S )Nr   r   )xreflen)ru   rv   rw   r>   loget_next_obj_posr.   r/   r}      s   z;DictionaryObject.read_from_stream.<locals>.get_next_obj_posr1   c                    sz    |   dt|j|d }|   }| ||    }|d}|dk r,td| d| || d  |d |d  S )Nl        r   	   endstreamr   z6Unable to find 'endstream' marker for obj starting at .	   )tellrt   rx   rB   findr   rD   )r1   r>   Zeoncurrrwru   r|   r.   r/   read_unsized_from_steam   s   

zBDictionaryObject.read_from_stream.<locals>.read_unsized_from_steamr      <<zDictionary read error at byte z: stream must begin with '<<'T       %r@   r      >z+Multiple definitions in dictionary at byte z	 for key    s   s   treamr4   )rr      z)Stream data must be followed by a newliner   rr   zStream length not definedr   __streamdata__   r~   ir   z7Unable to find 'endstream' marker after stream at byte z (nd='z', end='z').)rV   r   r   r   rT   rB   r   r   r   r   rD   r   r   r   rF   	Exceptionstrict__repr__r   rP   rW   updaterh   SALENGTHr`   r"   rf   StreamObjectinitialize_from_dictionary)r1   r>   r?   r   rG   r7   rH   rX   r]   excretvalmsgposseollengthtZpstarteZndstreamendr.   r|   r/   rI      s   







(













z!DictionaryObject.read_from_streamc                 C   rJ   rK   )r   rW   rI   rM   r.   r.   r/   rL   \  rN   zDictionaryObject.readFromStreamrO   )rP   rQ   rR   r   r\   rb   r   re   r&   rZ   propertyrj   rm   ro   r   r	   rS   rT   r6   r:   rU   r   r   rV   rI   rL   r.   r.   r.   r/   rW      s\    
	

 rW   c                
   @   s   e Zd Zd!ddZdefddZdefddZdefd	d
Zde	e fddZ
dededdfddZdededdfddZdeddfddZdededededdf
ddZdeddfddZd!ddZd!dd ZdS )"
TreeObjectr*   Nc                 C   s   t |  d S rO   )rW   __init__r,   r.   r.   r/   r   e  s   zTreeObject.__init__c                 C   s   t ddd |  S )NhasChildrenhas_children4.0.0)r   r   r,   r.   r.   r/   r   h  s   zTreeObject.hasChildrenc                 C   s   d| v S )N/Firstr.   r,   r.   r.   r/   r   l     zTreeObject.has_childrenc                 C   s   |   S rO   )childrenr,   r.   r.   r/   __iter__o  r   zTreeObject.__iter__c                 c   sb    |   sd S | td }| }	 |V  || td krd S |td}|d u r,d S | }q)Nr   T/Last/Next)r   r#   rf   rh   )r-   Z	child_refchildr.   r.   r/   r   r  s   zTreeObject.childrenr   r>   c                 C   r8   )NaddChild	add_child)r   r   )r-   r   r>   r.   r.   r/   r     s   
zTreeObject.addChildc                 C   s   |  }||}t|tsJ d| vr%|| td< td| td< d }ntt| d }|| td< t| td d | td< |rZ||}t|tsNJ ||td< ||td< || }t|tsfJ ||td< d S )	Nr   r   /Countr   r   /Prevr   /Parent)rf   Zget_referencer`   r"   r#   r%   r
   rW   )r-   r   r>   	child_objprevprev_refZ
parent_refr.   r.   r/   r     s(   


zTreeObject.add_childc                 C      t dd | | d S )NremoveChildremove_child)r   r   )r-   r   r.   r.   r/   r        
zTreeObject.removeChildr   r   curlastc                 C   s  | tdd}|du rP|r-| }|td= || td< t| td d | td< dS | td dks7J | td= | td= td| v rN| td= dS dS |rc| }||td< ||td< n||ksiJ |td= || td< t| td d | td< dS )z;Adjust the pointers of the linked list and tree node count.r   Nr   r   r   r   r   )rh   r#   rf   r%   )r-   r   r   r   r   Znext_refZnext_objr.   r.   r/   _remove_node_from_tree  s.   



 z!TreeObject._remove_node_from_treec           
      C   s   |  }td|vrtd|td | krtdd}d }d }| td }|  }| td }|  }	|d urd||krG| ||||	 d}n|}|}td|v r\|td }|  }nd }d }|d us8|sjtd	t| d S )
Nr   z/Removed child does not appear to be a tree itemz*Removed child is not a member of this treeFr   r   Tr   z"Removal couldn't find item in tree)rf   r#   ra   r   _reset_node_tree_relationship)
r-   r   r   foundr   r   Zcur_refr   Zlast_refr   r.   r.   r/   r     s8   
zTreeObject.remove_childc                 C   s   t ddd |   d S )N	emptyTree
empty_treer   )r   r   r,   r.   r.   r/   r     s   zTreeObject.emptyTreec                 C   sd   | D ]
}|  }t| qtd| v r| td= td| v r#| td= td| v r0| td= d S d S )Nr   r   r   )rf   r   r#   )r-   r   r   r.   r.   r/   r     s   


zTreeObject.empty_treer*   N)rP   rQ   rR   r   boolr   r   r   r   r   r   r   r   r   r   r   r   r   r.   r.   r.   r/   r   d  s.    

#
$r   r   r*   c                 C   s>   | t d= t d| v r| t d= t d| v r| t d= dS dS )z}
    Call this after a node has been removed from a tree.

    This resets the nodes attributes in respect to that tree.
    r   r   r   N)r#   )r   r.   r.   r/   r     s   

r   c                       s   e Zd ZdddZdef fddZeded fdd	Zej	ddd	Zede
fddZej	d
e
ddfddZdededeef ddfddZedeee
f ded fddZedeee
f ded fddZd ddZd ddZ  ZS )!r   r*   Nc                 C   s   d | _ d | _d S rO   )_StreamObject__datadecoded_selfr,   r.   r.   r/   r     s   
zStreamObject.__init__c                    s   t   }|t| j7 }|S rO   )superhash_value_datar   _datar-   r7   	__class__r.   r/   r     s   
zStreamObject.hash_value_dataDecodedStreamObjectc                 C   rk   NdecodedSelfr   r   r   r,   r.   r.   r/   r        
zStreamObject.decodedSelfr]   c                 C      t dd || _d S r   r   r-   r]   r.   r.   r/   r        

c                 C      | j S rO   r   r,   r.   r.   r/   r     s   zStreamObject._datac                 C   
   || _ d S rO   r   r   r.   r.   r/   r   "  s   
r1   r2   c                 C   sp   t t| j| ttj< t| || | tj= |d | j}|r,ddl	m
} |||}|| |d d S )Ns   
stream
r   )RC4_encrypts
   
endstream)r%   ry   r   r#   r   r   rW   r6   r5   Z	_securityr   )r-   r1   r2   r7   r   r.   r.   r/   r6   &  s   


zStreamObject.write_to_streamr7   )EncodedStreamObjectr   c                 C   s
   t | S rO   )r   r   )r7   r.   r.   r/   initializeFromDictionary5  s   
z%StreamObject.initializeFromDictionaryc                 C   s>   t j| v r	t }nt }| d |_| d= | t j= ||  |S )Nr   )r   FILTERr   r   r   r   r   )r7   r   r.   r.   r/   r   ;  s   


z'StreamObject.initialize_from_dictionaryr   c                 C      t dd |  S )NflateEncodeflate_encode)r   r   r,   r.   r.   r/   r   J     
zStreamObject.flateEncodec                 C   s   ddl m} tj| v r1| tj }t|tr|dttj	 nt }|
td |
| |}ntd}t }||ttj< || j|_|S )Nr   )FlateDecoder   z/FlateDecode)filtersr   r   r   r`   r)   insertr#   FTZFLATE_DECODErE   r   encoder   )r-   r   fZnewfr   r.   r.   r/   r   N  s   



zStreamObject.flate_encoder   )r]   r   r*   N)r*   r   )rP   rQ   rR   r   rT   r   r   r   r   setterr   r   r   r	   rS   r6   rU   r   r   r   r   r   __classcell__r.   r.   r   r/   r   
  s@    




r   c                   @   sL   e Zd ZdefddZdedefddZdefddZdedd	fd
dZd	S )r   r*   c                 C   r   rO   r   r,   r.   r.   r/   get_datac  s   zDecodedStreamObject.get_datar7   c                 C   r   rO   r   r   r.   r.   r/   set_dataf     
zDecodedStreamObject.set_datac                 C   rk   NgetDatar   )r   r   r,   r.   r.   r/   r   i  s   
zDecodedStreamObject.getDataNc                 C   r   NsetDatar   r   r   r   r.   r.   r/   r   m  r   zDecodedStreamObject.setData)rP   rQ   rR   r   r   r   r   r   r.   r.   r.   r/   r   b  s
    r   c                   @   s   e Zd ZdddZeded fddZejdeddfd	dZde	de
ef fd
dZde	de
ef fddZdeddfddZdeddfddZdS )r   r*   Nc                 C   s
   d | _ d S rO   )r   r,   r.   r.   r/   r   s  r   zEncodedStreamObject.__init__r   c                 C   rk   r   r   r,   r.   r.   r/   r   v  r   zEncodedStreamObject.decodedSelfr]   c                 C   r   r   r   r   r.   r.   r/   r   {  r   c                 C   sn   ddl m} | jd ur| j S t }|| |_t|  D ]\}}|tj	tj
tjfvr0|||< q|| _|jS )Nr   )decode_stream_data)r   r   r   r   r   r   rt   r0   r   r   r   ZDECODE_PARMS)r-   r   decodedrX   r]   r.   r.   r/   r     s   


zEncodedStreamObject.get_datac                 C   r   r   )r   r   r,   r.   r.   r/   r     r   zEncodedStreamObject.getDatar7   c                 C   s   t d)Nz7Creating EncodedStreamObject is not currently supported)r   r   r.   r.   r/   r     r   zEncodedStreamObject.set_datac                 C   s   t dd | |S r   r   r   r.   r.   r/   r     s   

zEncodedStreamObject.setDatar   )rP   rQ   rR   r   r   r   r   r   r   r	   rS   rT   r   r   r   r   r   r.   r.   r.   r/   r   r  s    
r   c                   @   s   e Zd Z	ddedededeee eeef f ddfddZ	de
ddfdd	Zde
deeef fd
dZedefddZejdeeef ddfddZdS )ContentStreamNr1   r>   r?   r*   c           	      C   s   || _ g | _| }t|tr5d}|D ]}|t|  7 }t|dks+|d dkr/|d7 }qt|}n| }|d us?J t|}t|}|| _	| 
| d S )N    r   r@   rr   )r>   
operationsrf   r`   r)   r   r   ry   r   r?   $_ContentStream__parse_content_stream)	r-   r1   r>   r?   r7   r   Zstream_bytesZstream_dataZstream_data_bytesr.   r.   r/   r     s"   

zContentStream.__init__c                 C   s   | dd g }	 t|}|dks|dkrd S | dd | s%|dv rOt|tjd}|dkrD|g ks6J | |}| j|df n'| j||f g }n|d	kra|d
vr`|	d}|d
vsWn
|t
|d | j q	)Nr   Tr   r@   r   )   '   "   BI   INLINE IMAGEr   r   rr   )rD   r   isalphar   r#   Zdelimiter_pattern_read_inline_imager   rE   rB   rF   r?   )r-   r1   operandspeekoperatoriir.   r.   r/   Z__parse_content_stream  s,   

z$ContentStream.__parse_content_streamc                 C   s  t  }	 t|}|dd |dkrnt|| j}t|}|dd t|| j}|||< q|d}|d d dks=J t }	 |d}|sLtd	|d
}	|	dkr[|	| ni|	|d|	  ||	t
| d |d}|d}
|
dkr||	d |	 tv r|d}||
 }d}|tv rd}||7 }|d}|tv s|r|dd n|dd |	| n|dd |	| qA|| dS )NTr@   r      I   r   s   IDi    zUnexpected end of stream   Er   F)settingsr7   )rW   r   rD   rF   r>   rB   r   r   r   r5   ry   r   getvalue)r-   r1   r  rH   rX   r]   rG   r7   buflocZtok2Ztok3infoZhas_q_whitespacer.   r.   r/   r     sX   







&z ContentStream._read_inline_imagec                 C   s   t  }| jD ]Q\}}|dkr;|d t  }|d |d  || dd  |d ||d  |d n|D ]}||d  |d	 q=|t| |d
 q| S )Nr   r   r  r   s   ID r7   s   EIr4   rr   )r   r   r5   r6   r  r   )r-   newdatar   r   Zdicttextopr.   r.   r/   r     s    

zContentStream._datar]   c                 C   s   |  tt| d S rO   )r   r   r   r   r.   r.   r/   r   +  s   rO   )rP   rQ   rR   r   r	   rS   r   r   rV   r   r   r   r   r   rT   r   r   r.   r.   r.   r/   r     s"    
< r   r1   r>   r?   c                 C   sr  |  d}| dd |dkrt| |S |dkr4|  d}| dd |dkr/t| ||S t| |S |dkr?t| ||S |d	ksG|d
krLt| S |dkrUt| |S |dkr^t	| S |dkr|dvry|  d}t
|dkrutd|dvsft| }| dd t| ||S |dv r|  d}| t
| d t|d urt| |S t| S td| d|   )Nr   r@      /   <r   r  r   r3      t   f   (   nr   r   r   zFile ended unexpectedly.s   0123456789+-.   z(Invalid Elementary Object starting with z @)rB   rD   r#   rI   rW   r'   r)   r    r(   r$   ry   r   r   rF   IndirectPatternmatchr"   r%   r   r   )r1   r>   r?   rH   r   r.   r.   r/   rF   0  sH   








rF   c                   @   st  e Zd ZdZdeeef ddfddZede	e
 fddZede	e
 fd	d
Zede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fddZede	e fdd Zede	e fd!d"Zede	e fd#d$ZdS )%Fieldz
    A class representing a field dictionary.

    This class is accessed through
    :meth:`get_fields()<PyPDF2.PdfReader.get_fields>`
    r7   r*   Nc              	   C   sN   t |  t t  }|D ]}z
|| | t|< W q ty$   Y qw d S rO   )rW   r   r   
attributesr   r#   KeyError)r-   r7   Zfield_attributesattrr.   r.   r/   r   k  s   
zField.__init__c                 C      |  tjS )z4Read-only property accessing the type of this field.)rh   r   r   r,   r.   r.   r/   
field_typex     zField.field_typec                 C   rk   )zX
        .. deprecated:: 1.28.3

            Use :py:attr:`field_type` instead.
        	fieldTyper  )r   r  r,   r.   r.   r/   r  }  rp   zField.fieldTypec                 C   r  )z6Read-only property accessing the parent of this field.)rh   r   ZParentr,   r.   r.   r/   parent  r  zField.parentc                 C   r  )z4Read-only property accessing the kids of this field.)rh   r   ZKidsr,   r.   r.   r/   kids  r  z
Field.kidsc                 C   r  )z4Read-only property accessing the name of this field.)rh   r   Tr,   r.   r.   r/   name  r  z
Field.namec                 C   r  )z>Read-only property accessing the alternate name of this field.)rh   r   ZTUr,   r.   r.   r/   alternate_name  r  zField.alternate_namec                 C   rk   )z\
        .. deprecated:: 1.28.3

            Use :py:attr:`alternate_name` instead.
        altNamer   )r   r   r,   r.   r.   r/   r!    rp   zField.altNamec                 C   r  )z
        Read-only property accessing the mapping name of this field. This
        name is used by PyPDF2 as a key in the dictionary returned by
        :meth:`get_fields()<PyPDF2.PdfReader.get_fields>`
        )rh   r   ZTMr,   r.   r.   r/   mapping_name     zField.mapping_namec                 C   rk   )zZ
        .. deprecated:: 1.28.3

            Use :py:attr:`mapping_name` instead.
        mappingNamer"  )r   r"  r,   r.   r.   r/   r$    rp   zField.mappingNamec                 C   r  )z
        Read-only property accessing the field flags, specifying various
        characteristics of the field (see Table 8.70 of the PDF 1.7 reference).
        )rh   r   ZFfr,   r.   r.   r/   flags     zField.flagsc                 C   r  )zr
        Read-only property accessing the value of this field. Format
        varies based on field type.
        )rh   r   Vr,   r.   r.   r/   r]     r&  zField.valuec                 C   r  )z=Read-only property accessing the default value of this field.)rh   r   ZDVr,   r.   r.   r/   default_value  r  zField.default_valuec                 C   rk   )z[
        .. deprecated:: 1.28.3

            Use :py:attr:`default_value` instead.
        defaultValuer(  )r   r(  r,   r.   r.   r/   r)    rp   zField.defaultValuec                 C   r  )z
        Read-only property accessing the additional actions dictionary.
        This dictionary defines the field's behavior in response to trigger events.
        See Section 8.5.2 of the PDF 1.7 reference.
        )rh   r   ZAAr,   r.   r.   r/   additional_actions  r#  zField.additional_actionsc                 C   rk   )z`
        .. deprecated:: 1.28.3

            Use :py:attr:`additional_actions` instead.
        additionalActionsr*  )r   r*  r,   r.   r.   r/   r+    rp   zField.additionalActions)rP   rQ   rR   __doc__r   rS   r   r   r   r   r#   r  r  rW   r  r)   r  r  r   r!  r"  r$  rV   r%  r]   r(  r)  r*  r+  r.   r.   r.   r/   r  c  sB    				r  c                
   @   st  e Zd ZdZdedeeeee	f deeef de
ddf
dd	Zedefd
dZdefddZdededeef ddfddZedee fddZedee fddZedee fddZedee fddZedee fddZedee fddZedee fddZedee fd d!Zedee fd"d#Zedee fd$d%Z edee fd&d'Z!dS )(Destinationa  
    A class representing a destination within a PDF file.
    See section 8.2.1 of the PDF 1.6 reference.

    :param str title: Title of this destination.
    :param IndirectObject page: Reference to the page of this destination. Should
        be an instance of :class:`IndirectObject<PyPDF2.generic.IndirectObject>`.
    :param str typ: How the destination is displayed.
    :param args: Additional arguments may be necessary depending on the type.
    :raises PdfReadError: If destination type is invalid.

    .. list-table:: Valid ``typ`` arguments (see PDF spec for details)
       :widths: 50 50

       * - /Fit
         - No additional arguments
       * - /XYZ
         - [left] [top] [zoomFactor]
       * - /FitH
         - [top]
       * - /FitV
         - [left]
       * - /FitR
         - [left] [bottom] [right] [top]
       * - /FitB
         - No additional arguments
       * - /FitBH
         - [top]
       * - /FitBV
         - [left]
    titlepagetypargsr*   Nc                 G   s\  t |  || td< || td< || td< |dkr0|\| ttj< | ttj< | td< d S |tjkrQ|\| ttj< | ttj< | ttj	< | ttj< d S |tj
tjfv rwz|\| ttj< W d S  tyv   t | ttj< Y d S w |tjtjfv rz|\| ttj< W d S  ty   t | ttj< Y d S w |tjtjfv rd S td|)N/Title/Page/Typez/XYZ/ZoomzUnknown Destination Type: )rW   r   r#   TALEFTZTOPTFZFIT_RZBOTTOMRIGHTZFIT_HZFIT_BHr   r$   ZFIT_VZFIT_BVZFITZFIT_Br   )r-   r.  r/  r0  r1  r.   r.   r/   r     s@   

zDestination.__init__c                    s(   t  d d g fdddD  S )Nr3  r4  c                    s   g | ]
}| v r | qS r.   r.   ).0xr,   r.   r/   
<listcomp>9  s
    z*Destination.dest_array.<locals>.<listcomp>)/Left/Bottom/Right/Topr5  )r)   r\   r,   r.   r,   r/   
dest_array5  s   
zDestination.dest_arrayc                 C   rk   )zX
        .. deprecated:: 1.28.3

            Use :py:attr:`dest_array` instead.
        getDestArrayrA  )r   rA  r,   r.   r.   r/   rB  @  s   
zDestination.getDestArrayr1   r2   c                 C   s   | d td}||| | d | j}||| td}||| | d td}||| | d | d d S )Nrq   z/Dr4   z/Sz/GoTorr   rs   )r5   r#   r6   rA  )r-   r1   r2   rX   r]   Zvalue_sr.   r.   r/   r6   I  s   



zDestination.write_to_streamc                 C   
   |  dS )z3Read-only property accessing the destination title.r2  rh   r,   r.   r.   r/   r.  \     
zDestination.titlec                 C   rC  )z9Read-only property accessing the destination page number.r3  rD  r,   r.   r.   r/   r/  a  rE  zDestination.pagec                 C   rC  )z2Read-only property accessing the destination type.r4  rD  r,   r.   r.   r/   r0  f  rE  zDestination.typc                 C      |  ddS )z-Read-only property accessing the zoom factor.r5  NrD  r,   r.   r.   r/   zoomk  r  zDestination.zoomc                 C   rF  )z<Read-only property accessing the left horizontal coordinate.r=  NrD  r,   r.   r.   r/   leftp  r  zDestination.leftc                 C   rF  )z=Read-only property accessing the right horizontal coordinate.r?  NrD  r,   r.   r.   r/   rightu  r  zDestination.rightc                 C   rF  )z9Read-only property accessing the top vertical coordinate.r@  NrD  r,   r.   r.   r/   topz  r  zDestination.topc                 C   rF  )z<Read-only property accessing the bottom vertical coordinate.r>  NrD  r,   r.   r.   r/   bottom  r  zDestination.bottomc                 C   s"   |  dttdtdtdgS )zGRead-only property accessing the color in (R, G, B) with values 0.0-1.0z/Cr   )rh   r)   r!   r,   r.   r.   r/   color  s   zDestination.colorc                 C   rF  )zDRead-only property accessing the font type. 1=italic, 2=bold, 3=bothz/Fr   rD  r,   r.   r.   r/   font_format  r  zDestination.font_formatc                 C   rF  )z
        Read-only property accessing the outline count.
        positive = expanded
        negative = collapsed
        absolute value = number of visible descendents at all levels
        r   NrD  r,   r.   r.   r/   outline_count  s   zDestination.outline_count)"rP   rQ   rR   r,  rS   r	   r%   r"   r$   rW   r   r   r   r)   rA  rB  r   rT   r6   r   r.  rV   r/  r0  rG  r!   rH  rI  rJ  rK  rL  r   rM  rN  r.   r.   r.   r/   r-    sZ     

)
	
r-  rO   )H
__author____author_email__loggingreior   typingr   r   r   r   r   r   r	   r
   _utilsr   r   r   r   r   r   r   r   r   	constantsr   r   r   r   r   r   r   r   r6  r   r8  errorsr   r   r   _baser    r!   r"   r#   r$   r%   r&   r'   r(   	getLoggerrP   loggerZNumberSignscompiler  rt   r)   rY   rW   r   r   r   r   r   r   rS   rV   rF   r  r-  r.   r.   r.   r/   <module>   sV   (,$	

8 c X+ 
3 	