3
VmW#                 @   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	 ddl
mZ dd	lmZ ed
dZeddZdd Zdd Zdd Zdd Zdd Zdd ZdS )z
    weasyprint.backgrounds
    ----------------------

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

    )divisionunicode_literals)
namedtuple)cycle   )boxes   )replaced)resolve_radii_percentages
Backgroundzcolor, layers, image_renderingBackgroundLayerzXimage, size, position, repeat, unbounded, painting_area, positioning_area, clipped_boxesc             C   st   |dkr$| j  | j | j | j fS |dkrH| j | j | j | j fS |dksXt|| j	 | j
 | j| jfS d S )Nz
border-boxzpadding-boxzcontent-box)border_box_xborder_box_yborder_widthborder_heightZpadding_box_xZpadding_box_yZpadding_widthZpadding_heightAssertionErrorZcontent_box_xZcontent_box_ywidthheight)boxZwhich_rectangle r   ]/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/layout/backgrounds.pybox_rectangle   s    

r   c                s   t   x j D ]}t| qW  jjdkr@d _dS fddjD }jd}|jdkr|t	| r|d _dS t
|j fddt|fttjjjjjjg D d _dS )	z%Fetch and position background images.ZhiddenNc                s$   g | ]\}}|d kr |n|qS )urlr   ).0type_value)get_image_from_urir   r   
<listcomp>B   s   z*layout_box_backgrounds.<locals>.<listcomp>Zbackground_colorr   c                s    g | ]}t  jf| qS r   )layout_background_layerZimage_resolution)r   Zlayer)r   pagestyler   r   r   K   s   )colorimage_renderinglayers)r
   Zall_childrenlayout_box_backgroundsr    Z
visibility
backgroundZbackground_imageZ	get_coloralphaanyr   r"   zipmapr   Zbackground_sizeZbackground_clipZbackground_repeatZbackground_originZbackground_positionZbackground_attachment)r   r   r   childZimagesr!   r   )r   r   r   r    r   r$   5   s.    




r$   c             C   s<   | dkr| S | j dkr| jS | j dks*t|| j d S dS )z>Return the evaluated percentage value, or the value unchanged.autoZpx%d   N)Zunitr   r   )r   Zrefer_tor   r   r   
percentageU   s    
r.   c
       +   
   C   s  g }
d}| |kr2dd|j  |j f}| j g}
nt| tjrg }
d}xB| jD ]8}|jrN|
dd |jD 7 }
t|tdd |jD }qNW | j | j	 | j | j
  |g}n"t| tjr| jrdd | jD }
tdd | jD }| j | j	 | j | j
  | j	 | g}nt| tjtjfr~| j }|rdd |D }
td	d |D }| j | j	 || j  | j	 | j  g}nRt| |}|d
kr| j g}
n2|dkr| j g}
n|dkst|| j g}
|d ksd|jddkrtd | |k|dddd|
dS |	dkrt|d}n
t| |}|\}}}}|\}}}}|dkr`tj|||j\}}nd|dkrtj|||j\}}nD|\}}|j|| jj\}}tj|||jt||t||||\}}|\} }!}"}#|| }$|| }%t|!|$}!t|#|%}#| dkr|$|! }!|"dkr|%|# }#|\}&}'|&dkrptdt|| }(||( })d}!|'dkrl|d dkrl||)| 9 }|)}|'dkrtdt|| }(||( }*d}#|&dkr|d dkr||*| 9 }|*}t|||f|!|#f|| |k|||
dS )Nr   c             S   s   g | ]}|j  qS r   )rounded_border_box)r   cellr   r   r   r   p   s    z+layout_background_layer.<locals>.<listcomp>c             s   s   | ]}|j  |j  V  qd S )N)r   r   )r   r0   r   r   r   	<genexpr>r   s   z*layout_background_layer.<locals>.<genexpr>c             S   s   g | ]}|j  qS r   )r/   )r   r0   r   r   r   r   z   s    c             s   s   | ]}|j  V  qd S )N)r   )r   r0   r   r   r   r1   |   s    c             S   s   g | ]}|j  qS r   )r/   )r   r0   r   r   r   r      s    c             s   s   | ]}|j  |j  V  qd S )N)r   r   )r   r0   r   r   r   r1      s   z
border-boxzpadding-boxzcontent-boxr   Zunused)image	unboundedpainting_areasizepositionrepeatpositioning_areaclipped_boxesZfixedZcoverZcontainrightZbottomroundr+   )r2   r5   r6   r7   r3   r4   r8   r9   )r   r   r   r   )Zmargin_widthZmargin_heightr/   
isinstancer   ZTableRowGroupBoxchildrenmaxr   r   r   ZTableRowBoxZTableColumnGroupBoxZTableColumnBoxZ	get_cellsr   r   Zrounded_padding_boxr   Zrounded_content_boxZget_intrinsic_sizer   r	   Zcover_constraint_image_sizingZintrinsic_ratioZcontain_constraint_image_sizingr    Z	font_sizeZdefault_image_sizingr.   r;   )+r   r   
resolutionr2   r5   Zclipr7   originr6   
attachmentr9   r4   Ztotal_heightrowr   cellsZmax_xr8   Zpositioning_xZpositioning_yZpositioning_widthZpositioning_heightZ
painting_xZ
painting_yZpainting_widthZpainting_heightZimage_widthZimage_heightZ
size_widthZsize_heightZiwidthZiheightZorigin_xZ
position_xZorigin_yZ
position_yZref_xZref_yZrepeat_xZrepeat_yZ	n_repeatsZ	new_widthZ
new_heightr   r   r   r   `   s    

















r   c                s   t | jd tj st| jd }|}|jj dkrb|jdkrbx"|jD ]}|jj dkrF|}P qFW |jrt| d |jj	 fdd|jj
D d| _d|_nd| _dS )	zSet a ``canvas_background`` attribute on the PageBox,
    with style for the canvas background, taken from the root elememt
    or a <body> child of the root element.

    See http://www.w3.org/TR/CSS21/colors.html#background

    r   htmlNbodyzpadding-boxc                s   g | ]}|j  d qS ))r4   )_replace)r   l)r4   r   r   r      s   z)set_canvas_background.<locals>.<listcomp>)r#   )r<   r=   r   Z	MarginBoxr   Zelement_taglowerr%   r   rF   r#   Zcanvas_background)r   Zroot_boxZ
chosen_boxr*   r   )r4   r   set_canvas_background   s    


rI   c             C   s   t | | | t|  d S )N)r$   rI   )r   r   r   r   r   layout_backgrounds   s    rJ   N)__doc__
__future__r   r   collectionsr   	itertoolsr   Zformatting_structurer    r	   Zpercentagesr
   r   r   r   r$   r.   r   rI   rJ   r   r   r   r   <module>	   s    
 }