a
    [Xhj                     @   s  d 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
mZmZ ddlmZmZ dd	lmZ d
dlmZmZmZ d
dlmZmZmZmZ dd dD Zd
dddZed ed ksJ dddddddddd	dddddddddd	dZdd dD Zedd e  D sJ ed Z!e"d d e!D ed!< i Z#dd#d$Z$d%d& Z%d'd( Z&e%d)d*d+ Z'e%d,e%d-d.d/ Z(e%d0d1d2 Z)e%d3e%d!e%d4d5d6 Z*e%d7e%d8d9d: Z+e%d;e%d<e%d=e%d>e%d?e%d@e%dAe%dBe%dCe%dDe%dEe%dFe%dGe%dHe%dIe%dJe%dKe%dLe%dMe%dNe%dOe%dPe%dQddSdTZ,e%dUe%dVe%dWe%dXdYdZ Z-e%d[d\d] Z.e%d^d_d` Z/e%dadbdc Z0e%dde%dee%dfe%dge%dhe%didjdk Z1e%dle%dmdndo Z2e%dpe%dqdrds Z3e%dte%dudvdw Z4e%dxe%dydzd{ Z5e%d|e%d}d~d Z6e%de%de%de%ddd Z7e%de%ddd Z8dd Z9e%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 Z@dd ZAdd ZBe%de%ddd ZCe%de%ddd ZDe%ddd ZEe%ddd ZFe%ddd ZGe%ddd ZHe%ddd ZIe%ddd ZJe%ddd ZKe%ddd ZLdddZMdd ZNdRS )z7Convert specified property values into computed values.    )pi)unquote)parse_color   )LOGGER)
FROM_UNITSffipango)Layoutfirst_line_metrics)get_link_attribute   )INITIAL_VALUESZERO_PIXELS	Dimension)ANGLE_TO_RADIANSLENGTH_UNITSLENGTHS_TO_PIXELSsafe_urljoinc                 C   s   i | ]\}}|t d  | qS )	font_size)r   ).0namefactor r   c/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/weasyprint/css/computed_values.py
<dictcomp>   s   r   ))zxx-smallg333333?)zx-smallg      ?)smallgqq?)mediumr   )Zlarge333333?)zx-largeg      ?)zxx-larger         )Zthinr   ZthickZborder_top_widthr         )	d      i,  r!     iX  r"   i   r#   r$   ZbolderZlighterc                 C   s*   i | ]"\}}}}|t ||t ||fqS r   )r   )r   Z	page_sizewidthheightunitr   r   r   r   D   s   
)/)Za10   %   mm)Za9r,   4   r-   )Za8r.   J   r-   )Za7r/   i   r-   )Za6r0      r-   )Za5r1      r-   )a4r2   )  r-   )a3r4     r-   )Za2r6   R  r-   )Za1r7   I  r-   )Za0r8   i  r-   )Zb10   ,   r-   )Zb9r:   >   r-   )Zb8r;   X   r-   )Zb7r<   }   r-   )Zb6r=      r-   )Zb5r>      r-   )Zb4r?   a  r-   )Zb3r@   r&   r-   )b2r&     r-   )b1rB     r-   )Zb0rD   i  r-   )Zc10   (   r-   )Zc9rF   9   r-   )Zc8rG   Q   r-   )Zc7rH   r   r-   )Zc6rI      r-   )Zc5rJ      r-   )Zc4rK   D  r-   )c3rL     r-   )c2rN     r-   )Zc1rP     r-   )Zc0rQ   i  r-   )zjis-b10    -   r-   )zjis-b9rS   @   r-   )zjis-b8rT   [   r-   )zjis-b7rU      r-   )zjis-b6rV      r-   )zjis-b5rW     r-   )zjis-b4rX   l  r-   )zjis-b3rY     r-   )zjis-b2rZ     r-   )zjis-b1r[     r-   )zjis-b0r\   i  r-   )letter      !@   in)Zlegalr^      r`   )Zledgerr_      r`   c                 c   s   | ]\}}|j |j k V  qd S N)value)r   r(   r)   r   r   r   	<genexpr>y       re   r3   c                 c   s   | ]}|j t|j  V  qd S rc   )rd   r   r*   )r   sizer   r   r   re   |   s   rg   Fc                 C   s   t | d | d | d | d | d | d | d | d | d	 | d
 | d | d | d | d f}|r||t | d t | d  7 }|S )NZfont_familyZ
