
    Bh                     N    S r SSKrSSKJr  SSKJr  SSKJr  S r  S
S jr	S	 r
g)z7Find anchors, links, bookmarks and inputs in documents.    N   )boxes)
percentage)Matrixc                 
   U (       d	  XX-   X$-   4$ U R                   nU" X5      u  pgU" X-   U5      u  pU" XU-   5      u  pU" X-   X$-   5      u  p[        XhX5      n[        XyX5      n[        XhX5      n[        XyX5      nXUU4$ )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y4box_x1box_y1box_x2box_y2s                     D/var/www/html/env/lib/python3.13/site-packages/weasyprint/anchors.pyrectangle_aabbr   
   s     U]EN::,,OU*FBU]E2FBUFN3FBU]EN;FB F F F F66))    c           
      	   U R                   S   (       Ga  [        U [        R                  5      (       Gd  U R	                  5       nU R                  5       nU R                   S   u  p[        X5      n[        X5      nU R                  5       U-   n	U R                  5       U-   n
[        XS9nU R                   S    H  u  pSu  nnnnnnUS:X  a  Uu  nnOUS:X  a2  [        R                  " U5      =nn[        R                  " U5      nU* nOoUS:X  a  [        US   U5      n[        US	   U5      nOJUS
:X  a3  [        R                  " US	   5      [        R                  " US   5      nnOUS:X  d   eUu  nnnnnn[        UUUUUU5      U-  nM     [        U	* U
* S9U-  U l        U(       a  U R                  U-  nOU R                  nOUnU R                  nU R                   S   S:X  a  SnOU R                   S   nU R                   S   nU R                   S   nU R                   S   nU=(       a    UnU=(       a/    [        U [        R                   [        R"                  45      (       + nU=(       a    UU;  nU R%                  5       nU R'                  5       (       a  U R(                  nXd;  a  / XF'   U(       d  U(       d  U(       d  U(       Ga  U(       a9  U R+                  5       U R-                  5       n nU R.                  U R0                  n"n!OU R3                  5       u  nn n!n"U(       d  U(       a  [5        UUU U!U"5      n#U(       a[  Uu  n$nU$S:X  d   eUu  n%n&[        U&[6        5      (       d   eU%S:X  a  U R9                  5       (       a  Sn%UR;                  U%U&W#U 45        U(       a*  XF   R;                  U R(                  U R                   W#45        U(       a5  U(       a  UR=                  UU 5      u  nn UUUU 4U4n'UR;                  U'5        U(       aK  UU UU!-   U U"-   4u  n(n)n*n+U(       a*  UR=                  U(U)5      u  n(n)UR=                  U*U+5      u  n*n+U(U)U*U+4UU'   U R?                  5        H  n,[A        U,XX4X5        M     g)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formsparent_matrixparent_formr3   r4   origin_xorigin_yoffset_xoffset_yr   nameargsabcdr"   r#   r<   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childs-                                                r   rI   rI      s<    yyjeoo&F&F'')))+ YY'9:h5h6##%0##%0(/))K0JD/Aq!Q1w1!&AHHTNB$tAw5tAw6xxQ($((47*;11x'''#' 1aAqAq!Q1-6F! 1$ hY8),v5 	!..>F..F''N
yy!"f,#34II&'E99VD))H%K!4nLKJsU]]EMM,JKKH;G!;J||~H
{{}}kk#!#Ex:,,.0A0A0C5EIIszz6E6*-,,.'E5%x&vueUFKI#J&&& $Ivfc****J&3+<+<+>+>(	LL)VY<=%%s{{CIIy&IJ%55eUCu&NHX&-2E55=%RX.-X*FFFF!'!7!7!G!'!7!7!G$*FFF#CGK !!#ugiT $r   c                    U R                    H  u  pgu  pn
Xc:  a  UR                  Xc-
  S-
  5        O?UnX:  a  USUR                  5       -   -  nX:  a  M  X:  a  UR                  X-
  S-
  5        UnU[        U5      -
  nU[	        U5      :X  d   eUS:  d   e/ nUR                  X5      u  pXtX4X4nX,S-
     R                  U5        X,S2	 UR                  U5        M     U$ )z-Make a tree of all bookmarks in a given page.r   N)rM   rG   popsumlenr   )pageskipped_levelslast_by_depthprevious_levelpage_numberr   levellabelpoint_xpoint_yr[   tempdepthchildrensubtrees                  r   make_page_bookmark_treer{      s    48>>/(w%! !!%"81"<=D'N..000 '$%%d&;a&?@N++N++++zz!11'C98Kai ''0&!X&1 4B2 r   )NN)__doc__r7   formatting_structurer   layout.percentr   r   r   r   rI   r{    r   r   <module>r      s0    =  ' & *( IM#cULr   