o
    Zh0h2$                     @   s   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ed	d
 Zdd Zdd ZdddZdddZdS )zLayout for floating boxes.   )boxes   )handle_min_max_width)resolve_percentagesresolve_position_percentages)shrink_to_fit) inline_replaced_box_width_height)table_wrapper_widthc                 C   s"   | j dkrt|| |j | _ d S d S )Nauto)widthr   )boxcontextcontaining_block r   M/var/www/html/rh/venv/lib/python3.10/site-packages/weasyprint/layout/float.pyfloat_width   s   
r   c                 C   s  ddl m} ddlm} ddlm}	 |j|j}
}t||
|f |dkr+|j	|
  }t||
|f |jdkr:d|_|jdkrBd|_|jdkrJd|_|jdkrRd|_t| |}|durb| j	|7  _	t|tjrnt|| n|jdkryt|| | |jrt| ||
|f t|tjr|   || |||d||dd	dd

\}}}}}}| | n;t|tjr|| ||||d||d	d	\}}}}}n"t|tjr|	| ||||d||d\}}}}}n
t|tjsJ d}t| ||}| j| ||fS )z/Set the width and position of floating ``box``.r   )block_container_layout)flex_layout)grid_layoutr
       NTF)bottom_space
skip_stackpage_is_emptyabsolute_boxesfixed_boxesadjoining_marginsdiscard	max_lines)r   r   r   r   r   r   r   )r   r   r   r   r   r   ) blockr   flexr   gridr   r   heightr   
position_ycontent_box_yr   margin_leftmargin_right
margin_topmargin_bottomget_clearance
isinstancer   BlockReplacedBoxr   r   is_table_wrapperr	   BlockContainerBoxcreate_block_formatting_contextfinish_block_formatting_contextFlexContainerBoxGridContainerBoxfind_float_positionexcluded_shapesappend)r   r   r   r   r   r   r   r   r   r   cb_width	cb_height	clearance	resume_at_r   r   r   float_layout   sl   





r9   c                 C   sz   | j r| j d j}|j|k r|d||j  t| ||\}}}|jd dkr/|||  7 }|||j ||j  |S )z,Get the right position of the float ``box``.r   floatright)r2   r"   	translateavoid_collisionsstylemargin_width
position_x)r   r   r   	highest_yrA   r"   available_widthr   r   r   r1   X   s   

r1   r   c                 C   sh   d}|j | }| jD ]'}|jd |jd dfv r1|j | }}||| k r1t|p*d|| | }q
|S )zDReturn None if there is no clearance, otherwise the clearance value.Nclearr;   bothr   )r"   r2   r?   margin_heightmax)r   r   collapsed_marginr6   hypothetical_positionexcluded_shapeyhr   r   r   r(   t   s   

r(   Tc                 C   sJ  | j }|r|jn| }|r| n| }|r| n| }| dkr0| r0dd|jfS 	 g }|D ]6}	|	j}
|	 }|
|  k rJ|
| k sfn |
||   k rY|
| k sfn |
|krk|
| || krk|	|	 q5dd |D }dd |D }|
 }|
 |j }|s||j7 }||j8 }|s|r|rtt||}|rtt||}||| krtdd |D }||kr|}q0	 |jd d	v st|tjs|jst|tjs| sJ |}|jd d
kr|jd dkrt|tjr|}n|jr|| }nt|tjs| sJ || }|| }|s ||j8 }||j8 }|||fS )Nr   Tc                 S   s(   g | ]}|j d  dkr|j|  qS )r;   left)r?   rA   r@   .0shaper   r   r   
<listcomp>   s
    z$avoid_collisions.<locals>.<listcomp>c                 S   s    g | ]}|j d  dkr|jqS )r;   r<   )r?   rA   rN   r   r   r   rQ      s
    c                 s   s    | ]
}|j |  V  qd S )N)r"   rF   rN   r   r   r   	<genexpr>   s
    
z#avoid_collisions.<locals>.<genexpr>r;   )r<   rM   none	directionrtl)r2   r"   border_box_yr@   border_widthrF   border_height
is_floatedr   r3   content_box_xr$   r%   rG   minr?   r)   r   LineBoxr+   r*   establishes_formatting_contextr&   )r   r   r   outerr2   r"   	box_width
box_heightcolliding_shapesrP   shape_position_yshape_margin_heightleft_boundsright_boundsmax_left_boundmax_right_boundnew_position_yrA   rC   r   r   r   r>      s   










r>   N)r   )T)__doc__formatting_structurer   min_maxr   percentr   r   	preferredr   replacedr   tabler	   r   r9   r1   r(   r>   r   r   r   r   <module>   s    
E
