
    Bh'                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	KJrJr  \" S
S5      r\" SS5      rS r  SS jrS rS rg)z$Manage background position and size.    )
namedtuple)cycle)parse_color   )boxes   )replaced)
percentageresolve_radii_percentages
Backgroundzcolor, layers, image_renderingBackgroundLayerzXimage, size, position, repeat, unbounded, painting_area, positioning_area, clipped_boxesc                    US:X  a>  U R                  5       U R                  5       U R                  5       U R                  5       4$ US:X  a>  U R	                  5       U R                  5       U R                  5       U R                  5       4$ US:X  d   U5       eU R                  5       U R                  5       U R                  U R                  4$ )N
border-boxpadding-boxcontent-box)border_box_xborder_box_yborder_widthborder_heightpadding_box_xpadding_box_ypadding_widthpadding_heightcontent_box_xcontent_box_ywidthheight)boxwhich_rectangles     N/var/www/html/env/lib/python3.13/site-packages/weasyprint/layout/background.pybox_rectangler!      s    ,& 0 0 2 1 1 35 	5 
M	)!2!2!4!3!3!57 	7 -/@@/!2!2!4IIszz# 	#    Nc                    SSK Jn  [        U5        U(       a#  UR                  5        H  n[	        XU5        M     Uc  UR
                  nUS   S   S:w  a  US   u  pxUS:X  a  U" US9Ul        OXl        US	   S   S:w  a  US	   u  pxUS:X  a  U" US9Ul        OXl        US
   S:X  a  / n	[        S5      n
O3US   nUS    VVs/ s H  u  pxUS:X  a  U" XS9OUPM     n	nnU" US5      n
U
R                  S:X  a  [        U	5      (       d  X:w  a  SUl        g[        U	/[        [        US   US   US   US   US   US   /5      Q76  Vs/ s H  n[        XUS   /UQ76 PM     nn[!        XUS   5      Ul        gs  snnf s  snf )z%Fetch and position background images.r   )	get_colorNborder_image_sourcer   noneurl)r'   mask_border_source
visibilityhiddentransparentimage_orientationbackground_image)r'   orientationbackground_colorbackground_sizebackground_clipbackground_repeatbackground_originbackground_positionbackground_attachmentimage_resolutionimage_rendering)
draw.colorr$   r   all_childrenlayout_box_backgroundsstyleborder_imagemask_border_imager   alphaany
backgroundzipmapr   layout_background_layerr   )pager   get_image_from_urilayout_childrenr;   r$   childtype_valueimagescolorr.   layerlayerss                 r    r:   r:   #   s    ' c"%%'E"40BC ( }		 "#A&&023E>1e<C$!"1%/12E>$65$AC!$)!\h&M*/0 !&&8 9; !: ~ 5B#() 9 	 ; %!34{{aF;!CN  .#e#$#$%&%&'()*., #- ./.E 	 51C+DMuM.  /  u5F/GHCN);/s   E=Fc
                 F	   / n
SnXL a  UR                   n/ n
GO}[        U [        R                  5      (       a  / n
SnU R                   Hi  nUR                  (       d  M  U
UR                   Vs/ s H  oR                  5       PM     sn-  n
[        U[        S UR                   5       5      5      nMk     U R                  5       U R                  5       U R                  5       U/nGO[        U [        R                  5      (       a  U R                  (       au  U R                   Vs/ s H  oR                  5       PM     n
n[        S U R                   5       5      nU R                  5       U R                  5       U R                  5       U/nGO[        U [        R                  [        R                  45      (       a  U R                  5       nU(       ah  U Vs/ s H  oR                  5       PM     n
n[        S U 5       5      n[        S U 5       5      nUU R                  5       UU-
  U R                  5       /nOY[!        X5      nUS:X  a  U R                  5       /n
O6US:X  a  U R#                  5       /n
OUS	:X  d   U5       eU R%                  5       /n
Ub"  UR'                  X R(                  S
   5      u  nnnUb  SWW4;   a  [+        S SUSSSSU
S9$ U	S:X  aO  [        U [        R,                  5      (       a#  SSU R/                  5       U R1                  5       4nO[!        US	5      nO[!        X5      nUu  nnnnUu  nnnnUS:X  a  [2        R4                  " UUW5      u  nn OZUS:X  a  [2        R6                  " UUW5      u  nn O8Uu  n!n"[2        R8                  " UUW[;        U!U5      [;        U"U5      UU5      u  nn Uu  n#n$n%n&UU-
  n'UU -
  n([;        U$U'5      n$[;        U&U(5      n&U#S:X  a  U'U$-
  n$U%S:X  a  U(U&-
  n&Uu  n)n*U)S:X  a8  [        S[=        UU-  5      5      n+UU+-  n,Sn$U*S:w  a  US   S:X  a  U U,U-  -  n U,nU*S:X  a8  [        S[=        UU -  5      5      n+UU+-  n-Sn&U)S:w  a  US   S:X  a  UU-U -  -  nU-n [+        UUU 4U$U&4USUUU
S9$ s  snf s  snf s  snf )N)r   r   r   r   r   c              3   @   #    U  H  oR                  5       v   M     g 7fNr   .0cells     r    	<genexpr>*layout_background_layer.<locals>.<genexpr>q   s      5C5AT&&((\   c              3   @   #    U  H  oR                  5       v   M     g 7frP   rQ   rR   s     r    rU   rV   z   s     G,$++--,rW   c              3   @   #    U  H  oR                  5       v   M     g 7frP   )r   rR   s     r    rU   rV      s     >))++rW   c              3   b   #    U  H%  oR                  5       UR                  5       -   v   M'     g 7frP   )r   r   rR   s     r    rU   rV      s)      MFKd!!#d&7&7&99es   -/r   r   r   	font_sizeFunused)image	unboundedpainting_areasizepositionrepeatpositioning_areaclipped_boxesfixedcovercontainrightbottomroundr   auto)r]   r`   ra   rb   r^   r_   rc   rd   )
bleed_area
isinstancer   TableRowGroupBoxchildrenrounded_border_boxmaxr   r   r   TableRowBoxTableColumnGroupBoxTableColumnBox	get_cellsminr   r!   rounded_padding_boxrounded_content_boxget_intrinsic_sizer;   r   PageBoxmargin_widthmargin_heightr	   cover_constraint_image_sizingcontain_constraint_image_sizingdefault_image_sizingr
   rj   ).r   rD   
resolutionr]   r`   cliprb   originra   
attachmentrd   r_   total_heightrowrT   r   cellsmin_xmax_xintrinsic_widthintrinsic_heightratiorc   positioning_xpositioning_ypositioning_widthpositioning_height
painting_x
painting_ypainting_widthpainting_heightimage_widthimage_height
size_widthsize_heightorigin_x
position_xorigin_y
position_yref_xref_yrepeat_xrepeat_y	n_repeats	new_width
new_heights.                                                 r    rC   rC   ^   s    MM
{ 	C//	0	0<<C|||:=,,"H:F$++-,"H H"< 5C58\\5C 2C  D	    0 0 2. 
C**	+	+<<69llD6Bd'')l  DG#,,GGF  "C$4$4$6  "F,M 
C%33U5I5IJ	K	KCHI544465MI>>>E MFKM ME s'')55=#:K:K:MOM &c0< 3356M]" 4467M=(.$.( 4467M383K3K		+.400)5}o/?@@%}HX%]D 	D
 Wc5==)) !"1c&6&6&8#:K:K:MN,T=A(5 	 HM="35G>K;J
NOw$,$J$J15%:!\		$,$L$L15%:!\ #'
K$,$A$A-uz#45{$671	%3!\ 2:.Hj(J+E-EJ.JJ.J7Z'
8Z'
Hh75!2[!@AB	%	1	
w47f#4I33L75!3l!BCD	')3

w47f#4:44K!<(j)#)#% %I"HD Js   -R%RRc           	         [        X U5        [        U R                  S   [        R                  5      (       a   eU R                  S   nUnUR
                  R                  5       S:X  aB  UR                  c5  UR                   H%  nUR
                  R                  5       S:X  d  M#  Un  O   UR                  (       a  [        U S5      nU R                  n[        X USUR                  S9  U R                  R                  U R                  R                   Vs/ s H  nUR                  US9PM     snS	9U l        X`l        SUl        gSU l        gs  snf )
zLayout backgrounds on the page box and on its children.

This function takes care of the canvas background, taken from the root
elememt or a <body> child of the root element.

See https://www.w3.org/TR/CSS21/colors.html#background

r   htmlNbodyr   F)rF   r;   )r_   )rM   )r:   rm   ro   r   	MarginBoxelement_taglowerr@   r!   r;   _replacerM   canvas_background)rD   rE   root_box
chosen_boxrG   r_   original_backgroundrL   s           r    layout_backgroundsr      s9    4'9:$--*EOO<<<<}}QHJ!!#v-(2E2E2M&&E  &&(F2"
 '
 %dL9"oo*E""	$ "&!9!9 "__3353E ];35 ": "6
 . $
!%5s   E)TN)__doc__collectionsr   	itertoolsr   tinycss2.color4r   formatting_structurer    r	   percentr
   r   r   r   r!   r:   rC   r    r"   r    <module>r      s[    * "  ' (  :&FG
56#  KO!%8Iv}%@!&r"   