a
    ¥Q•h2$  ã                   @   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r„d|_|jdkr”d|_|jdkr¤d|_t| |ƒ}|durÄ| j	|7  _	t|tjƒrÜt||ƒ n|jdkròt|| |ƒ |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ƒ�sÌJ ‚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 sÊn |
||   k r°|
| k sÊn |
|krh|
| || krh| 	|	¡ qhdd„ |D ƒ}dd„ |D ƒ}| 
¡ }| 
¡ |j }|�s"||j7 }||j8 }|�s.|�rŒ|�rBtt|ƒ|ƒ}|�rVtt|ƒ|ƒ}||| k�rŒtdd„ |D ƒƒ}||k�rŒ|}q`�qŒq`|jd dv �sÎt|tjƒ�sÎ|j�sÎt|tjƒ�sÎ| ¡ �sÎJ ‚|}|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
