o
    Zh0h                     @   sR   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y1x2y2x3y3x4y4box_x1box_y1box_x2box_y2 r   H/var/www/html/rh/venv/lib/python3.10/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 ]i\}}d\}}}}}}|dkrP|\}}nI|dkrdt
| }}t
|}| }n5|dkrwt|d |}t|d	 |}n"|d
krt
|d	 t
|d }}n|dksJ |\}}}}}}t	||||||| }q;t	|	 |
 d| | _|r| 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|r*|  |  }} | j| j}!}"n|  \}} }!}"|s8|r@t||| |!|"}#|ro|\}$}|$dksNJ |\}%}&t|&tsZJ |%dkrf|  rfd}%||%|&|#| f |r~|| | j| j |#f |r|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.

    	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formsparent_matrixparent_formr0   r1   origin_xorigin_yoffset_xoffset_yr	   nameargsabcdr   r    r9   r%   stater(   anchor_namehas_bookmarkhas_link
has_anchorr<   r
   r   r   r   	rectangle
token_type	link_typetargetbookmarkpos_x1pos_y1pos_x2pos_y2childr   r   r   rF      s   



 






rF   c                 C   s   | j D ]q\}}\}}	}
||kr||| d  n|}||k r+|d|  7 }||k s||kr8||| d  |}|t| }|t|ksHJ |dksNJ g }|||	\}}	||||	f||
f}||d  | ||d= || q|S )z-Make a tree of all bookmarks in a given page.r   N)rJ   rD   popsumlenr   )pageskipped_levelslast_by_depthprevious_levelpage_numberr	   levellabelpoint_xpoint_yrX   tempdepthchildrensubtreer   r   r   make_page_bookmark_tree   s(   
rw   )NN)__doc__r4   formatting_structurer   layout.percentr   r	   r   r   rF   rw   r   r   r   r   <module>   s    
f