3
?WF                 @   sB  d Z ddlmZmZ ddlmZmZ ddlmZ ddl	m
Z
 eddZddddddddZedd dD Zdddd Zed! ed ksted"d"d"d#d#d$d$d$d$d%	d&d&d&d&d&d"d"d#d#d%	d'Zeed(d)ed*d)fed*d)ed+d)fed+d)ed,d)fed-d)ed.d)fed.d)ed/d)fed0d1ed2d1fed0d1ed3d1fed2d1ed4d1fd5Zx(ej D ]\ZZejejk sbtqbW ed6 Zed7d eD ed8< d9d: Ze Zi Zd;d< Zd=d> Zed?d@dA ZedBdCdD ZedEdFdG Z edHed8edIdJdK Z!edLedMedNedOedPedQedRedSedTedUedVedWedXedYedZed[ed\ed]ed^ed_ddbdcZ"edddedf Z#edgdhdi Z$edjedkedledmednedodpdq Z%edrdsdt Z&eduedvedwedxdydz Z'ed{d|d} Z(ed~dd~ Z)eddd Z*eddd Z+eddd Z,eddd Z-eddd Z.eddd Z/eddd Z0eddd Z1eddd Z2eddd Z3eddd Z4eddd Z5dddZ6dd Z7d`S )aI  
    weasyprint.css.computed_values
    ------------------------------

    Convert *specified* property values (the result of the cascade and
    inhertance) into *computed* values (that are inherited).

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

    )divisionunicode_literals   )INITIAL_VALUES	Dimension   )get_link_attribute)textpxg      ?g      ?g      0@g      X@gRQ@gffffff9@g      @)r
   ptZpcincmmmqc             c   s(   | ] \}}}|t d  | | fV  qdS )	font_sizeN)r   ).0nameab r   ^/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/css/computed_values.py	<genexpr>+   s   r   xx-small      x-small   small   	   mediumlarge   x-largexx-large)Zthinr    ZthickZborder_top_widthi  i  i  )	d      i,  i  i  iX  i  i   i  r%   )bolderlighter   r      i)  i        ia  g      !@r            )Za5a4a3Zb5Zb4letterZlegalZledgerr0   c             c   s   | ]}|j t|j  V  qd S )N)valueLENGTHS_TO_PIXELSunit)r   dr   r   r   r      s    sizec              C   s>   dddddddg} t t}x| D ]}|j| q W t| | S )z>Some computed values are required by others, so order matters.Zfont_stretchfont_weightZfont_familyZfont_variantZ
font_styler   line_height)sortedr   removetuple)firstorderr   r   r   r   _computing_order   s    

r?   c                s    j dd  fdd}|S )z9Decorator registering a property ``name`` for a function.-_c                s   | t  < | S )z0Register the property ``name`` for ``function``.)COMPUTER_FUNCTIONS)function)r   r   r   	decorator   s    z$register_computer.<locals>.decorator)replace)r   rD   r   )r   r   register_computer   s    rF   c             C   s   |dkrt }dd }| |_||_||_||_||_||_tj}xBt	D ]:}||krRqD|| }	||}
|
dk	rv|
|||	}	|	||< qDW |j
|d< |S )a  
    Return a StyleDict of computed values.

    :param element: The HTML element these style apply to
    :param pseudo_type: The type of pseudo-element, eg 'before', None
    :param specified: a :class:`StyleDict` of specified values. Should contain
                      values for all properties.
    :param computed: a :class:`StyleDict` of already known computed values.
                     Only contains some properties (or none).
    :param parent_values: a :class:`StyleDict` of computed values of the parent
                          element (should contain values for all properties),
                          or ``None`` if ``element`` is the root element.
    Nc               S   s   dS )z#Dummy object that holds attributes.r   r   r   r   r   r   computer   s    zcompute.<locals>.computerZ_weasy_specified_display)r   elementpseudo_type	specifiedcomputedparent_style
