ó
±éRc           @  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 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	 d d
 „  ƒ  YZ e ƒ  j Z d „  Z d S(   s®   
A module for parsing and generating fontconfig patterns.

See the `fontconfig pattern specification
<http://www.fontconfig.org/fontconfig-user.html>`_ for more
information.
iÿÿÿÿ(   t   print_functionN(   t   Literalt
   ZeroOrMoret   Optionalt   Regext	   StringEndt   ParseExceptiont   Suppresss   \\\-:,s   \\([%s])s   ([%s])s   \\=_:,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   sÃ   A simple pyparsing-based parser for fontconfig-style patterns.

    See the `fontconfig pattern specification
    <http://www.fontconfig.org/fontconfig-user.html>`_ for more
    information.
    t   weightt   lightt   thint
   extralightt
   ultralightt   bookt   regulart   normalt   mediumt   demiboldt   semiboldt   bolds
   extra boldt	   extraboldt   blackt   heavyt   slantt   romant   italict   obliquet   widths   ultra-condensedt   ultracondenseds   extra-condensedt   extracondensedt	   condenseds   semi-condensedt   semicondensedt   expandeds   extra-expandedt   extraexpandeds   ultra-expandedt   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(   Ns   ([^%s]|(\\[%s]))*s   ([0-9]+\.?[0-9]*|\.[0-9]+)s   [a-z]+t   ,t   =t   -t   :(   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(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   __init__F   s8    		
;	c         C  sj   i  } |  _  y |  j j | ƒ Wn, |  j k
 rO } t d | | f ƒ ‚ n Xd |  _  |  j j ƒ  | S(   s¸   
        Parse the given fontconfig *pattern* and return a dictionary
        of key/value pairs useful for initializing a
        :class:`font_manager.FontProperties` object.
        s$   Could not parse font string: '%s'
%sN(   t   _propertiesR2   t   parseStringR   t
   ValueErrort   Nonet
   resetCache(   R3   R;   t   propst   e(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   parsev   s    	c         C  s   t  d t | d ƒ ƒ g S(   Ns   \1i    (   t   family_unescapet   str(   R3   t   st   loct   tokens(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR*   ‰   s    c         C  s   t  | d ƒ g S(   Ni    (   t   float(   R3   RG   RH   RI   (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR+   Œ   s    c         C  s   t  | d ƒ g S(   Ni    (   RF   (   R3   RG   RH   RI   (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR,   �   s    c         C  s   t  d t | d ƒ ƒ g S(   Ns   \1i    (   t   value_unescapeRF   (   R3   RG   RH   RI   (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR.   ’   s    c         C  s*   g  | D] } t  | ƒ ^ q |  j d <g  S(   NR4   (   RF   R=   (   R3   RG   RH   RI   t   x(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR/   •   s    &c         C  s*   g  | D] } t  | ƒ ^ q |  j d <g  S(   NR5   (   RF   R=   (   R3   RG   RH   RI   RL   (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR0   ™   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(   R3   RG   RH   RI   t   keyt   val(    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyR1   �   s    "

(   R	   R
   (   R	   R
   (   R	   R
   (   R	   R
   (   R	   R   (   R	   R   (   R	   s   normal(   R	   R   (   R	   R   (   R	   R   (   R	   R   (   R	   s
   extra bold(   R	   R   (   R	   R   (   R   s   normal(   R   R   (   R   R   (   s   widths   ultra-condensed(   s   widths   extra-condensed(   s   widthR   (   s   widths   semi-condensed(   s   widthR!   (   s   widths   extra-expanded(   s   widths   ultra-expanded(   t   __name__t
   __module__t   __doc__RN   R<   RD   R*   R+   R,   R.   R/   R0   R1   (    (    (    sW   /opt/xtal/ccp4-6.5-linux32/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(   s[   
    Given a dictionary of key/value pairs, generates a fontconfig
    pattern string.
    t    s-   family style variant weight stretch file sizet   get_s   \\\1R$   s   :%s=%sN(	   t   splitt   getattrR@   t   typet   listt   value_escapeRF   t   joinRP   (   t   dRB   R8   R5   RR   RS   RL   (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   generate_fontconfig_patternª   s    4(    (   RV   t
   __future__R    t   ret   syst	   pyparsingR   R   R   R   R   R   R   R(   t   compilet   subRE   t   family_escapeR-   RK   R]   R   RD   t   parse_fontconfig_patternR`   (    (    (    sW   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.pyt   <module>   s   4…