3
6Ad]S  ã               @   s®   d Z ddlm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jde ƒjZejde ƒjZdZejde ƒjZejde ƒjZG d	d
„ d
eƒZeƒ eƒ jƒ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/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdœ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 )EÚFontconfigPatternParserz¯
    A simple pyparsing-based parser for `fontconfig patterns`_.

    .. _fontconfig patterns:
       https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
    ÚweightÚlightÚbookÚregularÚnormalÚmediumÚdemiboldÚsemiboldÚboldú
extra boldÚblackÚheavyÚslantÚitalicÚobliqueÚwidthúultra-condensedúextra-condensedÚ	condensedúsemi-condensedÚexpandedúextra-expandedúultra-expanded)ZthinZ
extralightZ
ultralightr   r   r   r   r   r   r   r   Z	extraboldr   r   Zromanr   r   ZultracondensedZextracondensedr   Zsemicondensedr   ZextraexpandedZultraexpandedc       	      C   sú   t dttf ƒj| jƒ}t dƒj| jƒ}t dƒj| jƒ}t dttf ƒj| jƒ}|tt	dƒ| ƒ j| j
ƒ}|tt	dƒ| ƒ j| jƒ}|tt	dƒƒ | ttt	dƒƒ| ƒ |B j| 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ÚvalueZfamiliesZpoint_sizesÚpropertyÚpattern© r8   úˆ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/matplotlib-3.1.1-py3.6-linux-x86_64.egg/matplotlib/fontconfig_pattern.pyÚ__init__A   s8    



.z FontconfigPatternParser.__init__c             C   sd   i  }| _ y| jj|ƒ W n4 | jk
rN } ztd||f ƒ‚W Y dd}~X nX d| _ | jjƒ  |S )z¸
        Parse the given fontconfig *pattern* and return a dictionary
        of key/value pairs useful for initializing a
        :class:`font_manager.FontProperties` object.
        z$Could not parse font string: '%s'
%sN)Ú_propertiesr0   ÚparseStringr   Ú
ValueErrorÚ
resetCache)r1   r7   ÚpropsÚer8   r8   r9   Úparseq   s    
 
zFontconfigPatternParser.parsec             C   s   t dt|d ƒƒgS )Nz\1r   )Úfamily_unescapeÚstr)r1   ÚsÚlocÚtokensr8   r8   r9   r(   „   s    zFontconfigPatternParser._familyc             C   s   t |d ƒgS )Nr   )Úfloat)r1   rD   rE   rF   r8   r8   r9   r)   ‡   s    zFontconfigPatternParser._sizec             C   s   t |d ƒgS )Nr   )rC   )r1   rD   rE   rF   r8   r8   r9   r*   Š   s    zFontconfigPatternParser._namec             C   s   t dt|d ƒƒgS )Nz\1r   )Úvalue_unescaperC   )r1   rD   rE   rF   r8   r8   r9   r,   �   s    zFontconfigPatternParser._valuec             C   s   dd„ |D ƒ| j d< g S )Nc             S   s   g | ]}t |ƒ‘qS r8   )rC   )Ú.0Úxr8   r8   r9   ú
<listcomp>‘   s    z5FontconfigPatternParser._families.<locals>.<listcomp>r2   )r;   )r1   rD   rE   rF   r8   r8   r9   r-   �   s    z!FontconfigPatternParser._familiesc             C   s   dd„ |D ƒ| j d< g S )Nc             S   s   g | ]}t |ƒ‘qS r8   )rC   )rI   rJ   r8   r8   r9   rK   •   s    z8FontconfigPatternParser._point_sizes.<locals>.<listcomp>r3   )r;   )r1   rD   rE   rF   r8   r8   r9   r.   ”   s    z$FontconfigPatternParser._point_sizesc             C   sn   t |ƒdkrB|d | jkrj| j|d  \}}| jj|g ƒj|ƒ n(|d }|dd … }| jj|g ƒj|ƒ g S )Né   r   )ÚlenÚ
_constantsr;   Ú
setdefaultÚappendÚextend)r1   rD   rE   rF   ÚkeyÚvalr8   r8   r9   r/   ˜   s    z!FontconfigPatternParser._propertyN)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   )r   r   )r   r   )r   r    )r   r!   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rN   r:   rA   r(   r)   r*   r,   r-   r.   r/   r8   r8   r8   r9   r
      sD   0r
   c             C   s~   g }xndj ƒ D ]b}t| d| ƒƒ }|dk	r|g krt|ƒtkr^dd„ |D ƒ}|g kr^dj|ƒ}|jd||f ƒ qW dj|ƒS )	z[
    Given a dictionary of key/value pairs, generates a fontconfig
    pattern string.
    z-family style variant weight stretch file sizeÚget_Nc             S   s"   g | ]}|d k	rt dt|ƒƒ‘qS )Nz\\\1)Úvalue_escaperC   )rI   rJ   r8   r8   r9   rK   µ   s    z/generate_fontconfig_pattern.<locals>.<listcomp>r"   z:%s=%sÚ )ÚsplitÚgetattrÚtypeÚlistÚjoinrP   )Údr?   rR   rS   r8   r8   r9   Úgenerate_fontconfig_pattern«   s    
ra   )rW   Ú	functoolsr   ÚreÚ	pyparsingr   r   r   r   r   r   r	   r&   ÚcompileÚsubrB   Zfamily_escaper+   rH   rY   Úobjectr
   rA   Úparse_fontconfig_patternra   r8   r8   r8   r9   Ú<module>   s   	$ 