
    ,g'                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZmZ  ed
d      Z edd      Zd Z	 	 ddZd Zd Zy)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                    |dk(  r>| j                         | j                         | j                         | j                         fS |dk(  r>| j	                         | j                         | j                         | j                         fS |dk(  sJ |       | j                         | j                         | j                  | j                  fS )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     t/home/viktor/gitlab-persoonlijk/factuur-applicatie/venv/lib/python3.12/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                     ddl m} t        |       |r"|j                         D ]  }t	        | ||        ||j
                  }|d   d   dk7  r#|d   \  }}|dk(  r ||      |_        n||_        |d	   d   dk7  r#|d	   \  }}|dk(  r ||      |_        n||_        |d
   dk(  rg }	t        d      }
n4|d   }|d   D cg c]  \  }}|dk(  r
 |||      n| }	}} ||d      }
|
j                  dk(  rt        |	      s|| k7  rd|_        yt        |	gt        t        |d   |d   |d   |d   |d   |d   g       D cg c]  }t        || |d   g|  }}t!        |
||d         |_        yc c}}w c c}w )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"%%' 	DE"40BC	D }		 "#A&&023uE>1e<C$C!"1%/12uE>$65$AC!$)C!\h&M*/0 !&&8 9; u ~ 5kB#(); ; %!34{{aF$;!CN  .#e#$#$%&%&'()*., #- ./ 	 T51C+DMuM/F /  vu5F/GHCN);/s   E5E;c
           
         g }
d}| |u r|j                   }g }
nTt        | t        j                        rg }
d}| j                  D ]`  }|j                  s|
|j                  D cg c]  }|j                          c}z  }
t        |t        d |j                  D                    }b | j                         | j                         | j                         |g}nt        | t        j                        r| j                  rn| j                  D cg c]  }|j                          }
}t        d | j                  D              }| j                         | j                         | j                         |g}nt        | t        j                  t        j                  f      ry| j                         }|r|D cg c]  }|j                          }
}t        d |D              }t        d |D              }|| j                         ||z
  | j                         g}nWt!        | |      }|dk(  r| j                         g}
n4|dk(  r| j#                         g}
n|d	k(  sJ |       | j%                         g}
|#|j'                  || j(                  d
         \  }}}|dfv rt+        d d|dddd|
      S |	dk(  rJt        | t        j,                        r#dd| j/                         | j1                         f}nt!        |d	      }nt!        | |      }|\  }}}}|\  }}}}|dk(  rt3        j4                  ||      \  }} nW|dk(  rt3        j6                  ||      \  }} n7|\  }!}"t3        j8                  ||t;        |!|      t;        |"|      ||      \  }} |\  }#}$}%}&||z
  }'|| z
  }(t;        |$|'      }$t;        |&|(      }&|#dk(  r|'|$z
  }$|%dk(  r|(|&z
  }&|\  })}*|)dk(  r6t        dt=        ||z              }+||+z  },d}$|*dk7  r|d   dk(  r| |,|z  z  } |,}|*dk(  r6t        dt=        || z              }+||+z  }-d}&|)dk7  r|d   dk(  r||-| z  z  }|-} t+        ||| f|$|&f|d|||
      S c c}w c c}w c c}w )N)r   r   r   r   r   c              3   <   K   | ]  }|j                           y wNr   .0cells     r    	<genexpr>z*layout_background_layer.<locals>.<genexpr>q   s       5C-1D&&(5C   c              3   <   K   | ]  }|j                           y wrP   rQ   rR   s     r    rU   z*layout_background_layer.<locals>.<genexpr>z   s     G$++-GrV   c              3   <   K   | ]  }|j                           y wrP   )r   rR   s     r    rU   z*layout_background_layer.<locals>.<genexpr>   s     >))+>rV   c              3   ^   K   | ]%  }|j                         |j                         z    ' y wrP   )r   r   rR   s     r    rU   z*layout_background_layer.<locals>.<genexpr>   s.      M>B!!#d&7&7&99Ms   +-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_   r`   ra   r]   r^   rb   rc   )
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
   ri   ).r   rD   
resolutionr\   r_   clipra   originr`   
attachmentrc   r^   total_heightrowrT   r   cellsmin_xmax_xintrinsic_widthintrinsic_heightratiorb   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
d{ 	C//	0<< 	DC||:=,,"H26D++-"H H"< 5C58\\5C 2C  D		D  0 0 2. 
C**	+<<69llD.2'')DM DG#,,GGF  "C$4$4$6  "F,M 
C%33U5I5IJ	KCHI4T446IMI>>>E MFKM ME s'')55=#:K:K:MOM &c4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(f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   "QQ!3Q&c                    t        | | |       t        | j                  d   t        j                        rJ | j                  d   }|}|j
                  j                         dk(  r>|j                  2|j                  D ]#  }|j
                  j                         dk(  s!|} n |j                  rt        | d      }| j                  }t        | | |d|j                         | j                  j                  | j                  j                  D cg c]  }|j                  |       c}	      | _        || _        d|_        yd| _        yc c}w )
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:   rl   rn   r   	MarginBoxelement_taglowerr@   r!   r;   _replacerM   canvas_background)rD   rE   root_box
chosen_boxrG   r^   original_backgroundrL   s           r    layout_backgroundsr      s<    4'9:$--*EOO<<<}}QHJ!!#v-(2E2E2M&& 	E  &&(F2"
	
 %dL9"oo$*E""	$ "&!9!9 "__335 ];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"   