a
    Qh2$                     @   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 )Nauto)widthr   )boxcontextcontaining_block r   P/var/www/sistema_ama/venv/lib/python3.9/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rV|j	|
  }t||
|f |jdkrtd|_|jdkrd|_|jdkrd|_|jdkrd|_t| |}|dur| j	|7  _	t|tjrt|| n|jdkrt|| | |jr
t| ||
|f t|tjrT|   || |||d||dd	dd

\}}}}}}| | n|t|tjr|| ||||d||d	d	\}}}}}nHt|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   Z	highest_yrA   r"   available_widthr   r   r   r1   X   s    

r1   r   c                 C   sh   d}|j | }| jD ]N}|jd |jd dfv r|j |  }}||| k rt|pTd|| | }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   Zhypothetical_positionZexcluded_shapeyhr   r   r   r(   t   s    

r(   Tc                 C   sh  | j }|r|jn| }|r$| n| }|r8| n| }| dkr`| r`dd|jfS g }|D ]l}	|	j}
|	 }|
|  k r|
| k sn |
||   k r|
| k sn |
|krh|
| || krh|	|	 qhdd |D }dd |D }|
 }|
 |j }|s"||j7 }||j8 }|s.|r|rBtt||}|rVtt||}||| krtdd |D }||kr|}q`qq`|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|}n6|jr|| }n$t|tjs4| s4J || }|| }|s^||j8 }||j8 }|||fS )Nr   c                 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   rK   r   r   r   rN      s   c                 s   s   | ]}|j |  V  qd S )N)r"   rE   rK   r   r   r   	<genexpr>   s   z#avoid_collisions.<locals>.<genexpr>r;   )r<   rJ   none	directionrtl)r2   r"   border_box_yr@   border_widthrE   border_height
is_floatedr   r3   content_box_xr$   r%   rF   minr?   r)   r   LineBoxr+   r*   establishes_formatting_contextr&   )r   r   r   outerr2   r"   Z	box_widthZ
box_heightZcolliding_shapesrM   Zshape_position_yZshape_margin_heightZleft_boundsZright_boundsZmax_left_boundZmax_right_boundnew_position_yrA   rB   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