font_styleZfont_stretchfont_weightZfont_variant_ligaturesZfont_variant_positionZfont_variant_capsZfont_variant_numericZfont_variant_alternatesZfont_variant_east_asianZfont_feature_settingsZfont_variation_settingsZfont_language_overridelangr   line_heightstr)styleinclude_sizekeyr   r   r   _font_style_cache_key   s&    rp   c                    s     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   rv   r   ru   r   register_computer   s    rx   c                 C   s6  |\}}|dksJ |\}}}z| j ||}|dkr8n|dkrr|dr`dt|dd  f}ndt| j|f}n|dkrt| }n|d	krt| }nv|d
krt	| }n`|dkrt
t	| d}d}n@|tv rt
t	| |}d}n |tv rt
t	| |}d}W n ty,   Y d S 0 ||fS )Nattr()stringurl#Zinternalr   Zexternalcolorintegernumber%lengthangle)elementget
startswithr   r   base_urlr   stripintfloatr   r   r   	Exception)rm   values	func_namerd   	attr_nameZtype_or_unitfallback
attr_valuer   r   r   compute_attr   s<    


r   zbackground-imagec                    sl   |D ]b\}}|dv r0t  fdd|jD |_|dkrt |jf\|_|jdkrt |j|_q|S )z-Compute lenghts in gradient background-image.)zlinear-gradientradial-gradientc                 3   s&   | ]}|d urt  |nd V  qd S rc   r   )r   posr   rm   r   r   re      s   z#background_image.<locals>.<genexpr>r   explicit)tupleZstop_positionscompute_positioncenterZ	size_typelength_or_percentage_tuplerg   rm   r   r   type_rd   r   r   r   background_image   s    


r   zbackground-positionzobject-positionc                    s   t  fdd|D S )z'Compute lengths in background-position.c                 3   s2   | ]*\}}}}|t  ||t  |fV  qd S rc   r   )r   Zorigin_xZpos_xZorigin_yZpos_yr   r   r   re      s   
z#compute_position.<locals>.<genexpr>r   rm   r   r   r   r   r   r      s    r   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 rc   r   r   rd   r   r   r   re      rf   z-length_or_percentage_tuple.<locals>.<genexpr>r   r   r   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_onlyNr   r   r   r   r   re      s   zlength_tuple.<locals>.<genexpr>r   r   r   r   r   length_tuple   s    r   zbreak-afterzbreak-beforec                 C   s   |dkrdS |S )z<Compute the ``break-before`` and ``break-after`` properties.alwayspager   rm   r   rd   r   r   r   break_before_after   s    r   toprightleftbottomz
margin-topzmargin-rightzmargin-bottomzmargin-leftr)   r(   z	min-widthz
min-heightz	max-widthz
max-heightzpadding-topzpadding-rightzpadding-bottomzpadding-leftztext-indentzhyphenate-limit-zonez
flex-basisztext-underline-offsetztext-decoration-thicknessNc                 C   s   |dv r|S |j dkr"|rdS tS |j}|dkr>|r:|j S |S |tv rV|j t|  }n|dv r|du rn| d }|dkrt| d}|j | | }q|d	krt| d
}|j | | }q|dkr|j | }q|dkr|j | jd  }n|S |r|S t|dS )zCompute a length ``value``.)autocontentz	from-fontr   px)emexchremNr   r   xr   0r   r   )rd   r   r*   r   character_ratioZ
root_styler   )rm   r   rd   r   r   r*   resultratior   r   r   r      s0    