root_stylerB   getCOMPUTING_ORDERdisplay)rH   rI   rJ   rK   rL   rM   rG   getterr   r3   rC   r   r   r   compute   s(    

rR   zbackground-imagec                sl   xf|D ]^\}}|dkr. fdd|j D |_ |dkrt |jg\|_|jdkrt |j|_qW |S )z-Compute lenghts in gradient background-image.linear-gradientradial-gradientc                s$   g | ]}|d k	rt  |nd qS )N)length)r   pos)rG   r   r   r   
<listcomp>   s   z$background_image.<locals>.<listcomp>explicit)rS   rT   )Zstop_positionsbackground_positioncenterZ	size_typelength_or_percentage_tupler7   )rG   r   valuestype_r3   r   )rG   r   r   background_image   s    
r^   zbackground-positionc                s    fdd|D S )z'Compute lengths in background-position.c          	      s0   g | ](\}}}}|t  ||t  |fqS r   )rU   )r   Zorigin_xZpos_xZorigin_yZpos_y)rG   r   r   r   rW      s   z'background_position.<locals>.<listcomp>r   )rG   r   r\   r   )rG   r   r   rY      s    rY   ztransform-originc                s   t  fdd|D S )z5Compute the lists of lengths that can be percentages.c             3   s   | ]}t  |V  qd S )N)rU   )r   r3   )rG   r   r   r   r      s    z-length_or_percentage_tuple.<locals>.<genexpr>)r<   )rG   r   r\   r   )rG   r   r   r[      s    r[   zborder-spacingZclipc                s   t  fdd|D S )z.Compute the properties with a list of lengths.c             3   s   | ]}t  |d dV  qdS )T)pixels_onlyN)rU   )r   r3   )rG   r   r   r   r      s   zlength_tuple.<locals>.<genexpr>)r<   )rG   r   r\   r   )rG   r   r   length_tuple   s    r`   toprightleftbottomz
margin-topzmargin-rightzmargin-bottomzmargin-leftheightwidthz	min-widthz
min-heightz	max-widthz
max-heightzpadding-topzpadding-rightzpadding-bottomzpadding-leftztext-indentzhyphenate-limit-zoneNFc             C   s"  |dkr|S |j dkr"|rdS tS |j}|dkr>|r:|j S |S |tkrV|j t|  }n|dkr
|dkrp| jj}|dkr|j | t| j }nz|dkrtjd	|| jd
}|j	d |j
 \}tj|| j\}	}
|j |	 }n.|dkr|j | }n|dkr|j | jd  }n|S |r|S t|dS )zCompute a length ``value``.autor   r
   emexchremNF)hintingr   style0r   )rh   ri   rj   rk   )r3   ZERO_PIXELSr5   r4   rK   r   ex_ratior	   Layoutset_text
iter_linesZget_sizerM   r   )rG   r   r3   r   r_   r5   resultlayoutlineZlogical_widthrA   r   r   r   rU      s8    





rU   zletter-spacingc             C   s    |dkr|S t | ||ddS d S )NnormalT)r_   )rU   )rG   r   r3   r   r   r   pixel_length9  s    rx   zbackground-sizec                s    fdd|D S )z+Compute the ``background-size`` properties.c                s$   g | ]}|dkr|n
t  |qS )containcover)ry   rz   )r[   )r   r3   )rG   r   r   r   rW   D  s   z#background_size.<locals>.<listcomp>r   )rG   r   r\   r   )rG   r   r   background_sizeA  s    r{   zborder-top-widthzborder-right-widthzborder-left-widthzborder-bottom-widthzcolumn-rule-widthzoutline-widthc             C   sL   | j |jdd }|dkrdS |tkr.t| S t|tr<|S t| ||ddS )	z*Compute the ``border-*-width`` properties.rf   rm   nonehiddenr   T)r_   )r|   r}   )rK   rE   BORDER_WIDTH_KEYWORDS
isinstanceintrU   )rG   r   r3   rm   r   r   r   border_widthI  s    
r   zcolumn-widthc             C   s   t | ||ddS )z&Compute the ``column-width`` property.T)r_   )rU   )rG   r   r3   r   r   r   column_width`  s    r   zborder-top-left-radiuszborder-top-right-radiuszborder-bottom-left-radiuszborder-bottom-right-radiusc                s    fdd|D S )z+Compute the ``border-*-radius`` properties.c                s   g | ]}t  |qS r   )rU   )r   r3   )rG   r   r   r   rW   l  s    z!border_radius.<locals>.<listcomp>r   )rG   r   r\   r   )rG   r   r   border_radiusf  s    r   z
column-gapc             C   s"   |dkrt dd}t| ||ddS )z$Compute the ``column-gap`` property.rw   r   rh   T)r_   )r   rU   )rG   r   r3   r   r   r   
column_gapo  s    
r   contentc                s"   |dkr|S  fdd|D S dS )z!Compute the ``content`` property.rw   r|   c                s2   g | ]*\}}|d kr&d j j|dfn||fqS )attrSTRING )rH   rN   )r   r]   r3   )rG   r   r   rW   }  s   zcontent.<locals>.<listcomp>N)rw   r|   r   )rG   r   r\   r   )rG   r   r   w  s    
rP   c             C   sT   | j j}| j j}|dks8|dks8t| jddd  dkrP|dkrDd	S |dkrPdS |S )zdCompute the ``display`` property.

    See http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo

    absolutefixedr|   Z	getparentc               S   s   d S )Nr   r   r   r   r   <lambda>  s    zdisplay.<locals>.<lambda>Nzinline-tabletableinlinetable-row-grouptable-columntable-column-grouptable-header-grouptable-footer-group	table-row
