a
    [Xh2$                     @   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   \/var/www/viveiro_mudafortebrasil/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_boxesZadjoining_marginsdiscard	max_lines)r   r   r   r   r   r   r   )r   r   r   r   r   r   ) blockr   Zflexr   Zgridr   r   heightr   
position_yZcontent_box_yr   margin_leftmargin_right
margin_topZmargin_bottomget_clearance
isinstancer   BlockReplacedBoxr   r   is_table_wrapperr	   ZBlockContainerBoxZcreate_block_formatting_contextZfinish_block_formatting_contextZFlexContainerBoxZGridContainerBoxfind_float_positionexcluded_shapesappend)r   r   r   r   r   r   r   r   r   r   Zcb_widthZ	cb_height	clearanceZ	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)r(   r   	translateavoid_collisionsstylemargin_width
position_x)r   r   r   Z	highest_yr4   r   available_widthr   r   r   r'   X   s    

r'   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.   Zbothr   )r   r(   r2   margin_heightmax)r   r   Zcollapsed_marginr*   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)r2   r4   r3   .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/   )r2   r4   r<   r   r   r   r?      s   c                 s   s   | ]}|j |  V  qd S )N)r   r7   r<   r   r   r   	<genexpr>   s   z#avoid_collisions.<locals>.<genexpr>r.   )r/   r;   none	directionrtl)r(   r   Zborder_box_yr3   Zborder_widthr7   Zborder_heightZ
is_floatedr   r)   Zcontent_box_xr    r!   r8   minr2   r$   r   ZLineBoxr&   r%   Zestablishes_formatting_contextr"   )r   r   r   outerr(   r   Z	box_widthZ
box_heightZcolliding_shapesr>   Zshape_position_yZshape_margin_heightZleft_boundsZright_boundsZmax_left_boundZmax_right_boundZnew_position_yr4   r5   r   r   r   r1      s    









r1   N)r   )T)__doc__Zformatting_structurer   Zmin_maxr   percentr   r   	preferredr   Zreplacedr   tabler	   r   r,   r'   r#   r1   r   r   r   r   <module>   s   
E