r   z
bleed-leftzbleed-rightz	bleed-topzbleed-bottomc                 C   s2   |dkr"t d| d v rdnddS t| ||S d S )Nr   ZcropZmarks   r   r   )r   r   r   r   r   r   bleed2  s    r   zletter-spacingc                 C   s    |dkr|S t | ||ddS d S )NnormalTr   r   r   r   r   r   pixel_length=  s    r   zbackground-sizec                    s   t  fdd|D S )z+Compute the ``background-size`` properties.c                 3   s&   | ]}|d v r|n
t  |V  qdS ))ZcontainZcoverN)r   r   r   r   r   re   H  s   z"background_size.<locals>.<genexpr>r   r   r   r   r   background_sizeE  s    r   zimage-orientationc                 C   s0   |dv r|S |\}}t |t d d d |fS )z-Compute the ``image-orientation`` properties.)nonez
from-imager      Z   )roundr   )rm   r   r   r   Zflipr   r   r   image_orientationN  s    r   zborder-top-widthzborder-right-widthzborder-left-widthzborder-bottom-widthzcolumn-rule-widthzoutline-widthc                 C   sJ   | | dd }|dv rdS |tv r,t| S t|tr:|S t| ||ddS )z*Compute the ``border-*-width`` properties.r(   rm   )r   hiddenr   Tr   )rw   BORDER_WIDTH_KEYWORDS
isinstancer   r   )rm   r   rd   Zborder_styler   r   r   border_widthW  s    
r   zborder-image-slicezmask-border-slicec                 C   s   g }d}|D ]>}|dkr|}q|\}}|du r:| | q| t|d qt|dkrb|d9 }n0t|dkrx|d9 }nt|dkr| |d  g ||R S )z,Compute the ``border-image-slice`` property.Nfillr   r   r   r   r   )appendr   len)rm   r   r   computed_valuesr   rd   r   r*   r   r   r   border_image_slicen  s     

r   zborder-image-widthzmask-border-widthc                 C   s   g }|D ]6}|dkr | | q|\}}| |du r8|n| qt|dkrV|d9 }n0t|dkrl|d9 }nt|dkr| |d  t|S )z,Compute the ``border-image-width`` property.r   Nr   r   r   r   )r   r   r   )rm   r   r   r   rd   r   r*   r   r   r   border_image_width  s    

r   zborder-image-outsetzmask-border-outsetc                    sb    fdd|D }t |dkr*|d9 }n0t |dkr@|d9 }nt |dkrZ||d  t|S )z-Compute the ``border-image-outset`` property.c                    s*   g | ]"}t |ttfr|n
t |qS r   )r   r   r   r   r   r   r   r   
<listcomp>  s   z'border_image_outset.<locals>.<listcomp>r   r   r   r   )r   r   r   )rm   r   r   r   r   r   r   border_image_outset  s    

