a
    Sic                     @   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)thinZ
extralight
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_puncsetParseAction_family_size_name
value_punc_valuer   r   	_families_point_sizesr	   	_propertyr   r   _parserr   )	selffamilysizenamevaluefamiliesZpoint_sizespropertypattern r6   Z/var/www/html/django/DPS/env/lib/python3.9/site-packages/matplotlib/_fontconfig_pattern.py__init__>   s    



z FontconfigPatternParser.__init__c              
   C   sh   i  }| _ z| j| W n8 | jyR } ztd||f |W Y d}~n
d}~0 0 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-   parseStringr   
ValueError
resetCache)r.   r5   propser6   r6   r7   parsew   s    


zFontconfigPatternParser.parsec                 C   s   t dt|d gS Nz\1r   )family_unescapestrr.   sloctokensr6   r6   r7   r%      s    zFontconfigPatternParser._familyc                 C   s   t |d gS Nr   )floatrC   r6   r6   r7   r&      s    zFontconfigPatternParser._sizec                 C   s   t |d gS rG   rB   rC   r6   r6   r7   r'      s    zFontconfigPatternParser._namec                 C   s   t dt|d gS r@   )value_unescaperB   rC   r6   r6   r7   r)      s    zFontconfigPatternParser._valuec                 C   s   dd |D | j d< g S )Nc                 S   s   g | ]}t |qS r6   rI   .0xr6   r6   r7   
<listcomp>       z5FontconfigPatternParser._families.<locals>.<listcomp>r/   r9   rC   r6   r6   r7   r*      s    z!FontconfigPatternParser._familiesc                 C   s   dd |D | j d< g S )Nc                 S   s   g | ]}t |qS r6   rI   rK   r6   r6   r7   rN      rO   z8FontconfigPatternParser._point_sizes.<locals>.<listcomp>r0   rP   rC   r6   r6   r7   r+      s    z$FontconfigPatternParser._point_sizesc                 C   sn   t |dkrB|d | jv rj| j|d  \}}| j|g | n(|d }|dd  }| j|g | g S )N   r   )len
_constantsr9   
setdefaultappendextend)r.   rD   rE   rF   keyvalr6   r6   r7   r,      s    z!FontconfigPatternParser._propertyN)__name__
__module____qualname____doc__rS   r8   r?   r%   r&   r'   r)   r*   r+   r,   r6   r6   r6   r7   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 ur dt |V  qd S )Nz\\\1rI   rK   escape_funcr6   r7   	<genexpr>   s   z_escape_val.<locals>.<genexpr>)npiterable
isinstancerB   join)rX   r^   r6   r]   r7   _escape_val   s    rd   c                 C   sx   g }|   }|dur,|g kr,|t|t dD ]<}t| d|  }|du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filer0   get_z:%s=%s )Z
get_familyrU   rd   family_escapegetattrvalue_escaperc   )dr=   r/   rW   rX   r6   r6   r7   generate_fontconfig_pattern   s    rn   )r\   	functoolsr   renumpyr`   	pyparsingr   r   r   r   r   r   r	   r#   compilesubrA   rj   r(   rJ   rl   r
   r?   parse_fontconfig_patternrd   rn   r6   r6   r6   r7   <module>   s   $ 