a
    [Xh                     @   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 )zApply 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y1Zx2y2Zx3Zy3Zx4Zy4Zbox_x1Zbox_y1Zbox_x2Zbox_y2 r   W/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/weasyprint/anchors.pyrectangle_aabb
   s    r   c           -   	   C   s  | j d rt| tjs|  }|  }| j d \}	}
t|	|}t|
|}|  | }	|  | }
t	|	|
d}| j d D ]\}}d\}}}}}}|dkr|\}}n|dkrt
| }}t
|}| }nn|dkrt|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rd}n
| j d }| j d }| j d }| j d }|o|}|ot| tjtjf }|o||v}|  }|  r&| j}||vr&g ||< |s>|s>|s>|r|rf|  |   }} | j| j }!}"n|  \}} }!}"|s|rt||| |!|"}#|r|\}$}|$dksJ |\}%}&t|&tsJ |%dkr|  rd}%||%|&|#| f |r|| | j| j |#f |rD|r*||| \}} |||| f|f}'||' |r|| ||! | |" f\}(})}*}+|r||(|)\}(})||*|+\}*}+|(|)|*|+f||< |  D ]},t |,|||||| qdS )zGather anchors and other data related to specific positions in PDF.

    Currently finds anchors, links, bookmarks and forms.

    Z	transformZtransform_origin)ef)r   r   r   r   r   r   Zscalerotate	translater   r   Zskewr	   bookmark_levelnoneNZbookmark_statelinkanchorurlZexternal
attachment)!style
isinstancer   Z	InlineBoxborder_widthborder_heightr   Zborder_box_xZborder_box_yr   mathcossintanZtransformation_matrixbookmark_labelZTextBoxZLineBoxis_inputZis_formelementZcontent_box_xZcontent_box_yr   r   Zhit_arear   stris_attachmentappendr   Zall_childrengather_anchors)-ZboxZanchorslinks	bookmarksZformsZparent_matrixZparent_formr    r!   Zorigin_xZorigin_yZoffset_xZoffset_yr	   nameargsabcdr   r   r&   r   stater   Zanchor_nameZhas_bookmarkZhas_linkZ
has_anchorr'   r
   r   r   r   Z	rectangle
token_typeZ	link_typetargetbookmarkZpos_x1Zpos_y1Zpos_x2Zpos_y2childr   r   r   r,      s    




 







r,   c                 C   s   | j D ]\}}\}}	}
||kr2||| d  n8|}||k rP|d|  7 }q6||krj||| d  |}|t| }|t|ksJ |dksJ g }|||	\}}	||||	f||
f}||d  | ||d= || q|S )z-Make a tree of all bookmarks in a given page.r   N)r.   r+   popsumlenr   )pageZskipped_levelsZlast_by_depthZprevious_levelZpage_numberr	   levellabelZpoint_xZpoint_yr5   tempdepthchildrenZsubtreer   r   r   make_page_bookmark_tree   s&    
rC   )NN)__doc__r"   Zformatting_structurer   Zlayout.percentr   r	   r   r   r,   rC   r   r   r   r   <module>   s     
f