o
    hG%                     @   s   d Z ddlm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.    )inf   )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   Y/var/www/html/optinet_system/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   r   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   





r:   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)r3   r#   	translateavoid_collisionsstylemargin_width
position_x)r   r   r   	highest_yrB   r#   available_widthr   r   r   r2   Z   s   

r2   c           	      C   s   | j D ]}| r|jd |jd dfv rt  S qd}|j| }| jD ]'}|jd |jd dfv rK|j| }}||| k rKt|pDd|| | }q$|S )zDReturn None if there is no clearance, otherwise the clearance value.clearr<   bothNr   )broken_out_of_flow
is_floatedr@   r   r#   r3   margin_heightmax)	r   r   collapsed_marginbroken_shaper7   hypothetical_positionexcluded_shapeyhr   r   r   r)   v   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@   rB   rA   .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@   rB   rR   r   r   r   rU      s
    c                 s   s    | ]
}|j |  V  qd S )N)r#   rI   rR   r   r   r   	<genexpr>   s
    
z#avoid_collisions.<locals>.<genexpr>r<   )r=   rQ   none	directionrtl)r3   r#   border_box_yrA   border_widthrI   border_heightrH   r   r4   content_box_xr%   r&   rJ   minr@   r*   r   LineBoxr,   r+   establishes_formatting_contextr'   )r   r   r   outerr3   r#   	box_width
box_heightcolliding_shapesrT   shape_position_yshape_margin_heightleft_boundsright_boundsmax_left_boundmax_right_boundnew_position_yrB   rD   r   r   r   r?      s   










r?   N)r   )T)__doc__mathr   formatting_structurer   min_maxr   percentr   r   	preferredr	   replacedr
   tabler   r   r:   r2   r)   r?   r   r   r   r   <module>   s    
E
