a
    ¥Q•h¥j  ã                   @   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s¾J ‚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#dÃd#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ƒdÄdSdT„ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ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ƒƒd„d…„ ƒƒƒƒZ7e%d†ƒe%d‡ƒdˆd‰„ ƒƒZ8dŠd‹„ Z9e%dŒƒd�dŽ„ ƒZ:e%d�ƒd�d‘„ ƒZ;e%d’ƒd“d’„ ƒZ<e%d”ƒd•d”„ ƒZ=e%d–ƒd—d˜„ ƒZ>e%d™ƒdšd›„ ƒZ?e%dœƒd�dž„ ƒZ@dŸd „ ZAd¡d¢„ ZBe%d£ƒe%d¤ƒd¥d¦„ ƒƒZCe%d§ƒe%d¨ƒd©dª„ ƒƒZDe%d«ƒd¬d­„ ƒZEe%d®ƒd¯d®„ ƒZFe%d°ƒd±d°„ ƒZGe%d²ƒd³d²„ ƒZHe%d´ƒdµd¶„ ƒZIe%d·ƒd¸d·„ ƒZJe%d¹ƒdºd»„ ƒZKe%d¼ƒd½d¾„ ƒZLdÅd¿dÀ„ZMdÁdÂ„ 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   úW/var/www/sistema_ama/venv/lib/python3.9/site-packages/weasyprint/css/computed_values.pyÚ
