
 m[c           @` s  d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l Z d d l	 Z	 d d l
 Z
 y d d l m Z Wn! e k
 r d d l m Z n Xd d l Z d d l Z d d l m Z m Z m Z m Z m Z d d l m Z d d l m Z m Z y d d	 l m Z Wn! e k
 r7d d	 l m Z n Xe j e   Z! e" Z# i
 d
 d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d e$ 6Z% i	 d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6Z& i d d, 6d d- 6d  d# 6d  d. 6d  d/ 6d" d 6d" d0 6d$ d1 6d$ d2 6d$ d3 6d& d4 6d( d5 6d( d6 6d* d7 6Z' d8 d9 d: d; d< d= d> h Z( d? Z) d@ dA g Z* dB dC dD dE dF g Z+ dG dH dI dJ g Z, e# oe
 j- dK k re	 j. j/ dL  Z0 e0 e$ k	 re	 j1 j2 e0 dM dN  Z1 e, j3 e1  e	 j1 j2 e0 dO  Z1 e+ j3 e1  n  n  dP   Z4 dQ   Z5 dR   Z6 e$ dS dT  Z7 e$ dS dU  Z8 e   dV    Z9 dS dW  Z: e$ dS dX  Z; e j< dY  dZ    Z= d[ e> f d\     YZ? d]   Z@ d^   ZA dS d_  ZB d` e> f da     YZC e j< dY  db    ZD dc e jE f dd     YZE de   ZF df   ZG dg   ZH dh   ZI di e> f dj     YZJ dk e> f dl     YZK i  ZL dm   ZM e$ aN e$ ZO e dn  e jP  ZQ e$ do  ZR e# oe
 j- dK k rdp   ZS i  ZT dS dq  ZU n e$ ZO e   ZV eV e$ k	 re	 j1 j2 eV dr  ZO n  e$ aN i eJ   dS 6eJ   ds 6ZW dt   ZX eO ryU eH eO  aN eY tN du  pctN jZ eK j[ k rpeX   n e$ tN _\ e! j] dv eO  Wn' e j^ j_ k
 r  n eX   n Xn eX   dw   ZU d S(x   s  
A module for finding, managing, and using fonts across platforms.

This module provides a single :class:`FontManager` instance that can
be shared across backends and platforms.  The :func:`findfont`
function returns the best TrueType (TTF) font file in the local or
system font path that matches the specified :class:`FontProperties`
instance.  The :class:`FontManager` also handles Adobe Font Metrics
(AFM) font files for use by the PostScript backend.

The design is based on the `W3C Cascading Style Sheet, Level 1 (CSS1)
font specification <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_.
Future versions may implement the Level 2 or 2.1 specifications.

Experimental support is included for using `fontconfig` on Unix
variant platforms (Linux, OS X, Solaris).  To enable it, set the
constant ``USE_FONTCONFIG`` in this file to ``True``.  Fontconfig has
the advantage that it is the standard way to look up fonts on X11
platforms, so if a font is installed, it is much more likely to be
found.
i    (   t   absolute_importt   divisiont   print_functionN(   t   Iterable(   t   Timer(   t   afmt   cbookt   ft2fontt   rcParamst   get_cachedir(   t
   subprocess(   t   parse_fontconfig_patternt   generate_fontconfig_pattern(   t	   lru_cachegI+?s   xx-smallgh|?5?s   x-smallg-?t   smallg      ?t   mediumg333333?t   largeg
ףp=
?s   x-largegS?s   xx-larget   largert   smallerid   s   ultra-condensedi   s   extra-condensedi,  t	   condensedi  s   semi-condensedi  t   normaliX  s   semi-expandedi  t   expandedi   s   extra-expandedi  s   ultra-expandedt
   ultralightt   lightt   regulart   bookt   romant   semiboldt   demiboldt   demit   boldt   heavys
   extra boldt   blackt   serifs
   sans-serifs
   sans serift   cursivet   fantasyt	   monospacet   sanss@   Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folderss2   SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fontss/   SOFTWARE\Microsoft\Windows\CurrentVersion\Fontss   /usr/X11R6/lib/X11/fonts/TTF/s   /usr/X11/lib/X11/fontss   /usr/share/fonts/s   /usr/local/share/fonts/s)   /usr/lib/openoffice/share/fonts/truetype/s   /Library/Fonts/s   /Network/Library/Fonts/s   /System/Library/Fonts/s   /opt/local/share/fontst   win32t   HOMEt   Libraryt   Fontss   .fontsc         C` s   i d d 6d d 6d d 6|  S(   ss   
    Return a list of file extensions extensions that are synonyms for
    the given file extension *fileext*.
    t   ttft   otfR   (   R*   R+   (   R*   R+   (   R   (    (   t   fontext(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   get_fontext_synonyms   s    
c         C` sB   d j  g  | D] } d | | j   f ^ q  } t j |  |  S(   s   
    Return a list of all fonts matching any of the extensions,
    possibly upper-cased, found recursively under the directory.
    t   ;s	   *.%s;*.%s(   t   joint   upperR   t	   listFiles(   t	   directoryt
   extensionst   extt   pattern(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt
   list_fonts   s    	)c          C` s   y d d l  m }  Wn t k
 r' no XyZ |  j |  j t  } z0 y |  j | d  d SWn t k
 rn n XWd |  j |  XWn t k
 r n Xt	 j
 j t	 j d d  S(   s  
    Return the user-specified font directory for Win32.  This is
    looked up from the registry key::

      \\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Fonts

    If the key is not found, $WINDIR/Fonts will be returned.
    i    (   t   winregR)   Nt   WINDIR(   t	   six.movesR7   t   ImportErrort   OpenKeyt   HKEY_CURRENT_USERt	   MSFolderst   QueryValueExt   OSErrort   CloseKeyt   ost   pathR/   t   environ(   R7   t   user(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   win32FontDirectory   s    	R*   c   
      C` s  d d l  m } |  d k r( t   }  n  t |  } d t   } } xt D]} y | j | j |  } Wn t	 k
 r qK n X| s t
 |  |  Sz.xt | j |  d  D]} y | j | |  \ } } }	 t | t j  s w n  | j d d  d } t j j |  s-t j j |  |  } n  t j j |  j   } t j j |  d d | k ru| j |  n  Wq t k
 rq q t k
 rq q t k
 rq q Xq Wt |  SWd | j |  XqK Wd S(   s   
    Search for fonts in the specified font directory, or use the
    system directories if none given.  A list of TrueType font
    filenames are returned by default, or AFM fonts if *fontext* ==
    'afm'.
    i    (   R7   i   s    N(   R9   R7   t   NoneRE   R-   t   sett   MSFontDirectoriesR;   t   HKEY_LOCAL_MACHINER?   R6   t   ranget   QueryInfoKeyt	   EnumValuet
   isinstancet   sixt   string_typest   splitRA   RB   t   dirnameR/   t   abspatht   lowert   splitextt   addt   EnvironmentErrort   WindowsErrort   MemoryErrort   listR@   (
   R2   R,   R7   t   keyt   itemst   fontdirt   localt   jt   direct   tp(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   win32InstalledFonts   sB      c         C` sz   |  d k r t }  n  t |  } g  } xL |  D]D } | d k r\ | j t j | d   q. | j t | |   q. W| S(   sJ   
    Get list of font files on OS X - ignores font suffix by default.
    t   *N(   RF   t   OSXFontDirectoriesR-   t   extendR   R1   R6   (   t   directoriesR,   t   filesRB   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   OSXInstalledFonts  s    	c          C` s   t  d d    }  |  j   zA y t j t d  d g  } Wn t t j f k
 r[ g  SXWd |  j   Xg  } xW | j d  D]F } y t	 j
 | t j    } Wn t k
 r q n X| j |  q W| S(   s:   Cache and list the font filenames known to `fc-list`.
    i   c           S` s   t  j d  S(   NsL   Matplotlib is building the font cache using fc-list. This may take a moment.(   t   warningst   warn(    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   <lambda>  s   s   fc-lists   --format=%{file}\nNs   
(   R   t   startR
   t   check_outputt   strR?   t   CalledProcessErrort   cancelRP   RN   t	   text_typet   syst   getfilesystemencodingt   UnicodeDecodeErrort   append(   t   timert   outt   fnamest   fname(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   _call_fc_list  s     
 	c         C` sF   t  |   }  g  t   D], } t j j |  d d |  k r | ^ q S(   sK   List the font filenames known to `fc-list` having the given extension.
    i   (   R-   Ry   RA   RB   RT   (   R,   Rx   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   get_fontconfig_fonts,  s    c         C` s  t    } t |  } |  d k rt j d k r t   } | g }  x t |  D]V } t j j	 |  \ } } t
 |  d k rO | d j   | k rO | j |  qO qO Wq0t }  t j d k r x' t d |  D] } | j |  q Wn  xB t |  D] } | j |  q Wn t |  t j  r0|  g }  n  xG |  D]? } t | |  }	 x' |	 D] }
 | j t j j |
   qSWq7Wg  | D] }
 t j j |
  r|
 ^ qS(   s4  
    Search for fonts in the specified font paths.  If no paths are
    given, will use a standard set of system paths, as well as the
    list of fonts tracked by fontconfig if fontconfig is installed and
    available.  A list of TrueType fonts are returned by default with
    AFM fonts as an option.
    R&   i   t   darwinR,   N(   RG   R-   RF   Rq   t   platformRE   Ra   RA   RB   RT   t   lenRS   RU   t   X11FontDirectoriesRg   Rz   RM   RN   RO   R6   RR   t   exists(   t	   fontpathsR,   t	   fontfilest   fontextsR\   t   ft   baseR4   RB   Rf   Rx   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   findSystemFonts4  s.    			(!s   2.1c         C` sn   t  |  t j  rC y t |  j   }  Wqj t k
 r? d }  qj Xn' |  t d d d  k r^ n t d   |  S(   s   
    Return the weight property as a numeric value.  String values
    are converted to their corresponding numeric value.
    i  id   i  s   weight not a valid integer(   RM   RN   RO   t   weight_dictRS   t   KeyErrorRJ   t
   ValueError(   t   weight(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   weight_as_number^  s    t	   FontEntryc           B` s5   e  Z d  Z d d d d d d d d  Z d   Z RS(   sj   
    A class for storing Font properties.  It is used when populating
    the font lookup dictionary.
    t    R   R   c         C` sp   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ y t t |   |  _ Wn t	 k
 rk | |  _ n Xd  S(   N(
   Rx   t   namet   stylet   variantR   t   stretchRm   t   floatt   sizeR   (   t   selfRx   R   R   R   R   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   __init__u  s    							c         C` s8   d |  j  t j j |  j  |  j |  j |  j |  j f S(   Ns   <Font '%s' (%s) %s %s %s %s>(	   R   RA   RB   t   basenameRx   R   R   R   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   __repr__  s    $(   t   __name__t
   __module__t   __doc__R   R   (    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   p  s   c   	      ` s8  |  j  } |  j   } | j d  } | j d    | rQ | j d  j   } n d }   ru   j d  j     n d     j d  d k r d } n[   j d  d k r d } n= | j d	  d k r d
 } n |  j t j @r d } n d
 } | j   d k rd } n d
 } t	   f d   t
 D d  } | s\|  j t j @rSd } q\d } n    j d  d k s  j d  d k s  j d  d k rd } nW   j d  d k rd } n9   j d  d k s  j d  d k rd } n d
 } |  j st d   n  d } t |  j | | | | | |  S(   s  
    Extract information from a TrueType font file.

    Parameters
    ----------
    font : `.FT2Font`
        The TrueType font file from which information will be extracted.

    Returns
    -------
    `FontEntry`
        The extracted font properties.

    i   i    i   i   t	   mac_romanR   t   obliquet   italicR   R   t   capitalss
   small-capsc         3` s*   |  ]  }   j  |  d  k r | Vq d S(   i    N(   t   find(   t   .0t   w(   t   sfnt4(    s6   lib/python2.7/site-packages/matplotlib/font_manager.pys	   <genexpr>  s    i  i  t   narrowR   t   conds	   demi conds   semi-condensedt   wideR   s$   Non-scalable fonts are not supportedt   scalable(   i   i    i    i   (   i   i    i    i   (   R   s
   small-capsN(   t   family_namet   get_sfntt   gett   decodeRS   R   t   style_flagsR   t   ITALICt   nextR   RF   t   BOLDR   t   NotImplementedErrorR   Rx   (	   t   fontR   t   sfntt   sfnt2R   R   R   R   R   (    (   R   s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   ttfFontProperty  sN    									*		*			c   	      C` sr  | j    } | j   j   } | j   d k sK | j   j d  d k rT d } n* | j   j d  d k rx d } n d } | j   d k r d } n d } | j   j   } | j d  d k s | j d  d k s | j d	  d k r d } nW | j d
  d k rd } n9 | j d  d k sA| j d  d k rJd } n d } d } t |  | | | | | |  S(   s   
    Extract information from an AFM font file.

    Parameters
    ----------
    font : `.AFM`
        The AFM font file from which information will be extracted.

    Returns
    -------
    `FontEntry`
        The extracted font properties.

    i    R   R   R   R   s
   small-capsR   R   R   s	   demi conds   semi-condensedR   R   R   (   R   s
   small-caps(   t   get_familynamet   get_fontnameRS   t	   get_angleR   t
   get_weightR   (	   t   fontpathR   R   t   fontnameR   R   R   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   afmFontProperty  s*    -			*		*	c   	   	   C` s  g  } t    } x|  D]} t j d |  t j j |  d } | | k rT q n | j |  | d k r y t | d  } Wn$ t k
 r t j	 d |  q n Xz> y t
 j |  } Wn$ t k
 r t j	 d |  w n XWd | j   Xy t | |  } Wqt k
 rq qXn y t j |  } Wng t k
 rYt j	 d |  q nD t k
 ryt j	 d  q n$ t k
 rt j	 d	 |  q n Xy t |  } Wn  t t t t f k
 rq n X| j |  q W| S(
   s   
    A function to create a font lookup list.  The default is to create
    a list of TrueType fonts.  An AFM font list can optionally be
    created.
    s   createFontDict: %si   R   t   rbs   Could not open font file %ss   Could not parse font file %sNs   Cannot handle unicode filenamess#   IO error - cannot open font file %s(   RG   t   _logt   debugRA   RB   RP   RU   t   openRV   t   infoR   t   AFMt   RuntimeErrort   closeR   R   R   t   FT2Fontt   UnicodeErrort   IOErrorR   R   R   Rt   (	   R   R,   t   fontlistt   seent   fpathRx   t   fhR   t   prop(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   createFontList*  sT    	 
t   FontPropertiesc        	   B` s  e  Z d  Z d d d d d d d d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z e Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e Z d   Z e Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s	  
    A class for storing and manipulating font properties.

    The font properties are those described in the `W3C Cascading
    Style Sheet, Level 1
    <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_ font
    specification.  The six properties are:

      - family: A list of font names in decreasing order of priority.
        The items may include a generic font family name, either
        'serif', 'sans-serif', 'cursive', 'fantasy', or 'monospace'.
        In that case, the actual font to be used will be looked up
        from the associated rcParam in :file:`matplotlibrc`.

      - style: Either 'normal', 'italic' or 'oblique'.

      - variant: Either 'normal' or 'small-caps'.

      - stretch: A numeric value in the range 0-1000 or one of
        'ultra-condensed', 'extra-condensed', 'condensed',
        'semi-condensed', 'normal', 'semi-expanded', 'expanded',
        'extra-expanded' or 'ultra-expanded'

      - weight: A numeric value in the range 0-1000 or one of
        'ultralight', 'light', 'normal', 'regular', 'book', 'medium',
        'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy',
        'extra bold', 'black'

      - size: Either an relative value of 'xx-small', 'x-small',
        'small', 'medium', 'large', 'x-large', 'xx-large' or an
        absolute font size, e.g., 12

    The default font property for TrueType fonts (as specified in the
    default :file:`matplotlibrc` file) is::

      sans-serif, normal, normal, normal, normal, scalable.

    Alternatively, a font may be specified using an absolute path to a
    .ttf file, by using the *fname* kwarg.

    The preferred usage of font sizes is to use the relative values,
    e.g.,  'large', instead of absolute font sizes, e.g., 12.  This
    approach allows all text sizes to be made larger or smaller based
    on the font manager's default font size.

    This class will also accept a `fontconfig
    <https://www.freedesktop.org/wiki/Software/fontconfig/>`_ pattern, if it is
    the only argument provided.  See the documentation on `fontconfig patterns
    <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>`_.
    This support does not require fontconfig to be installed.  We are merely
    borrowing its pattern syntax for use here.

    Note that matplotlib's internal font manager and fontconfig use a
    different algorithm to lookup fonts, so the results of the same pattern
    may be different in matplotlib than in other applications that use
    fontconfig.
    c	   	      C` sM  t  t d  |  _ t d |  _ t d |  _ t d |  _ t d |  _ t d |  _ d  |  _	 | d  k	 r |  j
 j | j
  d  St | t j  r | d  k r | d  k r | d  k r | d  k r | d  k r | d  k r |  j |  d  Sn  |  j |  |  j |  |  j |  |  j |  |  j |  |  j |  |  j |  d  S(   Ns   font.familys
   font.styles   font.variants   font.weights   font.stretchs	   font.size(   t   _normalize_font_familyR   t   _familyt   _slantt   _variantt   _weightt   _stretcht   _sizeRF   t   _filet   __dict__t   updateRM   RN   RO   t   set_fontconfig_patternt
   set_familyt	   set_stylet   set_variantt
   set_weightt   set_stretcht   set_filet   set_size(	   R   t   familyR   R   R   R   R   Rx   t   _init(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s4    
	c         C` s
   t  |  S(   N(   R   (   R   R5   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   _parse_fontconfig_pattern  s    c         C` sU   t  |  j    |  j   |  j   |  j   |  j   |  j   |  j   f } t |  S(   N(	   t   tuplet
   get_familyt	   get_slantt   get_variantR   t   get_stretcht   get_size_in_pointst   get_filet   hash(   R   t   l(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   __hash__  s    					c         C` s   t  |   t  |  k S(   N(   R   (   R   t   other(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   __eq__  s    c         C` s   t  |   t  |  k S(   N(   R   (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   __ne__  s    c         C` s
   |  j    S(   N(   t   get_fontconfig_pattern(   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   __str__  s    c         C` s   |  j  S(   sL   
        Return a list of font names that comprise the font family.
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` s   t  t |    j S(   s\   
        Return the name of the font that best matches the font
        properties.
        (   t   get_fontt   findfontR   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   get_name  s    c         C` s   |  j  S(   s^   
        Return the font style.  Values are: 'normal', 'italic' or
        'oblique'.
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt	   get_style  s    c         C` s   |  j  S(   sY   
        Return the font variant.  Values are: 'normal' or
        'small-caps'.
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` s   |  j  S(   s   
        Set the font weight.  Options are: A numeric value in the
        range 0-1000 or one of 'light', 'normal', 'regular', 'book',
        'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold',
        'heavy', 'extra bold', 'black'
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` s   |  j  S(   s   
        Return the font stretch or width.  Options are: 'ultra-condensed',
        'extra-condensed', 'condensed', 'semi-condensed', 'normal',
        'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'.
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` s   |  j  S(   s'   
        Return the font size.
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   get_size
  s    c         C` s   |  j  S(   N(   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` s   |  j  S(   s=   
        Return the filename of the associated font.
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` s
   t  |   S(   s  
        Get a fontconfig pattern suitable for looking up the font as
        specified with fontconfig's ``fc-match`` utility.

        See the documentation on `fontconfig patterns
        <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>`_.

        This support does not require fontconfig to be installed or
        support for it to be enabled.  We are merely borrowing its
        pattern syntax for use here.
        (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` s,   | d k r t d } n  t |  |  _ d S(   s7  
        Change the font family.  May be either an alias (generic name
        is CSS parlance), such as: 'serif', 'sans-serif', 'cursive',
        'fantasy', or 'monospace', a real font name or a list of real
        font names.  Real font names are not supported when
        `text.usetex` is `True`.
        s   font.familyN(   RF   R   R   R   (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   '  s    c         C` sA   | d k r t d } n  | d k r4 t d   n  | |  _ d S(   s[   
        Set the font style.  Values are: 'normal', 'italic' or
        'oblique'.
        s
   font.styleR   R   R   s'   style must be normal, italic or obliqueN(   R   R   R   (   RF   R   R   R   (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   4  s
    c         C` sA   | d k r t d } n  | d k r4 t d   n  | |  _ d S(   sN   
        Set the font variant.  Values are: 'normal' or 'small-caps'.
        s   font.variantR   s
   small-capss$   variant must be normal or small-capsN(   R   s
   small-caps(   RF   R   R   R   (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   @  s
    c         C` s   | d k r t d } n  y4 t |  } | d k  s@ | d k rL t    n  Wn, t k
 r{ | t k r| t d   q| n X| |  _ d S(   s	  
        Set the font weight.  May be either a numeric value in the
        range 0-1000 or one of 'ultralight', 'light', 'normal',
        'regular', 'book', 'medium', 'roman', 'semibold', 'demibold',
        'demi', 'bold', 'heavy', 'extra bold', 'black'
        s   font.weighti    i  s   weight is invalidN(   RF   R   t   intR   R   R   (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   J  s    c         C` s   | d k r t d } n  y4 t |  } | d k  s@ | d k rL t    n  Wn, t k
 r{ | t k r| t d   q| n X| |  _ d S(   s  
        Set the font stretch or width.  Options are: 'ultra-condensed',
        'extra-condensed', 'condensed', 'semi-condensed', 'normal',
        'semi-expanded', 'expanded', 'extra-expanded' or
        'ultra-expanded', or a numeric value in the range 0-1000.
        s   font.stretchi    i  s   stretch is invalidN(   RF   R   R   R   t   stretch_dictR   (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   \  s    c         C` s   | d k r t d } n  y t |  } Wne t k
 r y t | } Wn3 t k
 r| t d d j t t t     q X| t	 j
   } n X| d k  r t j d |  d } n  | |  _ d S(   s   
        Set the font size.  Either an relative value of 'xx-small',
        'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'
        or an absolute font size, e.g., 12.
        s	   font.sizes%   Size is invalid. Valid font size are s   , g      ?sH   Fontsize %1.2f < 1.0 pt not allowed by FreeType. Setting fontsize = 1 ptN(   RF   R   R   R   t   font_scalingsR   R/   t   mapRm   t   FontManagert   get_default_sizeR   R   R   (   R   R   t   scale(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   n  s"     		c         C` s   | |  _  d S(   sw   
        Set the filename of the fontfile to use.  In this case, all
        other properties will be ignored.
        N(   R   (   R   t   file(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    c         C` st   xm t  j |  j |   D]S \ } } t |  t k rU t |  d |  | d  q t |  d |  |  q Wd S(   s}  
        Set the properties by parsing a fontconfig *pattern*.

        See the documentation on `fontconfig patterns
        <https://www.freedesktop.org/software/fontconfig/fontconfig-user.html>`_.

        This support does not require fontconfig to be installed or
        support for it to be enabled.  We are merely borrowing its
        pattern syntax for use here.
        t   set_i    N(   RN   t	   iteritemsR   t   typeRY   t   getattr(   R   R5   RZ   t   val(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    %c         C` s   t  d |   S(   s   Return a deep copy of selfR   (   R   (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   copy  s    N(    R   R   R   RF   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   set_nameR   t	   set_slantR   R   R   R   R   R   R  (    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   a  sH   9#		
																
	
					c         C` s   g  } x t  j |   D] } x t  j |  D]{ } xr t  j |  D]a } xX t  j |  D]G } x> t  j |  D]- } x$ t  j |  D] } | j |  q Wqn WqX WqB Wq, Wq W| S(   s<   
    flatten a ttfdict to all the filenames it contains
    (   RN   t
   itervaluesRt   (   t   dRw   t   namedt   styledt   variantdt   weightdt   stretchdRx   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   ttfdict_to_fnames  s    %t   JSONEncoderc           B` s   e  Z d    Z RS(   c         C` s^   t  | t  r" t | j d d St  | t  rD t | j d d St t |   j |  Sd  S(   Nt   _classR   R   (   RM   R   t   dictR   R   t   superR  t   default(   R   t   o(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR    s
    (   R   R   R  (    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR    s   c         C` s   |  j  d d   } | d  k r" |  S| d k rQ t j t  } | j j |   | S| d k r t j t  } | j j |   | St d |   d  S(   NR  R   R   s'   don't know how to deserialize _class=%s(   t   popRF   R   t   __new__R   R   R   R   (   R  t   clst   r(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   _json_decode  s    c         C` sh   t  | d  S } y  t j |  | d t d d Wn) t k
 r] } t j d j |   n XWd QXd S(   sY   Dumps a data structure as JSON in the named file.
    Handles FontManager and its fields.R   R  t   indenti   s$   Could not save font_manager cache {}N(   R   t   jsont   dumpR  R   Rh   Ri   t   format(   t   datat   filenameR   t   e(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt	   json_dump  s
     c         C` s/   t  |  d   } t j | d t SWd QXd S(   s[   Loads a data structure as JSON from the named file.
    Handles FontManager and its fields.R  t   object_hookN(   R   R  t   loadR  (   R  R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt	   json_load  s    c         C` s_   t  |  t j  r' t j |   g }  n4 t  |  t  r[ g  |  D] } t j |  ^ q= }  n  |  S(   N(   RM   RN   RO   Rp   R   (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s
    %t	   TempCachec           B` s8   e  Z d  Z d
 Z d   Z d   Z d   Z d	   Z RS(   s>  
    A class to store temporary caches that are (a) not saved to disk
    and (b) invalidated whenever certain font-related
    rcParams---namely the family lookup lists---are changed or the
    font cache is reloaded.  This avoids the expensive linear search
    through all fonts every time a font is looked up.
    s
   font.serifs   font.sans-serifs   font.cursives   font.fantasys   font.monospacec         C` s   i  |  _  |  j   |  _ d  S(   N(   t   _lookup_cachet   make_rcparams_keyt   _last_rcParams(   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    	c         C` s+   t  t  g g  |  j D] } t | ^ q S(   N(   t   idt   fontManagert   invalidating_rcparamsR   (   R   t   param(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR%    s    c         C` s@   |  j    } | |  j k r0 i  |  _ | |  _ n  |  j j |  S(   N(   R%  R&  R$  R   (   R   R   RZ   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s
    	c         C` sA   |  j    } | |  j k r0 i  |  _ | |  _ n  | |  j | <d  S(   N(   R%  R&  R$  (   R   R   t   valueRZ   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyRG     s
    	(   s
   font.serifs   font.sans-serifs   font.cursives   font.fantasys   font.monospace(   R   R   R   R)  R   R%  R   RG   (    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR#    s    			R   c           B` s   e  Z d  Z d Z d d d  Z d   Z e d    Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d d e e d  Z RS(   s}  
    On import, the :class:`FontManager` singleton instance creates a
    list of TrueType fonts based on the font properties: name, style,
    variant, weight, stretch, and size.  The :meth:`findfont` method
    does a nearest neighbor search to find the font that most closely
    matches the specification.  If no good enough match is found, a
    default font is returned.
    i   R   c         C` sA  |  j  |  _ | |  _ | |  _ t j j t d d d  t j j t d d d  t j j t d d d  g } x d d g D] } | t j k r| t j | } | j	 d  d	 k r | j
 | j d   q
| j	 d
  d	 k r | j
 | j d
   q
| j |  q| q| Wt j d t |   t |  t   |  _ i d d 6d d 6|  _ i  |  _ xa |  j D]B } t j d |  | j   j	 d  d	 k rd| |  j d <PqdqdW|  j d	 |  j d <t |  j  |  _ t | d d t d d  |  _ t |  j d d |  _ t |  j  r0|  j d	 |  j d <n d  |  j d <d  S(   Nt   datapatht   fontsR*   R   t   pdfcorefontst   TTFPATHt   AFMPATHR.   i    t   :s   font search path %ss   DejaVu Sanst	   Helveticas   trying fontname %ss   DejaVuSans.ttfR,   (   t   __version__t   _versiont   _FontManager__default_weightt   default_sizeRA   RB   R/   R   RC   R   Rd   RP   Rt   R   R   Rm   R   t   ttffilest   defaultFamilyt   defaultFontR   RS   R   t   ttflistt   afmfilest   afmlistR}   RF   (   R   R   R   t   pathst   pathnamet   ttfpathRx   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     sB    			c         C` s   |  j  S(   s1   
        Return the default font weight.
        (   R5  (   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   get_default_weightK  s    c           C` s   t  d S(   s/   
        Return the default font size.
        s	   font.size(   R   (    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   Q  s    c         C` s   | |  _  d S(   sN   
        Set the default font weight.  The initial value is 'normal'.
        N(   R5  (   R   R   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   set_default_weightX  s    c         C` s
   t   d S(   sd   
        Update the font dictionary with new font files.
        Currently not implemented.
        N(   R   (   R   t	   filenames(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   update_fonts^  s    c   	      C` s  t  | t t f  s! | g } n t |  d k r7 d S| j   } d t |  } x t |  D] \ } } | j   } | t k r | d k r d } n  t d | } g  | D] } | j   ^ q } | | k r| j |  } | | t |  | Sq` | | k r` | | Sq` Wd S(	   s'  
        Returns a match score between the list of font families in
        *families* and the font family name *family2*.

        An exact match at the head of the list returns 0.0.

        A match further down the list will return between 0 and 1.

        No match will return 1.0.
        i    g      ?i   R%   s
   sans serifs
   sans-serifs   font.(   R%   s
   sans serif(	   RM   RY   R   R}   RS   t	   enumeratet   font_family_aliasesR   t   index(	   R   t   familiest   family2t   stept   it   family1t   optionst   xt   idx(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   score_familyh  s&    	c         C` s0   | | k r d S| d k r, | d k r, d Sd S(   s   
        Returns a match score between *style1* and *style2*.

        An exact match returns 0.0.

        A match between 'italic' and 'oblique' returns 0.1.

        No match returns 1.0.
        g        R   R   g?g      ?(   R   R   (   R   R   (    (   R   t   style1t   style2(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   score_style  s    
c         C` s   | | k r d Sd Sd S(   s~   
        Returns a match score between *variant1* and *variant2*.

        An exact match returns 0.0, otherwise 1.0.
        g        g      ?N(    (   R   t   variant1t   variant2(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   score_variant  s    c         C` s~   y t  |  } Wn# t k
 r5 t j | d  } n Xy t  |  } Wn# t k
 rk t j | d  } n Xt | |  d S(   s   
        Returns a match score between *stretch1* and *stretch2*.

        The result is the absolute value of the difference between the
        CSS numeric values of *stretch1* and *stretch2*, normalized
        between 0.0 and 1.0.
        i  g     @@(   R   R   R   R   t   abs(   R   t   stretch1t   stretch2t   stretchval1t   stretchval2(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   score_stretch  s    c         C` s   t  | t j  r4 t  | t j  r4 | | k r4 d Sy t |  } Wn# t k
 ri t j | d  } n Xy t |  } Wn# t k
 r t j | d  } n Xd t | |  d d S(   si  
        Returns a match score between *weight1* and *weight2*.

        The result is 0.0 if both weight1 and weight 2 are given as strings
        and have the same value.

        Otherwise, the result is the absolute value of the difference between the
        CSS numeric values of *weight1* and *weight2*, normalized
        between 0.05 and 1.0.
        g        i  gffffff?g     @@g?(   RM   RN   RO   R   R   R   R   RV  (   R   t   weight1t   weight2t
   weightval1t
   weightval2(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   score_weight  s    c         C` s|   | d k r d Sy t  |  } Wn" t k
 rD |  j t | } n Xy t  |  } Wn t k
 ri d SXt | |  d S(   s  
        Returns a match score between *size1* and *size2*.

        If *size2* (the size specified in the font file) is 'scalable', this
        function always returns 0.0, since any font size can be generated.

        Otherwise, the result is the absolute distance between *size1* and
        *size2*, normalized so that the usual range of font sizes (6pt -
        72pt) will lie between 0.0 and 1.0.
        R   g        g      ?g      R@(   R   R   R6  R   RV  (   R   t   size1t   size2t   sizeval1t   sizeval2(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt
   score_size  s    R*   c         C` s(  t  | t  s t |  } n  | j   } | d k	 rJ t j d |  | S| d k rb |  j } n	 |  j } | d k r t | j	 |  } | d k	 r | Sn t
 j j |  } d }	 d }
 x| D]} | d k	 rt
 j j t
 j j | j  | g  | k rq n  |  j | j   | j  d |  j | j   | j  |  j | j   | j  |  j | j   | j  |  j | j   | j  |  j | j   | j   } | |	 k  r| }	 | }
 n  | d k r Pq q W|
 d k s|	 d k r{| rJt! j" d | j   |  j# | f  | j$   } | j% |  j# |  |  j& | | | t'  St! j" d | |  j( | f t)  |  j( | } n2 t j d | |
 j t* |
 j  |	 f  |
 j } t
 j j+ |  s| rt j, d	  t-   t. j& | | | t/ t'  St0 d
   n  | d k r$t | j1 | |  n  | S(   s  
        Search the font list for the font that most closely matches
        the :class:`FontProperties` *prop*.

        :meth:`findfont` performs a nearest neighbor search.  Each
        font is given a similarity score to the target font
        properties.  The first font with the highest score is
        returned.  If no matches below a certain threshold are found,
        the default font (usually DejaVu Sans) is returned.

        `directory`, is specified, will only return fonts from the
        given directory (or subdirectory of that directory).

        The result is cached, so subsequent lookups don't have to
        perform the O(n) nearest neighbor search.

        If `fallback_to_default` is True, will fallback to the default
        font family (usually "DejaVu Sans" or "Helvetica") if
        the first lookup hard-fails.

        See the `W3C Cascading Style Sheet, Level 1
        <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_ documentation
        for a description of the font finding algorithm.
        s   findfont returning %sR   g?O8Mg      $@i    s6   findfont: Font family %s not found. Falling back to %ss*   findfont: Could not match %s. Returning %ss1   findfont: Matching %s to %s (%s) with score of %fs7   findfont: Found a missing font file.  Rebuilding cache.s   No valid font could be foundN(2   RM   R   R   RF   R   R   R<  R:  R$  R   RA   RB   t   normcaset   commonprefixRx   RO  R   R   RR  R   R   RU  R   R   R`  R   R   R[  R   R   Re  R   R   Rh   Ri   R8  R  R   R   t   FalseR9  t   UserWarningt   reprt   isfileR   t   _rebuildR(  t   TrueR   RG   (   R   R   R,   R2   t   fallback_to_defaultt   rebuild_if_missingRx   R   t   cachedt
   best_scoret	   best_fontR   t   scoret   default_propt   result(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     sp    		 	N(   R   R   R   R3  RF   R   R@  t   staticmethodR   RA  RC  RO  RR  RU  R[  R`  Re  Rm  R   (    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s   0			
	!					c         C` s   t  j j |   d j   d k r t j |   } | d k r} t |  d   } | j d  } Wd QX| d k } | t |  <n  | St	 S(   s   
    Returns True if the given font is a Postscript Compact Font Format
    Font embedded in an OpenType wrapper.  Used by the PostScript and
    PDF backends that can not subset these fonts.
    i   s   .otfR   i   Nt   OTTO(
   RA   RB   RT   RS   t   _is_opentype_cff_font_cacheR   RF   R   t   readRh  (   R  Ru  t   fdt   tag(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   is_opentype_cff_fontT  s    "i@   c         C` s&   | d  k r t d } n  t |  |  S(   Ns   text.hinting_factor(   RF   R   t	   _get_font(   R  t   hinting_factor(    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR   j  s    c         C` s   t  |  } d | } yA t j d d d |  g d t j d t j } | j   d } Wn t t f k
 rq d  SX| j d k r xq | j	 d  D]] } y t
 j | t j    } Wn t k
 r q n Xt j j |  d	 d	 | k r | Sq Wn  d  S(
   Nt   .s   fc-matchs   -ss   --format=%{file}\nt   stdoutt   stderri    s   
i   (   R-   R
   t   Popent   PIPEt   communicateR?   R   RF   t
   returncodeRP   RN   Rp   Rq   Rr   Rs   RA   RB   RT   (   R5   R,   R   R4   t   pipet   outputRx   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   fc_matchs  s&    
	 c         C` s{   t  |  t j  s! |  j   }  n  t j |   } | d  k	 r@ | St |  |  } | d  k rm t d |  } n  | t |  <| S(   NR1  (   RM   RN   RO   R   t   _fc_match_cacheR   RF   R  (   R   R,   Rp  Ru  (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    
s   fontList.jsonR   c           C` sF   t    a t r5 t j t   t t t  Wd  QXn  t j d  d  S(   Ns   generated new fontManager(	   R   R(  t   _fmcacheR   t   Lockedt   cachedirR  R   R   (    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyRl    s
    	R4  s"   Using fontManager instance from %sc         K` s   t  j |  |  } | S(   N(   R(  R   (   R   t   kwR   (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyR     s    (`   R   t
   __future__R    R   R   RN   t   collectionsR   R  RA   Rq   t	   threadingR   R:   t   dummy_threadingRh   t   loggingt
   matplotlibR   R   R   R   R	   t   matplotlib.compatR
   t   matplotlib.fontconfig_patternR   R   t	   functoolsR   t   backports.functools_lru_cachet	   getLoggerR   R   Rh  t   USE_FONTCONFIGRF   R   R   R   RE  R=   RH   R~   Rc   R|   RC   R   t   homeRB   R/   Rt   R-   R6   RE   Ra   Rg   Ry   Rz   R   t
   deprecatedR   t   objectR   R   R   R   R   R  R  R  R  R"  R   R#  R   Rx  R|  R(  R  R   R}  R   R  R  R   R  R$  Rl  t   hasattrR4  R3  R6  R   R  t   TimeoutError(    (    (    s6   lib/python2.7/site-packages/matplotlib/font_manager.pyt   <module>   s  (


					
	
	0*	W	D7 D
		
		% G			
	

	