3
<W                 @   s   d Z ddlmZ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
    weasyprint.float
    ----------------

    :copyright: Copyright 2011-2014 Simon Sapin and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

    )divisionunicode_literals   )list_marker_layout)handle_min_max_width)resolve_percentagesresolve_position_percentages)shrink_to_fit)table_wrapper_width   )boxesc             C   s   | j dkrt|| |j | _ d S )Nauto)widthr	   )boxcontextcontaining_block r   W/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/layout/float.pyfloat_width   s    
r   c             C   s  ddl m} ddlm} |j|j }}	t|||	f |	dkrJ|j|j  }	t	|||	f |j
dkrhd|_
|jdkrxd|_|jdkrd|_|jdkrd|_t| |}
|
dk	r| j|
7  _t|tjr||dd n|jdkrt|| | |jr t| |||	f t|tjrT| j  || |tdd|d	||dd
	\}}}}}t| | | j| nt|tjsftt| ||}| jj| |S )z/Set the width and position of floating ``box``.r   )block_container_layout) inline_replaced_box_width_heightr   r   N)device_sizeinfF)Zmax_position_yZ
skip_stackr   Zpage_is_emptyabsolute_boxesfixed_boxesZadjoining_margins)Zblocksr   Zinlinesr   r   heightr   
position_yZcontent_box_yr   margin_leftmargin_right
margin_topZmargin_bottomget_clearance
isinstancer   ZBlockReplacedBoxr   Zis_table_wrapperr
   ZBlockBoxZcreate_block_formatting_contextfloatr   Zfinish_block_formatting_contextAssertionErrorfind_float_positionexcluded_shapesappend)r   r   r   r   r   r   r   r   Zcb_widthZ	cb_height	clearance_r   r   r   float_layout   sJ    







r)   c             C   sx   | j r.| j d j}|j|k r.|jd||j  t| ||\}}}|jjdkr\|||j  7 }|j||j ||j  |S )z,Get the right position of the float ``box``.r   r   right)r%   r   	translateavoid_collisionsstyler"   margin_width
position_x)r   r   r   Z	highest_yr0   r   available_widthr   r   r   r$   W   s    
r$   c             C   sh   d}|j | }xT| jD ]J}|jj|jjdfkr|j |j  }}||| k rt|pRd|| | }qW |S )zDReturn None if there is no clearance, otherwise the clearance value.NZbothr   )r   r%   r.   clearr"   margin_heightmax)r   r   Zcollapsed_marginr'   Zhypothetical_positionZexcluded_shapeyhr   r   r   r    s   s    
r    Tc                sT  | j }|r|jn|j |r$|j n|j }|r8|j n|j  |j dkr`|j r`dd|jfS x fdd|D }dd |D }dd |D }|j	 }	|j	 |j }
|s|	|j
7 }	|
|j8 }
|s|r|rtt||	}	|rtt||
}
||
|	 krtdd |D }|kr|qbP qbW |	}|
|	 }|sJ||j
8 }|j8 ||fS )Nr   c                s|   g | ]t}|j   k o&|j |j  k n  st|j     k oN|j |j  k n  st|j kr|j |j    kr|qS r   )r   r3   ).0shape)
box_heightr   r   r   
<listcomp>   s    
z$avoid_collisions.<locals>.<listcomp>c             S   s&   g | ]}|j jd kr|j|j  qS )left)r.   r"   r0   r/   )r7   r8   r   r   r   r:      s   c             S   s   g | ]}|j jd kr|jqS )r*   )r.   r"   r0   )r7   r8   r   r   r   r:      s   c             s   s   | ]}|j |j  V  qd S )N)r   r3   )r7   r8   r   r   r   	<genexpr>   s   z#avoid_collisions.<locals>.<genexpr>)r%   r   Zborder_box_yr/   Zborder_widthr3   Zborder_heightZ
is_floatedr   Zcontent_box_xr   r   r4   minr   )r   r   r   Zouterr%   Z	box_widthZcolliding_shapesZleft_boundsZright_boundsZmax_left_boundZmax_right_boundZnew_positon_yr0   r1   r   )r9   r   r   r-      sH    







r-   N)r   )T)__doc__
__future__r   r   markersr   Zmin_maxr   Zpercentagesr   r   Z	preferredr	   Ztablesr
   Zformatting_structurer   r   r)   r$   r    r-   r   r   r   r   <module>	   s   :
