U
    d»{jû  ã                   @   s¼   d Z ddlmZ ddlZddlZddlmZmZm	Z	m
Z
mZmZmZ dZe de ¡jZe de ¡jZdZe de ¡jZe de ¡jZG d	d
„ d
ƒZeƒ eƒ jƒZdd„ Zdd„ ZdS )zŸ
A module for parsing and generating `fontconfig patterns`_.

.. _fontconfig patterns:
   https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
é    )Ú	lru_cacheN)ÚLiteralÚ
ZeroOrMoreÚOptionalÚRegexÚ	StringEndÚParseExceptionÚSuppressz\\\-:,z\\([%s])z([%s])z\\=_:,c                   @   sŽ   e Zd ZdZddddddddddd	d
dddddddddddddœZdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Z	d"d#„ Z
d$d%„ Zd&d'„ Zd(d)„ Zd*S )+ÚFontconfigPatternParserz¯
    A simple pyparsing-based parser for `fontconfig patterns`_.

    .. _fontconfig patterns:
       https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
    )ÚweightÚlight)r   Úbook)r   Úregular)r   Únormal)r   Úmedium)r   Údemibold)r   Úsemibold)r   Úbold)r   z
extra bold)r   Úblack)r   Úheavy)Úslantr   )r   Úitalic)r   Úoblique)Úwidthzultra-condensed)r   zextra-condensed)r   Ú	condensed)r   zsemi-condensed)r   Úexpanded)r   zextra-expanded)r   zultra-expanded)ZthinZ
extralightZ
ultralightr   r   r   r   r   r   r   r   Z	extraboldr   r   Úromanr   r   ZultracondensedZextracondensedr   Zsemicondensedr   ZextraexpandedZultraexpandedc           	      C   sú   t dttf ƒ | j¡}t dƒ | j¡}t dƒ | j¡}t dttf ƒ | j¡}|tt	dƒ| ƒ  | j
¡}|tt	dƒ| ƒ  | j¡}|tt	dƒƒ | ttt	dƒƒ| ƒ |B  | j¡}t|ƒtt	dƒ| ƒ tt	dƒ| ƒ tƒ  }|| _t| _d S )Nz([^%s]|(\\[%s]))*z([0-9]+\.?[0-9]*|\.[0-9]+)z[a-z]+ú,ú=ú-ú:)r   Úfamily_puncZsetParseActionÚ_familyÚ_sizeÚ_nameÚ
value_puncÚ_valuer   r   Ú	_familiesÚ_point_sizesr	   Ú	_propertyr   r   Ú_parserr   )	ÚselfÚfamilyÚsizeÚnameÚvalueZfamiliesZpoint_sizesÚpropertyÚpattern© r2   ú]/var/www/html/bwave/python/venv/lib/python3.8/site-packages/matplotlib/_fontconfig_pattern.pyÚ__init__>   s˜    
ÿþÿþÿþ
ÿþÿÿÿüÿÿÿÿüÿ
ÿþ
ÿÿýúùÿÿÿÿþÿÿûøÿz FontconfigPatternParser.__init__c              
   C   sf   i  }| _ z| j |¡ W n6 | jk
rP } ztd||f ƒ|‚W 5 d}~X Y nX d| _ | j ¡  |S )z²
        Parse the given fontconfig *pattern* and return a dictionary
        of key/value pairs useful for initializing a
        `.font_manager.FontProperties` object.
        z$Could not parse font string: '%s'
%sN)Ú_propertiesr*   ZparseStringr   Ú
ValueErrorZ
resetCache)r+   r1   ÚpropsÚer2   r2   r3   Úparsew   s    

ÿÿ
zFontconfigPatternParser.parsec                 C   s   t dt|d ƒƒgS ©Nz\1r   )Úfamily_unescapeÚstr©r+   ÚsÚlocÚtokensr2   r2   r3   r"   Š   s    zFontconfigPatternParser._familyc                 C   s   t |d ƒgS ©Nr   )Úfloatr=   r2   r2   r3   r#   �   s    zFontconfigPatternParser._sizec                 C   s   t |d ƒgS rA   ©r<   r=   r2   r2   r3   r$   �   s    zFontconfigPatternParser._namec                 C   s   t dt|d ƒƒgS r:   )Úvalue_unescaper<   r=   r2   r2   r3   r&   “   s    zFontconfigPatternParser._valuec                 C   s   dd„ |D ƒ| j d< g S )Nc                 S   s   g | ]}t |ƒ‘qS r2   rC   ©Ú.0Úxr2   r2   r3   Ú
<listcomp>—   s     z5FontconfigPatternParser._families.<locals>.<listcomp>r,   ©r5   r=   r2   r2   r3   r'   –   s    z!FontconfigPatternParser._familiesc                 C   s   dd„ |D ƒ| j d< g S )Nc                 S   s   g | ]}t |ƒ‘qS r2   rC   rE   r2   r2   r3   rH   ›   s     z8FontconfigPatternParser._point_sizes.<locals>.<listcomp>r-   rI   r=   r2   r2   r3   r(   š   s    z$FontconfigPatternParser._point_sizesc                 C   sn   t |ƒdkrB|d | jkrj| j|d  \}}| j |g ¡ |¡ n(|d }|dd … }| j |g ¡ |¡ g S )Né   r   )ÚlenÚ
_constantsr5   Ú
setdefaultÚappendÚextend)r+   r>   r?   r@   ÚkeyÚvalr2   r2   r3   r)   ž   s    z!FontconfigPatternParser._propertyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rL   r4   r9   r"   r#   r$   r&   r'   r(   r)   r2   r2   r2   r3   r
      sF   è9r
   c                    s2   t  | ¡rt| tƒr| g} d ‡ fdd„| D ƒ¡S )zË
    Given a string value or a list of string values, run each value through
    the input escape function to make the values into legal font config
    strings.  The result is returned as a string.
    r   c                 3   s$   | ]}|d k	rˆ dt |ƒƒV  qd S )Nz\\\1rC   rE   ©Úescape_funcr2   r3   Ú	<genexpr>º   s    ÿz_escape_val.<locals>.<genexpr>)ÚnpÚiterableÚ
isinstancer<   Újoin)rQ   rW   r2   rV   r3   Ú_escape_val±   s    r]   c                 C   sx   g }|   ¡ }|dk	r,|g kr,| t|tƒ¡ dD ]<}t| d| ƒƒ }|dk	r0|g kr0| d|t|tƒf ¡ q0d |¡S )z[
    Given a dictionary of key/value pairs, generates a fontconfig
    pattern string.
    N)ÚstyleÚvariantr   ZstretchÚfiler-   Úget_z:%s=%sÚ )Z
get_familyrN   r]   Úfamily_escapeÚgetattrÚvalue_escaper\   )Údr7   r,   rP   rQ   r2   r2   r3   Úgenerate_fontconfig_pattern¾   s    rg   )rU   Ú	functoolsr   ÚreÚnumpyrY   Z	pyparsingr   r   r   r   r   r   r	   r!   ÚcompileÚsubr;   rc   r%   rD   re   r
   r9   Zparse_fontconfig_patternr]   rg   r2   r2   r2   r3   Ú<module>   s   $ 