σ
 m[c           @` sH  d  Z  d d l m Z m Z m Z 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 y d d l m Z Wn! e k
 r« d d l m Z n Xd 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 d
 e f d     YZ e   e   j  Z d   Z  d S(   uΔ   
A module for parsing and generating fontconfig patterns.

See the `fontconfig pattern specification
<https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>`_ for
more information.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   Literalt
   ZeroOrMoret   Optionalt   Regext	   StringEndt   ParseExceptiont   Suppress(   t	   lru_cacheu   \\\-:,u   \\([%s])u   ([%s])u   \\=_:,t   FontconfigPatternParserc           B` s  e  Z d  Z i d+ d 6d, d 6d- d 6d. d 6d/ d 6d0 d 6d1 d 6d2 d	 6d3 d
 6d4 d 6d5 d 6d6 d 6d7 d 6d8 d 6d9 d 6d: d 6d; d 6d< d 6d= d 6d> d 6d? d 6d@ d 6dA d 6dB d! 6Z d"   Z d#   Z d$   Z d%   Z d&   Z d'   Z	 d(   Z
 d)   Z d*   Z RS(C   uΩ   A simple pyparsing-based parser for fontconfig-style patterns.

    See the `fontconfig pattern specification
    <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>`_
    for more information.
    u   weightu   lightu   thinu
   extralightu
   ultralightu   booku   regularu   normalu   mediumu   demiboldu   semiboldu   boldu
   extra boldu	   extraboldu   blacku   heavyu   slantu   romanu   italicu   obliqueu   widthu   ultra-condensedu   ultracondensedu   extra-condensedu   extracondensedu	   condensedu   semi-condensedu   semicondensedu   expandedu   extra-expandedu   extraexpandedu   ultra-expandedu   ultraexpandedc   	      C` sU  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   |  | Bj |  j  } t |  t t	 d  |  t t	 d  |  t   } | |  _ t |  _ d  S(   Nu   ([^%s]|(\\[%s]))*u   ([0-9]+\.?[0-9]*|\.[0-9]+)u   [a-z]+u   ,u   =u   -u   :(   R   t   family_punct   setParseActiont   _familyt   _sizet   _namet
   value_punct   _valueR   R   t	   _familiest   _point_sizesR
   t	   _propertyR   R   t   _parserR	   (	   t   selft   familyt   sizet   namet   valuet   familiest   point_sizest   propertyt   pattern(    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   __init__I   s8    		
;	c         C` sj   i  } |  _  y |  j j |  Wn, |  j k
 rO } t d | | f   n Xd |  _  |  j j   | S(   uΈ   
        Parse the given fontconfig *pattern* and return a dictionary
        of key/value pairs useful for initializing a
        :class:`font_manager.FontProperties` object.
        u$   Could not parse font string: '%s'
%sN(   t   _propertiesR   t   parseStringR	   t
   ValueErrort   Nonet
   resetCache(   R   R    t   propst   e(    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   parsey   s    	c         C` s   t  d t | d   g S(   Nu   \1i    (   t   family_unescapet   str(   R   t   st   loct   tokens(    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR      s    c         C` s   t  | d  g S(   Ni    (   t   float(   R   R,   R-   R.   (    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR      s    c         C` s   t  | d  g S(   Ni    (   R+   (   R   R,   R-   R.   (    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR      s    c         C` s   t  d t | d   g S(   Nu   \1i    (   t   value_unescapeR+   (   R   R,   R-   R.   (    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR      s    c         C` s*   g  | D] } t  |  ^ q |  j d <g  S(   Nu   family(   R+   R"   (   R   R,   R-   R.   t   x(    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR      s    &c         C` s*   g  | D] } t  |  ^ q |  j d <g  S(   Nu   size(   R+   R"   (   R   R,   R-   R.   R1   (    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR      s    &c         C` s   t  |  d k r^ | d |  j k r |  j | d \ } } |  j j | g   j |  q n0 | d } | d } |  j j | g   j |  g  S(   Ni   i    (   t   lent
   _constantsR"   t
   setdefaultt   appendt   extend(   R   R,   R-   R.   t   keyt   val(    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR       s    "

(   u   weightu   light(   u   weightu   light(   u   weightu   light(   u   weightu   light(   u   weightu   book(   u   weightu   regular(   u   weightu   normal(   u   weightu   medium(   u   weightu   demibold(   u   weightu   semibold(   u   weightu   bold(   u   weightu
   extra bold(   u   weightu   black(   u   weightu   heavy(   u   slantu   normal(   u   slantu   italic(   u   slantu   oblique(   u   widthu   ultra-condensed(   u   widthu   extra-condensed(   u   widthu	   condensed(   u   widthu   semi-condensed(   u   widthu   expanded(   u   widthu   extra-expanded(   u   widthu   ultra-expanded(   t   __name__t
   __module__t   __doc__R3   R!   R)   R   R   R   R   R   R   R   (    (    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR   &   sF   
	0							c         C` sε   g  } d } d } xΓ d j    D]΅ } t |  d |    } | d k	 r | g  k r t |  t k rΊ g  | D]' } | d k	 rl t d t |   ^ ql } | g  k rΊ d j |  } qΊ n  | j d | | f  q q Wd j |  S(   u[   
    Given a dictionary of key/value pairs, generates a fontconfig
    pattern string.
    u    u-   family style variant weight stretch file sizeu   get_u   \\\1u   ,u   :%s=%sN(	   t   splitt   getattrR%   t   typet   listt   value_escapeR+   t   joinR5   (   t   dR'   R   R   R7   R8   R1   (    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   generate_fontconfig_pattern³   s    '(!   R;   t
   __future__R    R   R   R   t   sixt   ret	   pyparsingR   R   R   R   R   R	   R
   t	   functoolsR   t   ImportErrort   backports.functools_lru_cacheR   t   compilet   subR*   t   family_escapeR   R0   R@   t   objectR   R)   t   parse_fontconfig_patternRC   (    (    (    s<   lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   <module>   s"   	"4