<dictcomp>   s   ÿr   ))zxx-smallg333333ã?)zx-smallg      è?)ÚsmallgÇqÇqì?)Úmediumr   )Úlargeç333333ó?)zx-largeg      ø?)zxx-larger   é   é   )Zthinr   ZthickÚ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   Ú	page_sizeÚwidthÚheightÚunitr   r   r   r   D   s   
ÿ)/)Úa10é   é%   Úmm)Úa9r0   é4   r1   )Úa8r3   éJ   r1   )Úa7r5   éi   r1   )Úa6r7   é”   r1   )Úa5r9   éÒ   r1   )Úa4r;   é)  r1   )Úa3r=   é¤  r1   )Úa2r?   éR  r1   )Úa1rA   éI  r1   )Úa0rC   i¥  r1   )Zb10é   é,   r1   )Zb9rF   é>   r1   )Zb8rG   éX   r1   )Zb7rH   é}   r1   )Zb6rI   é°   r1   )Zb5rJ   éú   r1   )Úb4rK   éa  r1   )Úb3rM   r(   r1   )Úb2r(   éÃ  r1   )Úb1rP   éè  r1   )Úb0rR   i†  r1   )Zc10é   é(   r1   )Zc9rU   é9   r1   )Zc8rV   éQ   r1   )Zc7rW   ér   r1   )Zc6rX   é¢   r1   )Úc5rY   éå   r1   )Úc4r[   éD  r1   )Úc3r]   éÊ  r1   )Úc2r_   éˆ  r1   )Úc1ra   é•  r1   )Úc0rc   i  r1   )zjis-b10é    é-   r1   )zjis-b9rf   é@   r1   )zjis-b8rg   é[   r1   )zjis-b7rh   é€   r1   )zjis-b6ri   é¶   r1   )zjis-b5rj   é  r1   )zjis-b4rk   él  r1   )zjis-b3rl   é  r1   )zjis-b2rm   éØ  r1   )zjis-b1rn   é  r1   )zjis-b0ro   i°  r1   )Úletterç      !@é   Úin)Úlegalrq   é   rs   )Zledgerrr   é   rs   c                 c   s   | ]\}}|j |j k V  qd S ©N)Úvalue)r   r+   r,   r   r   r   Ú	<genexpr>y   ó    ry   r<   c                 c   s   | ]}|j t|j  V  qd S rw   )rx   r   r-   )r   Úsizer   r   r   ry   |   s   r{   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 )NÚfont_familyÚ
font_styleÚfont_stretchÚfont_weightÚfont_variant_ligaturesÚfont_variant_positionÚfont_variant_capsÚfont_variant_numericÚfont_variant_alternatesÚfont_variant_east_asianÚfont_feature_settingsÚfont_variation_settingsÚfont_language_overrideÚlangr   Úline_height©Ústr)ÚstyleÚinclude_sizeÚkeyr   r   r   Ú_font_style_cache_key„   s&    òr�   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   r–   r   r•   r   Úregister_computerš   s    r˜   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rˆt| ¡ ƒ}nŒ|d	kržt| ¡ ƒ}nv|d
kr´t	| ¡ ƒ}n`|dkrÔt
t	| ¡ ƒdƒ}d}n@|tv rôt
t	| ¡ ƒ|ƒ}d}n |tv �rt
t	| ¡ ƒ|ƒ}d}W n t�y,   Y d S 0 ||fS )Núattr()ÚstringÚurlú#Úinternalr   ÚexternalÚcolorÚintegerÚnumberú%ÚlengthÚangle)ÚelementÚgetÚ
startswithr   r   Úbase_urlr   ÚstripÚintÚfloatr   r   r   Ú	Exception)r�   ÚvaluesÚ	func_namerx   Ú	attr_nameÚ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 rw   ©r£   )r   Úpos©r   r�   r   r   ry   Í   s   ÿz#background_image.<locals>.<genexpr>r´   Úexplicit)ÚtupleZstop_positionsÚcompute_positionÚcenterZ	size_typeÚlength_or_percentage_tupler{   ©r�   r   r­   Útype_rx   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 rw   rµ   )r   Zorigin_xÚpos_xZorigin_yÚpos_yr·   r   r   ry   Ý   s   
þÿz#compute_position.<locals>.<genexpr>©r¹   ©r�   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 rw   rµ   ©r   rx   r·   r   r   ry   æ   rz   z-length_or_percentage_tuple.<locals>.<genexpr>rÂ   rÃ   r   r·   r   r¼   ã   s    r¼   zborder-spacingÚ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   ry   î   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   ©r�   r   rx   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r�t| dƒ}|j | | }qä|d	kr²t| 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×   )rx   r   r-   r   Úcharacter_ratioÚ
root_styler   )r�   r   rx   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Ñ   ÚcropÚ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   ry   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   )r�   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+   r�   )rå   Úhiddenr   TrÆ   )r—   ÚBORDER_WIDTH_KEYWORDSÚ
isinstancerª   r£   )r�   r   rx   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)r�   r   r­   Úcomputed_valuesrî   rx   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¹   )r�   r   r­   rñ   rx   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¹   )r�   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 rw   rµ   rÄ   r·   r   r   ry   ¾  rz   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r¸t | |ƒ}|d u r˜d }q¼|d |f|d dd …  f}n|}|d u rêt d| jd	 d
d„ |D ƒ¡f ¡ q| |¡ qt|ƒS )Nr   )rš   rÒ   r›   Úquotezleader()r™   r   rš   )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 rw   r‹   )r   Úitemr   r   r   ry   æ  rz   z _content_list.<locals>.<genexpr>)r³   r   Úwarningr¥   Újoinrï   r¹   )r�   r­   rñ   rx   Ú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©r�   r   r   ry   ÷  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ð   Úpseudo_typer   )r�   r   r­   rx   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  )Ú	specifiedÚis_root_elementrð   r§   )r�   r   rx   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  )r�   r   rx   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r¶t|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smalleréÿÿÿÿr   gš™™™™™é?r¢   r&   T)rÇ   r   )	ÚFONT_SIZE_KEYWORDSÚlistr­   Úparent_styler   Ú	enumerater-   rx   r£   )r�   r   rx   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#   Úboldr$   r)   Nr   )r  r   ÚFONT_WEIGHT_RELATIVE)r�   r   rx   Úparent_valuer   r   r   r   G  s    


r   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¹   )r�   r   r­   Úreturn_valuesr  rx   Ú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¹   )r�   r   r­   r"  rx   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-   rx   r£   )r�   r   rx   r   Zfont_size_valueÚpixelsr   r   r   rŠ   š  s    



rŠ   Úanchorc                 C   s(   |dkr$|\}}| j  |¡pd}|S dS )z Compute the ``anchor`` property.rå   N©r¥   r¦   )r�   r   r­   r’   r�   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å   Nr™   )r   r¥   r¨   r½   r   r   r   r*  ³  s    r‰   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å   Nr™   rš   r)  )r�   r   r­   r�   r   r   r   r‰   À  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¹   )r�   r   rx   rÜ   r”   Ú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.)ÚbaselineÚmiddleztext-topztext-bottomrÍ   rÐ   Úsuperr   ç      à?Úsubg      à¿r¢   r&   TrÆ   N)r-   Ústrut_layoutrx   r£   )r�   r   rx   r,   r’   r   r   r   Úvertical_alignÞ  s    
r5  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    r6  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 )zˆReturn 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)rŽ   ú Ú NF)Z	resume_atZspace_collapser�   rŠ   râ   r&  r   )r�   Zstrut_layoutsr
   Úset_textÚget_first_liner   )r�   Úcontextr�   ÚlayoutÚliner’   Ztext_heightr/  rÜ   r¾   rŠ   r   r   r   r4  ú  s0    



ÿ

r4  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ƒpìd}
|
||< |
S )z3Return the ratio of 1ex/font_size or 1ch/font_size.)rØ   rÙ   Zratio_rØ   rÕ   rÖ   râ   Úletter_spacingr   r6  rR   r   N)r;  r�   zPangoRectangle *r!   r2  )Úcacher�   Úcopyr
   r9  r:  r   Únewr	   Zpango_layout_line_get_extentsÚyr   r+   Úreleaserè   )r�   Ú	characterr?  Ú	cache_keyr<  r=  r’   Zink_extentsZlogical_extentsZmeasurerÝ   r   r   r   rÚ     s.    





rÚ   )F)NF)N)OÚ__doc__Úmathr   Úurllib.parser   Útinycss2.color4r   Úloggerr   Ztext.ffir   r   r	   Ztext.line_breakr
   r   Úurlsr   Ú
propertiesr   r   r   Úutilsr   r   r   r   r  rë   r  Z
PAGE_SIZESÚallr­   ZINITIAL_PAGE_SIZEr¹   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  r   r   r  r!  r$  r%  rŠ   r(  r*  r‰   r+  r,  r5  r6  r4  rÚ   r   r   r   r   Ú<module>   sT  ýý÷÷ôþ5ÿ
#

8"


#





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




!