table-celltable-captioninline-blockblock)r   r   )
r   r   r   r   r   r   r   r   r   r   )rJ   floatpositiongetattrrH   )rG   r   r3   Zfloat_r   r   r   r   rP     s      r   c             C   s   | j jdkrdS |S dS )zbCompute the ``float`` property.

    See http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo

    r   r   r|   N)r   r   )rJ   r   )rG   r   r3   r   r   r   compute_float  s    r   z	font-sizec             C   sH   |t krt | S | jd }|jdkr2|j| d S t| ||d|dS dS )z#Compute the ``font-size`` property.r   %g      Y@T)r_   r   N)FONT_SIZE_KEYWORDSrL   r5   r3   rU   )rG   r   r3   Zparent_font_sizer   r   r   r     s    


r   zfont-weightc             C   s>   |dkrdS |dkrdS |d	kr6| j d }t| | S |S dS )
z%Compute the ``font-weight`` property.rw   i  Zboldi  r'   r(   r8   N)r'   r(   )rL   FONT_WEIGHT_RELATIVE)rG   r   r3   Zparent_valuer   r   r   r8     s    
r8   zline-heightc             C   sZ   |dkr|S |j sd|jfS |j dkrB|jd }| jj}|| }nt| ||dd}d|fS )z%Compute the ``line-height`` property.rw   NUMBERr   g      Y@T)r_   ZPIXELS)r5   r3   rK   r   rU   )rG   r   r3   factorZfont_size_valueZpixelsr   r   r   r9     s    



r9   anchorc             C   s$   |dkr |\}}| j j|pdS dS )z Compute the ``anchor`` property.r|   N)rH   rN   )rG   r   r\   rA   keyr   r   r   r     s    linkc             C   s0   |dkrdS |\}}|dkr(t | j|S |S dS )zCompute the ``link`` property.r|   Nr   )r   rH   )rG   r   r\   r]   r3   r   r   r   r     s    langc             C   s<   |dkrdS |\}}|dkr,| j j|p*dS |dkr8|S dS )zCompute the ``lang`` property.r|   Nr   string)rH   rN   )rG   r   r\   r]   r   r   r   r   r     s    ztab-sizec             C   s   t |tr|S t| ||S dS )z"Compute the ``tab-size`` property.N)r   r   rU   )rG   r   r3   r   r   r   tab_size  s    
r   	transformc             C   s<   g }x2|D ]*\}}|dkr&t | ||}|j||f q
W |S )z#Compute the ``transform`` property.	translate)r[   append)rG   r   r3   rt   rC   argsr   r   r   r     s    zvertical-alignc             C   sn   |dkr|S |dkr | j jd S |d	kr4| j jd S |jd
krZt| j \}}||j d S t| ||ddS dS )z(Compute the ``vertical-align`` property.baselinemiddletext-toptext-bottomra   rd   superg      ?subr   g      Y@T)r_   N)r   r   r   r   ra   rd   g      )rK   r   r5   strut_layoutr3   rU   )rG   r   r3   re   rA   r   r   r   vertical_align	  s    
r   zword-spacingc             C   s    |dkrdS t | ||ddS dS )z&Compute the ``word-spacing`` property.rw   r   T)r_   N)rU   )rG   r   r3   r   r   r   word_spacing  s    r   Tc             C   sx   | j }| jdkrd }}n tjd| |ddd\}}}}}}|dkrJ||fS |\}}|dkrd|| j9 }|||| d  fS )zReturn a tuple of the used value of ``line-height`` and the baseline.

    The baseline is given from the top edge of line height.

    r   r   N)rl   	max_width
line_widthrw   r   r   )r9   r   r	   Zsplit_first_line)rm   rl   r9   Zpango_heightr   rA   r]   r3   r   r   r   r   %  s    


r   c             C   sJ   d}t jd|| d}|jd |j \}t j|\}}t| | dpHdS )z9Return the ratio 1ex/font_size, according to given style.i  F)rl   r   rm   xr   g      ?)r	   rq   rr   rs   Zget_ink_positionround)rm   r   ru   rv   rA   Zink_height_above_baseliner   r   r   rp   ;  s    

rp   gUUUUUU?g\.B@gx<@gx<@gx<?r   r   r   r   r   r   r   r   r   r    r   r   r!   r"   r   r#   r   r   r$   r   r   )r   r   r   r   r   r   r   )NF)T)8__doc__
__future__r   r   Z
propertiesr   r   Zurlsr   r   r	   ro   r4   dictr   r~   AssertionErrorr   Z
PAGE_SIZESr\   whr3   ZINITIAL_PAGE_SIZEr<   r?   rO   rB   rF   rR   r^   rY   r[   r`   rU   rx   r{   r   r   r   r   r   rP   r   r   r8   r9   r   r   r   r   r   r   r   r   rp   r   r   r   r   <module>   s   
      







	5	2'		