r   zborder-image-repeatzmask-border-repeatc                 C   s   t |dkr|d S |S )z-Compute the ``border-image-repeat`` property.r   r   )r   r   r   r   r   border_image_repeat  s    r   zcolumn-widthzoutline-offsetc                 C   s   t | ||ddS )z Compute a pixel length property.Tr   r   r   r   r   r   length_pixels_only  s    r   zborder-top-left-radiuszborder-top-right-radiuszborder-bottom-left-radiuszborder-bottom-right-radiusc                    s   t  fdd|D S )z+Compute the ``border-*-radius`` properties.c                 3   s   | ]}t  |V  qd S rc   r   r   r   r   r   re     rf   z border_radius.<locals>.<genexpr>r   r   r   r   r   border_radius  s    r   z
column-gapzrow-gapc                 C   s   |dkr|S t | ||S )z!Compute the ``*-gap`` properties.r   r   r   r   r   r   gap  s    r   c              	   C   s   g }|D ]}|d dv r|}n|d dkrJ|d d dks>J t | |}nr|d dv r\|}n`|d dv r|d d }|d dkrt | |}|d u rd }q|d |f|d dd   f}n|}|d u rtd| jd	d
d |D f  q|| qt|S )Nr   )rz   r   r{   quotezleader()ry   r   rz   )z	counter()z
counters()z	content()z	element()zstring())ztarget-counter()ztarget-counters()ztarget-text()z*Unable to compute %r value for content: %rz, c                 s   s   | ]}t |V  qd S rc   rk   )r   itemr   r   r   re     rf   z _content_list.<locals>.<genexpr>)r   r   warningr   joinr   r   )rm   r   r   rd   Zcomputed_valueZanchor_tokenattrr   r   r   _content_list  s.    
 
r   zbookmark-labelc                 C   s
   t | |S )z(Compute the ``bookmark-label`` property.r   r   r   r   r   bookmark_label  s    r   z
string-setc                    s   t  fdd|D S )z$Compute the ``string-set`` property.c                 3   s$   | ]}|d  t  |d fV  qdS )r   r   Nr   )r   
string_setrm   r   r   re     s   zstring_set.<locals>.<genexpr>r   r   r   r   r   r     s    r   r   c                 C   s>   t |dkr4|\}|dkr(| jr$dS dS |dkr4dS t| |S )z!Compute the ``content`` property.r   r   Zinhibitcontentsr   )r   Zpseudo_typer   )rm   r   r   rd   r   r   r   r     s    displayc                 C   st   | j d }| j d }|dv s*|dks*| jrp|dkr6dS t|dkrT|d d	rTd
S |d dkrpd|v rldS d
S |S )z!Compute the ``display`` property.r   positionabsolutefixedr   )zinline-table)blocktabler   r   ztable-)r   flowinline	list-item)r   r   r   )	specifiedZis_root_elementr   r   )rm   r   rd   Zfloat_r   r   r   r   r     s    

r   c                 C   s*   | j d }|dv s|d dkr"dS |S dS )zCompute the ``float`` property.r   r   r   z	running()r   N)r   )rm   r   rd   r   r   r   r   compute_float  s    
r   z	font-sizec                 C   s   |t v rt | S tt  }| jdu r0td }n
| jd }|dkrpt|D ]\}}||krJ||   S qJ|d S |dkrt|ddd D ]"\}}||k r|| d    S q|d S |jd	kr|j| d
 S t| ||d|dS dS )z#Compute the ``font-size`` property.Nr   Zlargerr   Zsmallerr   g?r   r$   T)r   r   )	FONT_SIZE_KEYWORDSlistr   parent_styler   	enumerater*   rd   r   )rm   r   rd   Zkeyword_valuesZparent_font_sizeiZkeyword_valuer   r   r   r   '  s,    



r   zfont-weightc                 C   sR   |dkrdS |dkrdS |dv rJ| j du r4td }n
| j d }t| | S |S dS )z%Compute the ``font-weight`` property.r   r!   Zboldr"   r'   Nrh   )r   r   FONT_WEIGHT_RELATIVE)rm   r   rd   Zparent_valuer   r   r   rh   G  s    


rh   c                 C   s4   |dv r|S t |tr0|jdkr$|S t| ||S dS )zCompute track breadth.)r   zmin-contentzmax-contentfrN)r   r   r*   r   r   r   r   r   _compute_track_breadthX  s    

r   c              
   C   s   g }t |D ]\}}|d dkr,|| qt| ||}|rH|| q|d dkr~|dt| ||d t| ||d f q|d dkr|dt| ||d f q|d dkr|d|d t| ||d f qt|S )zCompute track size.r   r   minmax()r   fit-content()zrepeat())r   r   r   r   _track_sizer   )rm   r   r   return_valuesr   rd   track_breadthr   r   r   r   c  s,    r   zgrid-template-columnszgrid-template-rowsc                 C   s(   |dks|d dkr|S t | ||S dS )z+Compute the ``grid-template-*`` properties.r   r   ZsubgridN)r   r   r   r   r   grid_template}  s    r   zgrid-auto-columnszgrid-auto-rowsc              
   C   s   g }|D ]}t | ||}|r(|| q|d dkrj|dt| ||d gd t| ||d gd f q|d dkr|dt| ||d gd f qt|S )z'Compute the ``grid-auto-*`` properties.r   r   r   r   r   )r   r   	grid_autor   )rm   r   r   r   rd   r   r   r   r   r     s    r   zline-heightc                 C   sZ   |dkr|S |j sd|jfS |j dkrB|jd }| d }|| }nt| ||dd}d|fS )	z%Compute the ``line-height`` property.r   NUMBERr   r$   r   Tr   ZPIXELS)r*   rd   r   )rm   r   rd   r   Zfont_size_valueZpixelsr   r   r   rj     s    



rj   anchorc                 C   s(   |dkr$|\}}| j |pd}|S dS )z Compute the ``anchor`` property.r   Nr   r   )rm   r   r   rr   ro   Zanchor_namer   r   r   r     s    linkc                 C   s4   |dkrdS |\}}|dkr,t | j|| jS |S dS )zCompute the ``link`` property.r   Nry   )r   r   r   r   r   r   r   r     s    ri   c                 C   s<   |dkrdS |\}}|dkr,| j |p*dS |dkr8|S dS )zCompute the ``lang`` property.r   Nry   rz   r   )rm   r   r   ro   r   r   r   ri     s    ztab-sizec                 C   s   t |tr|S t| ||S )z"Compute the ``tab-size`` property.)r   r   r   r   r   r   r   tab_size  s    r   	transformc                 C   s<   g }|D ]*\}}|dkr$t | ||}|||f qt|S )z#Compute the ``transform`` property.	translate)r   r   r   )rm   r   rd   r   rt   argsr   r   r   r     s    zvertical-alignc                 C   sl   |dv r|S |dkr | d d S |dkr4| d d S |j dkrXt| \}}||j d S t| ||d	d
S dS )z(Compute the ``vertical-align`` property.)baselineZmiddleztext-topztext-bottomr   r   superr         ?subg      r   r$   Tr   N)r*   strut_layoutrd   r   )rm   r   rd   r)   rr   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.r   r   Tr   Nr   r   r   r   r   word_spacing  s    r  c                 C   s   | d dkrdS |r4t | dd}||jv r4|j| S t|| }|d | \}}t|d|dd	| d
\}}}}}}| d dkr||f}|r||j|< |S | d \}	}
|	dkr|
| d 9 }
|
||
| d  f}|r||j|< |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   )r   r   T)rn     NF)Z	resume_atZspace_collapserm   rj   r   r   r   )rp   Zstrut_layoutsr
   set_textget_first_liner   )rm   contextro   layoutlinerr   Ztext_heightr   r   r   rj   r   r   r   r    s0    





r  c                 C   s   |dv sJ | j d|dkrdnd  }t| }||v r@|| S |  } d| d< d| d	< d
| d< td| d}|| | \}}td}td}t	||| |dkr|j
 t }	n
|jt }	t| t| t|	| d  dpd}
|
||< |
S )z3Return the ratio of 1ex/font_size or 1ch/font_size.)r   r   Zratio_r   r   r   r   Zletter_spacingr   r  rD   r   N)r  rm   zPangoRectangle *r    r  )cacherp   copyr
   r	  r
  r   newr	   Zpango_layout_line_get_extentsyr   r(   releaser   )rm   	characterr  	cache_keyr  r  rr   Zink_extentsZlogical_extentsZmeasurer   r   r   r   r     s.    





r   )F)NF)N)O__doc__mathr   urllib.parser   Ztinycss2.color4r   loggerr   Ztext.ffir   r   r	   Ztext.line_breakr
   r   urlsr   Z
propertiesr   r   r   utilsr   r   r   r   r   r   r   Z
PAGE_SIZESallr   ZINITIAL_PAGE_SIZEr   rs   rp   rx   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   rh   r   r   r   r   rj   r   r   ri   r   r   r  r  r  r   r   r   r   r   <module>   sT  5
#

8"


#

















!