a
    ¥Q•h  ã                   @   sN   d Z ddlZddlmZ ddlmZ ddlmZ dd„ Zdd	d
„Z	dd„ Z
dS )z7Find anchors, links, bookmarks and inputs in documents.é    Né   )Úboxes)Ú
percentage)ÚMatrixc                 C   sª   | s|||| || fS | j }|||ƒ\}}||| |ƒ\}}	|||| ƒ\}
}||| || ƒ\}}t|||
|ƒ}t||	||ƒ}t|||
|ƒ}t||	||ƒ}||||fS )z„Apply a transformation matrix to an axis-aligned rectangle.

    Return its axis-aligned bounding box as ``(x1, y1, x2, y2)``.

    )Útransform_pointÚminÚmax)ÚmatrixÚpos_xÚpos_yÚwidthÚheightr   Úx1Úy1Úx2Úy2Úx3Úy3Úx4Úy4Zbox_x1Zbox_y1Zbox_x2Zbox_y2© r   úK/var/www/sistema_ama/venv/lib/python3.9/site-packages/weasyprint/anchors.pyÚrectangle_aabb
   s    r   c           -   	   C   sÄ  | j d �r‚t| tjƒ�s‚|  ¡ }|  ¡ }| j d \}	}
t|	|ƒ}t|
|ƒ}|  ¡ | }	|  ¡ | }
t	|	|
d�}| j d D ]Ö\}}d\}}}}}}|dkr¤|\}}n–|dkrÌt
 |¡ }}t
 |¡}| }nn|dkròt|d |ƒ}t|d	 |ƒ}nH|d
k�rt
 |d	 ¡t
 |d ¡ }}n|dk�s*J ‚|\}}}}}}t	||||||ƒ| }qzt	|	 |
 d�| | _|�rz| j| }n| j}n|}| j}| j d dk�r¢d}n
| j d }| j d }| j d }| j d }|�oÒ|}|�oìt| tjtjfƒ }|�oú||v}|  ¡ }|  ¡ �r&| j}||v�r&g ||< |�s>|�s>|�s>|�rœ|�rf|  ¡ |  ¡  }} | j| j }!}"n|  ¡ \}} }!}"|�s‚|�r’t||| |!|"ƒ}#|�rð|\}$}|$dk�s®J ‚|\}%}&t|&tƒ�sÆJ ‚|%dk�rÞ|  ¡ �rÞd}%| |%|&|#| f¡ |�r||  | j| j |#f¡ |�rD|�r*| || ¡\}} |||| f|f}'| |'¡ |�rœ|| ||! | |" f\}(})}*}+|�rŒ| |(|)¡\}(})| |*|+¡\}*}+|(|)|*|+f||< |  ¡ D ]},t |,||||||ƒ �q¤dS )zƒGather anchors and other data related to specific positions in PDF.

    Currently finds anchors, links, bookmarks and forms.

    Ú	transformÚtransform_origin)ÚeÚf)r   r   r   r   r   r   ÚscaleÚrotateÚ	translater   r   Úskewr	   Úbookmark_levelÚnoneNÚbookmark_stateÚlinkÚanchorÚurlÚexternalÚ
attachment)!ÚstyleÚ
isinstancer   Ú	InlineBoxÚborder_widthÚborder_heightr   Úborder_box_xÚborder_box_yr   ÚmathÚcosÚsinÚtanÚtransformation_matrixÚbookmark_labelÚTextBoxÚLineBoxÚis_inputÚis_formÚelementÚcontent_box_xÚcontent_box_yr   r   Úhit_arear   ÚstrÚis_attachmentÚappendr   Úall_childrenÚgather_anchors)-ÚboxÚanchorsÚlinksÚ	bookmarksÚformsZparent_matrixZparent_formr,   r-   Úorigin_xÚorigin_yÚoffset_xÚoffset_yr	   ÚnameÚargsÚaÚbÚcÚdr   r   r5   r!   Ústater$   Úanchor_nameZhas_bookmarkZhas_linkZ
has_anchorr8   r
   r   r   r   Ú	rectangleÚ
token_typeÚ	link_typeÚtargetÚbookmarkZpos_x1Zpos_y1Zpos_x2Zpos_y2Úchildr   r   r   rB      s˜    




 ÿ







rB   c                 C   sè   | j D ]Ü\}}\}}	}
||kr2| || d ¡ n8|}||k rP|d| ¡  7 }q6||krj| || d ¡ |}|t|ƒ }|t|ƒksŠJ ‚|dks–J ‚g }| ||	¡\}}	||||	f||
f}||d   |¡ ||d…= | |¡ q|S )z-Make a tree of all bookmarks in a given page.r   N)rF   r@   ÚpopÚsumÚlenr   )ÚpageÚskipped_levelsÚlast_by_depthÚprevious_levelÚpage_numberr	   ÚlevelÚlabelZpoint_xZpoint_yrR   ÚtempÚdepthÚchildrenÚsubtreer   r   r   Úmake_page_bookmark_tree„   s&    
rh   )NN)Ú__doc__r0   Úformatting_structurer   Zlayout.percentr   r	   r   r   rB   rh   r   r   r   r   Ú<module>   s     ÿ
f