
    ,g                     L    d Z ddlZddlmZ ddlmZ ddlmZ d Z	 	 d
dZ	d	 Z
y)z7Find anchors, links, bookmarks and inputs in documents.    N   )boxes)
percentage)Matrixc                 *   | s||||z   ||z   fS | j                   } |||      \  }} |||z   |      \  }}	 ||||z         \  }
} |||z   ||z         \  }}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_y2s                     j/home/viktor/gitlab-persoonlijk/factuur-applicatie/venv/lib/python3.12/site-packages/weasyprint/anchors.pyrectangle_aabbr   
   s     eUU]EFN::,,OUE*FBUU]E2FBUEFN3FBUU]EFN;FBRR FRR FRR FRR F666))    c           
      0   | j                   d   rt        | t        j                        s| j	                         }| j                         }| j                   d   \  }	}
t        |	|      }t        |
|      }| j                         |z   }	| j                         |z   }
t        |	|
      }| j                   d   D ]  \  }}d\  }}}}}}|dk(  r|\  }}n|dk(  r0t        j                  |      x}}t        j                  |      }| }nj|dk(  rt        |d   |      }t        |d	   |      }nF|d
k(  r1t        j                  |d	         t        j                  |d         }}n|dk(  sJ |\  }}}}}}t        ||||||      |z  } t        |	 |
       |z  | _        |r| j                  |z  }n| j                  }n|}| j                  }| j                   d   dk(  rd}n| j                   d   }| j                   d   }| j                   d   }| j                   d   }|xr |}|xr+ t        | t        j                   t        j"                  f       }|xr ||v}| j%                         }| j'                         r| j(                  }||vrg ||<   |s|s|s|r[|r9| j+                         | j-                         } }| j.                  | j0                  }"}!n| j3                         \  }} }!}"|s|rt5        ||| |!|"      }#|rO|\  }$}|$dk(  sJ |\  }%}&t        |&t6              sJ |%dk(  r| j9                         rd}%|j;                  |%|&#| f       |r+||   j;                  | j(                  | j                   #f       |r0|r|j=                  ||       \  }} |||| f|f}'|j;                  |'       |rF|| ||!z   | |"z   f\  }(})}*}+|r*|j=                  |(|)      \  }(})|j=                  |*|+      \  }*}+|(|)|*|+f||<   | j?                         D ]  },tA        |,||||||        y)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_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      sL    yyjeoo&F'')))+ YY'9:(h5h6##%0##%0(h/))K0 	7JD$/Aq!Q1w1!&AHHTNB$tAw5tAw6xxQ($((47*;1x'''#' 1aAqAq!Q1-6F!	7$ 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#!#E+x:,,.0A0A0C5EIIszz6E*-,,.'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 !!# UuguiTUr   c                    | j                   D ]  \  }}\  }}	}
||kD  r|j                  ||z
  dz
         n?|}||k  r|d|j                         z   z  }||k  r||kD  r|j                  ||z
  dz
         |}|t        |      z
  }|t	        |      k(  sJ |dk\  sJ g }|j                  ||	      \  }}	||||	f||
f}||dz
     j                  |       ||d= |j                  |        |S )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{      s1    48>> '/u(w%>! !!%."81"<=D'N..000 'n$%%d^&;a&?@N++N++++zz!11'7C;98UKeai ''0%&!X&1'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   