
H_Gc           @   s.  d  Z  d d k Z d d k Z d d k Z d d k Z d d k l Z d d k Z d d k l Z d d k l	 Z	 d d k l
 Z
 l Z l Z d d k l Z d d k l Z l Z y d d k Z Wn e j
 o d d k Z n Xe Z e i Z h  d	 d
 <d d <d d <d d <d d <d d <d d <d d <d d <Z h  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* d+ <Z d, Z d- d. g Z d/ d0 d1 d2 g Z d3 d4 d5 g Z e pn e i i d6  Z  e  d j	 oK e i" i# e  d7 d8  Z" e i$ e"  e i" i# e  d9  Z" e i$ e"  qon d:   Z% d;   Z& d d< d=  Z' d>   Z( d d< d?  Z) d@   Z* d< dA  Z+ d d< dB  Z, dC   Z- dD e. f dE     YZ/ dF   Z0 dG   Z1 dH   Z2 d< dI  Z3 dJ   Z4 dK e. f dL     YZ5 dM   Z6 dN   Z7 dO   Z8 dP d[ dQ     YZ9 h  Z: dR   Z; e oJ e i< dS j o: d d k= Z= dT   Z> e= i? dU  Z@ h  ZA d< dV  ZB nl e i" i# e   dW  ZC d aD dX   ZE y* e8 eC  aD d tD _F e iG dY eC  Wn eE   n XdZ   ZB d S(\   s  
A module for finding, managing, and using fonts across-platforms.

This module provides a single FontManager that can be shared across
backends and platforms.  The findfont() function returns the best
TrueType (TTF) font file in the local or system font path that matches
the specified FontProperties.  The 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.


KNOWN ISSUES

  - documentation
  - font variant is untested
  - font stretch is incomplete
  - font size is incomplete
  - font size_adjust is incomplete
  - default font algorithm needs improvement and testing
  - setWeights function needs improvement
  - 'light' is an invalid weight value, remove it.
  - update_fonts not implemented


Authors   : John Hunter <jdhunter@ace.bsd.uchicago.edu>
            Paul Barrett <Barrett@STScI.Edu>
Copyright : John Hunter (2004,2005), Paul Barrett (2004,2005)
License   : matplotlib license (PSF compatible)
            The font directory code is from ttfquery,
            see license/LICENSE_TTFQUERY.
iN(   t   Set(   t   afm(   t   ft2font(   t   rcParamst   get_homet   get_configdir(   t   is_string_like(   t   parse_fontconfig_patternt   generate_fontconfig_patterngI+?s   xx-smallgh|?5?s   x-smallg-?t   smallg      ?t   mediumg333333?t   largeg
ףp=
?s   x-largegS?s   xx-larget   largert   smalleri   t   lighti  t   normalt   regulart   booki  t   romaniX  t   semiboldt   demiboldt   demii  t   boldi   t   heavys
   extra boldi  t   blacks@   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/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/t   HOMEt   Libraryt   Fontss   .fontsc         C   s   h  d d <d d <|  S(   Nt   ttft   otfR   (   R   R   (   s   afm(    (   t   fontext(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_fontext_synonymsb   s    c          C   s   y d d k  }  Wn t j
 o nZ X|  i |  i t  } z2 y |  i | d  d SWn t j
 o n XWd |  i |  Xt i	 i
 t i d d  S(   s3   Return the user-specified font directory for Win32.iNR   i    t   WINDIR(   t   _winregt   ImportErrort   OpenKeyt   HKEY_CURRENT_USERt	   MSFolderst   QueryValueExt   OSErrort   CloseKeyt   ost   patht   joint   environ(   R!   t   user(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   win32FontDirectoryf   s    	R   c         C   s  d d k  } |  d j o t   }  n t |  } d h  } } xt D]} y | i | i |  } Wn t j
 o
 qF n X| pH g  } x7 | D]/ } | i t	 i	 t
 i i |  d |    q W| Sn z x t | i |  d  D] }	 y | i | |	  \ } }
 } t
 i i |
  p t
 i i |  |
  }
 n t
 i i |
  i   }
 t
 i i |
  d d | j o d | |
 <n Wq t j
 o
 q q t j
 o
 q q Xq W| i   SWd | i |  XqF Wd S(   s   
    Search for fonts in the specified font directory, or use the
    system directories if none given.  A list of TrueType fonts are
    returned by default with AFM fonts as an option.
    iNs   *.i   (   R!   t   NoneR.   R   t   MSFontDirectoriesR#   t   HKEY_LOCAL_MACHINER'   t   extendt   globR)   R*   R+   t   ranget   QueryInfoKeyt	   EnumValuet   dirnamet   abspatht   lowert   splitextt   EnvironmentErrort   WindowsErrort   keysR(   (   t	   directoryR   R!   t   keyt   itemst   fontdirt   localt   filest   extt   jt   direct   any(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   win32InstalledFontsx   sD      - !c       
      s}   g      f d   }  xa t  D]Y } y1 t i i |  o t i i | |  d  n Wq t t t t	 f j
 o q Xq W  S(   s,   Return the system font directories for OS X.c            s     i  |  d  S(   N(   t   append(   t   argR>   RC   (   t	   fontpaths(    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   add   s    N(
   t   OSXFontDirectoriesR)   R*   t   isdirt   walkR/   t   IOErrorR'   t	   TypeErrort
   ValueError(   RL   RA   (    (   RK   s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   OSXFontDirectory   s     	c         C   s   |  d j o t   }  n t |  } g  } x |  D] } | d j o) | i t i t i i | d    q3 xf | D]^ } | i t i t i i | d |    | i t i t i i | d | i      qv Wq3 W| S(   s?   Get list of font files on OS X - ignores font suffix by defaultt   *s   *.N(	   R/   RS   R   R2   R3   R)   R*   R+   t   upper(   R>   R   RC   R*   RD   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   OSXInstalledFonts   s     ) )7c       
      s}   g      f d   }  xa t  D]Y } y1 t i i |  o t i i | |  d  n Wq t t t t	 f j
 o q Xq W  S(   s+   Return the system font directories for X11.c            s     i  |  d  S(   N(   RI   (   RJ   R>   RC   (   RK   (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyRL      s    N(
   t   X11FontDirectoriesR)   R*   RN   RO   R/   RP   R'   RQ   RR   (   RL   RA   (    (   RK   s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   x11FontDirectory   s     	c      	   C   s   y d d k  } Wn t j
 o h  Sn Xt |   }  h  } | i d  \ } } | d j os xp | i d  D][ } | i d  d } t i i |  d d |  j o! t i i |  o d | | <qn qn Wn | S(   s   Grab a list of all the fonts that are being tracked by fontconfig.
    This is an easy way to grab all of the fonts the user wants to be made
    available to applications, without knowing where all of them reside.iNs   fc-list filei    s   
t   :i   (	   t   commandsR"   R   t   getstatusoutputt   splitR)   R*   R:   t   exists(   R   RZ   t	   fontfilest   statust   outputt   linet   fname(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_fontconfig_fonts   s    	 !c         C   s  h  } t  |  } |  d j o t i d j o} t   } | g }  x t |  D]V } t i i |  \ } } t	 |  d j o% | d i
   | j o d | | <qN qN Wq5t   }  t i d j o( x% t d |  D] } d | | <q Wn xE t |  D] } d | | <q Wn$ t |  t t f  o |  g }  n x |  D] } g  }	 xf | D]^ } |	 i t i t i i | d |    |	 i t i t i i | d | i      qOWx$ |	 D] }
 d | t i i |
  <qWq<Wg  } | i   D]$ }
 t i i |
  o | |
 q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.
    t   win32i   t   darwinR   s   *.N(   R   R/   t   syst   platformR.   RH   R)   R*   R:   t   lenR9   RX   RV   Rc   t
   isinstancet   strt   unicodeR2   R3   R+   RU   R8   R=   R]   (   RK   R   R^   t   fontextsRA   t   ft   baseRD   R*   RC   Rb   t   _[1](    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   findSystemFonts   s@    		 *	    )3 c         C   sn   t  |  t  o4 y t |  i   }  Wqj t j
 o d }  qj Xn' |  t d d d  j o 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(   Ri   Rj   t   weight_dictR9   t   KeyErrorR4   RR   (   t   weight(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   weight_as_number  s    	t   FontKeyc           B   s)   e  Z d  Z d d d d d d d  Z RS(   sc   
    A class for storing Font properties.  It is used when populating
    the font dictionary.
    t    R   R
   c         C   si   | |  _  | |  _ | |  _ | |  _ | |  _ y t t |   |  _ Wn t j
 o | |  _ n Xd  S(   N(	   t   namet   stylet   variantRs   t   stretchRj   t   floatt   sizeRR   (   t   selfRw   Rx   Ry   Rs   Rz   R|   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   __init__+  s    					(   t   __name__t
   __module__t   __doc__R~   (    (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyRu   %  s   c      	   C   sz  |  i  } |  i   } | i d  } | i d  } | o | i   } n d } | o | i   } n d } | i d  d j o
 d } nb | i d  d j o
 d } nB | i d  d j o
 d	 } n" |  i t i @o
 d } n d	 } | i   d j o
 d } n d	 } d } x5 t	 i
   D]' } | i |  d j o | } Pq$q$W| p% |  i t i @o
 d } q{d } n t |  } | i d  d j p, | i d  d j p | i d  d j o
 d }	 n] | i d  d j o
 d }	 n= | i d  d j p | i d  d j o
 d }	 n d	 }	 |  i o
 d }
 n t t |  i     }
 d } t | | | | |	 |
  S(   sj   
    A function for populating the FontKey by extracting information
    from the TrueType font file.
    i   i    i   i   Rv   t   obliquet   italicR   R   t   capitalss
   small-capsi  i  t   narrowt	   condensedt   conds	   demi conds   semi-condensedt   widet   expandedt   scalable(   i   i    i    i   (   i   i    i    i   (   R   s
   small-capsN(   t   family_namet   get_sfntt   getR9   t   findt   style_flagsR   t   ITALICR/   Rq   R=   t   BOLDRt   R   Rj   R{   t   get_fontsizeRu   (   t   fontRw   t   sfntt   sfnt2t   sfnt4Rx   Ry   Rs   t   wRz   R|   t   size_adjust(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   ttfFontProperty>  s\    	




 	


,

,



c         C   s   |  i    } |  i   d j p | i   i d  d j o
 d } n- | i   i d  d j o
 d } n d } | i   d j o
 d } n d } t |  i   i    } d } d } d	 } t | | | | | |  S(
   se   
    A function for populating the FontKey by extracting information
    from the AFM font file.
    i    R   R   R   R   s
   small-capsR   (   s   capitalss
   small-capsN(   t   get_familynamet	   get_angleR9   R   Rt   t
   get_weightR/   Ru   (   R   Rw   Rx   Ry   Rs   Rz   R|   R   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   afmFontProperty  s    /



c         C   s   y t  t | i   } Wn t j
 o | i } n X|  i | i h   i | i h   i | i h   i | i h   i | i	 h   } | | | <d S(   s   
    A function to add a font file name to the font dictionary using
    the FontKey properties.  If a font property has no dictionary, then
    create it.
    N(
   Rj   R{   R|   RR   t
   setdefaultRw   Rx   Ry   Rs   Rz   (   t   fontdictt   propRb   R|   t   d(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   add_filename  s    c   	      C   s  h  } h  } x|  D]} t  i d | d  t i i |  d } | i |  o q n d | | <| d j o y t | d  } Wn t  i d |  q n Xy% z t i |  } Wd | i	   XWn' t
 j
 o t  i d |  q n Xt |  } n y t i t |   } WnI t
 j
 o t  i d |  q n$ t j
 o t  i d	  q n Xy t |  } Wn
 q n Xt | | |  q W| S(
   s   
    A function to create a dictionary of font file paths.  The
    default is to create a dictionary for TrueType fonts.  An AFM font
    dictionary can optionally be created.
    s   createFontDict: %st   debugi   R   t   rs   Could not open font file %sNs   Could not parse font file %ss   Cannot handle unicode filenames(   t   verboset   reportR)   R*   R\   t   has_keyt   openR   t   AFMt   closet   RuntimeErrorR   R   t   FT2FontRj   t   UnicodeErrorR   R   (	   R^   R   R   t   seent   fpathRb   t   fhR   R   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   createFontDict  sD     

c         C   s  |  i    } t |  d j o? | i   d } x, t d d d  D] } | | |  | <qB Wn | i d  o/ x, t d d d  D] } | d |  | <q Wn | i d  on | i d  o/ xW t d d d  D] } | d |  | <q Wqx, t d d d  D] } | d |  | <q Wn | i d  o, x) d d d g D] } | d |  | <q;Wn | i d  oe | i d  o) xN d d g D] } | d |  | <qWqx) d d d g D] } | d |  | <qWn | i d	  o/ x, d
 d d	 d g D] } | d	 |  | <qWn | i d  oh | i d	  o) xQ d
 d g D] } | d |  | <q8Wqx, d
 d d	 d g D] } | d |  | <qgWn d S(   s   
    A function to populate missing values in a font weight
    dictionary.  This proceedure is necessary since the font finding
    algorithm always matches on the weight property.
    i   i    id   i  i  i  i,  i   i   iX  i  i  N(   t   copyRh   R=   R4   R   (   R   t   tempt   wgtRE   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt
   setWeights  sT              t   FontPropertiesc        	   B   s  e  Z d  Z d e f d     YZ 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 d   Z d   Z d   Z d   Z d   Z e Z d   Z d   Z d   Z d   Z d   Z d   Z e Z d   Z d   Z d   Z RS(   sV  
    A class for storing and manipulating font properties.

    The font properties are those described in the W3C Cascading Style
    Sheet, Level 1 (CSS1; 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 last item is the default font name and is given the
                name of the font family, either serif, sans-serif,
                cursive, fantasy, and monospace.
      style   - Either normal, italic or oblique.
      variant - Either normal or small-caps.
      stretch - Either an absolute value of ultra-condensed, extra-
                condensed, condensed, semi-condensed, normal, semi-
                expanded, expanded, extra-expanded or ultra-expanded;
                or a relative value of narrower or wider.
                This property is currently not implemented and is set to
                normal.
      weight  - A numeric value in the range 100, 200, 300, ..., 900.
      size    - Either an absolute value of xx-small, x-small, small,
                medium, large, x-large, xx-large; or a relative value
                of smaller or larger; or an absolute font size, e.g. 12;
                or scalable.

    The default font property for TrueType fonts is: sans-serif, normal,
    normal, normal, 400, scalable.

    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, i.e. by using the set_default_size() method of the
    font manager.

    This class will also accept a fontconfig pattern, if it is the only
    argument provided.  fontconfig patterns are described here:

      http://www.fontconfig.org/fontconfig-user.html

    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.
    t   FontPropertiesSetc           B   s   e  Z d  Z e d e d Z e e  o e g Z n e d g Z e d g Z e d g Z e d g Z	 e d g Z
 d Z RS(	   s   This class contains all of the default properties at the
        class level, which are then overridden (only if provided) at
        the instance level.s   font.s   font.familys
   font.styles   font.variants   font.weights   font.stretchs	   font.sizeN(   R   R   R   R   t   familyR   t   slantRy   Rs   Rz   R|   R/   t   file(    (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR   t  s   c	   	      C   s  |  i    |  _ | d  j	 o |  i i i |  d  Sn t |  ox | d  j o^ | d  j oQ | d  j oD | d  j o7 | d  j o* | d  j o |  i |  |  i _ d  Sn | g } n |  i |  |  i |  |  i	 |  |  i
 |  |  i |  |  i |  |  i |  d  S(   N(   R   t   _FontProperties__propsR/   t   __dict__t   updateR   t   _parse_fontconfig_patternt
   set_familyt	   set_stylet   set_variantt
   set_weightt   set_stretcht   set_filet   set_size(	   R}   R   Rx   Ry   Rs   Rz   R|   Rb   t   _init(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR~     s*    c         C   s
   t  |  S(   N(   R   (   R}   t   pattern(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s    c         C   s   t  t |  i i   S(   N(   t   hasht   reprR   R   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   __hash__  s    c         C   s
   |  i    S(   N(   t   get_fontconfig_pattern(   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   __str__  s    c         C   s
   |  i  i S(   sC   Return a list of font names that comprise the font family.
        (   R   R   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt
   get_family  s    c         C   s   t  i t t |     i S(   sB   Return the name of the font that best matches the font properties.(   R   R   Rj   t   findfontR   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_name  s    c         C   s   |  i  i d S(   s>   Return the font style.  Values are: normal, italic or oblique.i    (   R   R   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt	   get_style  s    c         C   s   |  i  i d S(   s;   Return the font variant.  Values are: normal or small-caps.i    (   R   Ry   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_variant  s    c         C   s   |  i  i d S(   sp   
        Return the font weight.  See the FontProperties class for a
        a list of possible values.
        i    (   R   Rs   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s    c         C   s   |  i  i d S(   sm   
        Return the font stretch or width.  Options are: normal,
        narrow, condensed, or wide.
        i    (   R   Rz   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_stretch  s    c         C   s   t  |  i i d  S(   s   Return the font size.i    (   R{   R   R|   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_size  s    c         C   s-   |  i  i d  j	 o |  i  i d Sn d  Sd  S(   Ni    (   R   R   R/   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_file  s    c         C   s   t  |  i i  S(   N(   R   R   R   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s    c         C   sQ   | d j o |  i i i d d  n' t |  o | g } n | |  i _ d S(   s   
        Change the font family.  May be either an alias (generic name
        is CSS parlance), such as: serif, sans-serif, cursive,
        fantasy, or monospace, or a real font name.
        R   N(   R/   R   R   t   popR   R   (   R}   R   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s
    c         C   sW   | d j o |  i i i d d  n- | d j o t d   n | g |  i _ d S(   s;   Set the font style.  Values are: normal, italic or oblique.Rx   R   R   R   s'   style must be normal, italic or obliqueN(   s   normals   italics   oblique(   R/   R   R   R   RR   R   (   R}   Rx   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s
    c         C   sW   | d j o |  i i i d d  n- | d j o t d   n | g |  i _ d S(   s8   Set the font variant.  Values are: normal or small-caps.Ry   R   s
   small-capss$   variant must be normal or small-capsN(   s   normals
   small-caps(   R/   R   R   R   RR   Ry   (   R}   Ry   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s
    c         C   sj   | d j o |  i i i d d  n@ | t j o# | t i   j o t d   n | g |  i _ d S(   sm   
        Set the font weight.  See the FontProperties class for a
        a list of possible values.
        Rs   s   weight is invalidN(   R/   R   R   R   Rq   R=   RR   Rs   (   R}   Rs   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s    c         C   s:   | d j o |  i i i d d  n | g |  i _ d S(   sj   
        Set the font stretch or width.  Options are: normal, narrow,
        condensed, or wide.
        Rz   N(   R/   R   R   R   Rz   (   R}   Rz   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s    c         C   s   | d j o |  i i i d d  n} t |  o@ t i   } t i |  } | d j	 o | | } qt | } n t	 | t
 t f  o | g } n | |  i _ d S(   s   Set the font size.R|   N(   R/   R   R   R   R   t   fontManagert   get_default_sizet   font_scalingsR   Ri   t   intR{   R|   (   R}   R|   t   parent_sizet   scaling(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s    
c         C   s:   | d  j o |  i i i d d   n | g |  i _ d  S(   NR   (   R/   R   R   R   R   (   R}   R   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR   %  s    c         C   s   |  i  |  |  i _ d  S(   N(   R   R   R   (   R}   R   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   set_fontconfig_pattern-  s    c         C   s    |  i  i | g   i |  d  S(   N(   R   R   RI   (   R}   R?   t   val(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   add_property_pair0  s    c         C   s   t  d |  i i  S(   s   Return a deep copy of selfR   (   R   R   R   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR   3  s    N(   R   R   R   t   objectR   R/   R~   R   R   R   R   R   R   R   R   R   R   R   R   R   t   set_nameR   R   R   R   R   R   t   get_size_in_pointsR   R   R   (    (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR   F  sD   ,																			
				c         C   s   g  } x |  i    D] } x} | i    D]o } xf | i    D]X } xO | i    D]A } x8 | i    D]* } x! | i    D] } | i |  qr Wq_ WqL Wq9 Wq& Wq W| S(   s2   flatten a ttfdict to all the filenames it contains(   t   valuesRI   (   R   t   fnamest   namedt   styledt   variantdt   weightdt   stretchdRb   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   ttfdict_to_fnames7  s          %c         C   s5   t  | d  } z t i |  |  Wd | i   Xd S(   sk   Equivalent to pickle.dump(data, open(filename, 'w'))
    but closes the file to prevent filehandle leakage.R   N(   R   t   picklet   dumpR   (   t   datat   filenameR   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   pickle_dumpC  s    c         C   s4   t  |  d  } z t i |  } Wd | i   X| S(   se   Equivalent to pickle.load(open(filename, 'r'))
    but closes the file to prevent filehandle leakage.R   N(   R   R   t   loadR   (   R   R   R   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   pickle_loadL  s
    t   FontManagerc           B   sV   e  Z d  Z d
 d d  Z d   Z d   Z d   Z d   Z d   Z	 d d	  Z
 RS(   s  
    On import, the FontManager creates a dictionary of TrueType
    fonts based on the font properties: name, style, variant, weight,
    stretch, and size.  The findfont() method searches this dictionary
    for a font file name that exactly matches the font properties of the
    specified text.  If none is found, a default font is returned.  By
    updating the dictionary with the properties of the found font, the
    font dictionary can act like a font cache.
    R   c   	      C   s#  | |  _  | |  _ t i i t d d d  t i i t d d d  g } x d d g D] } t i i |  o~ t i | } | i d  d j o | i	 | i
 d   q | i d	  d j o | i	 | i
 d	   q | i |  qW qW Wt i d
 t |   t |  t   |  _ x_ |  i D]D } t i d | d  | i   i d  d j o | |  _ Pq)q)W|  i d |  _ t |  i  |  _ t d oG t i i t d d d  } t | d d } t | d d |  _ n; t | d d t d d  |  _ t |  i d d |  _ d  S(   Nt   datapatht   fontsR   R   t   TTFPATHt   AFMPATHt   ;i    RY   s   font search path %ss   trying fontname %sR   s   vera.ttfs   pdf.use14corefontst   pdfcorefontsR   (   t   _FontManager__default_weightt   default_sizeR)   R*   R+   R   R,   R   R   R2   R\   RI   R   R   Rj   Rp   t   ttffilesR9   t   defaultFontR   t   ttfdictt   afmdictt   afmfiles(	   R}   R|   Rs   t   pathst   pathnamet   ttfpathRb   t   afmpathR   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR~   a  s<    		 
 		c         C   s   |  i  S(   s   Return the default font weight.(   R   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   get_default_weight  s    c         C   s#   |  i  d j o t d Sn |  i  S(   s   Return the default font size.s	   font.sizeN(   R   R/   R   (   R}   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     s    c         C   s   | |  _  d S(   s<   Set the default font weight.  The initial value is 'normal'.N(   R   (   R}   Rs   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   set_default_weight  s    c         C   s   | |  _  d S(   sR   Set the default font size in points.  The initial value is set by font.size in rc.N(   t   _FontManager__default_size(   R}   R|   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   set_default_size  s    c         C   s
   t   d S(   sd   
        Update the font dictionary with new font files.
        Currently not implemented.
        N(   t   NotImplementedError(   R}   t	   filenames(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   update_fonts  s    R   c      
      s  t  } t   o t    n  i   } | d j	 o t i d | d  | Sn | d j o |  i  n
 |  i   i	   d }  i
     i    t  i       i    t  i             f d   } t d d d d	 d
 d g  } x  i	   D]w } | | j oL | d j o
 d } n x> t d | D] }	 | |	  } | o PqXqXWn | |  } | o PqqW| ph t d i  i	           }
 t  |
 |  i  t i d |    |  i f  |  i Sn | S(   s  
        Search the font dictionary for a font that exactly or closely
        matches the specified font properties.  See the FontProperties class
        for a description.

        The properties are searched in the following order: name, style,
        variant, weight, stretch, and size.  The font weight always matches
        returning the closest weight, and the font size always matches for
        scalable fonts.  An oblique style font will be used inplace of a
        missing italic style font if present.  See the W3C Cascading Style
        Sheet, Level 1 (CSS1; http://www.w3.org/TR/1998/REC-CSS2-19980512/)
        documentation for a description of the font finding algorithm.
        s   findfont returning %sR   R   i    c            s-  yQ  |        } t  i d t   d  t  i d | d  | SWn t j
 o n Xd  }  } | i |   o | |  } n t  i d t   d  d  S| i    o |   } nr   d j o | i d  o | d } nG   d j o | i d  o | d } n t  i d t   d  d  S| i   o |  } n t  i d t   d  d  S| i   p t |  n | i   p d  Sn |  } | i   oJ |  } | i d	  o | d	 } q| i   o |  } qn | d  j o: x7 | i   D]% } | i d	  o | d	 } Pq(q(Wn | d  j o: x7 | i   D]% } | i   o |  } PqoqoWn | d  j o t  i d
 t   d  nf t d i	  i
           } t  | |  t  i d t   d  t  i d | d  | S(   NsT   	findfont cached %(name)s, %(style)s, %(variant)s, %(weight)s, %(stretch)s, %(size)sR   s   findfont returning %ss   	findfont failed %(name)sR   R   s$   	findfont failed %(name)s, %(style)ss1   	findfont failed %(name)s, %(style)s, %(variant)sR   sI   	findfont failed %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)st   ,sR   	findfont found %(name)s, %(style)s, %(variant)s %(weight)s, %(stretch)s, %(size)s(   R   R   t   localsRr   R/   R   R   R   Ru   R+   R   R   (   Rw   Rb   R   t   stretch_fontR   t   fontkey(   Rx   Rs   Rz   Ry   R   R   R|   (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   lookup_name  sn    

 
 
*t   serifs
   sans-serift   cursivet   fantasyt	   monospacet   sanss   font.R
  s)   Could not match %s, %s, %s.  Returning %sN(   t   FalseR   R   R   R/   R   R   R   R   R   R   R   Rt   R   R   Rj   R   R    R   Ru   R+   R   R   (   R}   R   R   R   Rb   t   original_nameR  t   font_family_aliasesRw   t   name2R  (    (   Rs   R|   Rx   Rz   R   Ry   R   s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR     sL    	!C 
 	* N(   R   R   R   R/   R~   R  R   R  R  R	  R   (    (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR   V  s   	2					c         C   s   t  i i |   d i   d j of t i |   } | d j oB t |  d  } | i d  } | i	   | d j } | t |  <n | Sn t
 S(   sv   
    Returns True if the given font is a Postscript Compact Font Format
    Font embedded in an OpenType wrapper.
    i   s   .otft   rbi   t   OTTON(   R)   R*   R:   R9   t   _is_opentype_cff_font_cacheR   R/   R   t   readR   R  (   R   t   resultt   fdt   tag(    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   is_opentype_cff_font+  s    #
Rd   c   	      C   s   d d  k  } t |  } d | } | i d |   \ } } | d j oV xS t i |  D]> } | i d  } t i i |  d d | j o | SqX qX Wn d  S(   Nit   .s   fc-match -sv "%s"i    i   (
   RZ   R   R[   t   _fc_match_regext   finditert   groupR)   R*   R:   R/   (	   R   R   RZ   Rl   RD   R_   R`   t   matchR   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   fc_match?  s    
 !s   \sfile:\s+"([^"]*)"c         C   s~   t  |   p |  i   }  n t i |   } | d  j	 o | Sn t |  |  } | d  j o t d |  } n | t |  <| S(   NRY   (   R   R   t   _fc_match_cacheR   R/   R%  (   R   R   t   cachedR  (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR   N  s    
s   fontManager.cachec           C   s'   t    a t t t  t i d  d  S(   Ns   generated new fontManager(   R   R   R   t   _fmcacheR   R   (    (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyt   _rebuilda  s    	s"   Using fontManager instance from %sc         K   sW   t  i |  |  } t i i |  p. t i d |  t   t  i |  |  } n | S(   Ns1   %s returned by pickled fontManager does not exist(   R   R   R)   R*   R]   R   R   R)  (   R   t   kwR   (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pyR   n  s    (    (H   R   R)   Rf   R3   t   shutilt   setsR    t
   matplotlibR   R   R   R   R   t   matplotlib.cbookR   t   matplotlib.fontconfig_patternR   R   t   cPickleR   R"   R  t   USE_FONTCONFIGR   R   Rq   R%   R0   RW   RM   R,   R   t   homeR/   R*   R+   RI   R   R.   RH   RS   RV   RX   Rc   Rp   Rt   R   Ru   R   R   R   R   R   R   R   R   R   R   R  R  Rg   t   reR%  t   compileR!  R&  R   R(  R   R)  R   R   (    (    (    s@   /Users/cmoad/workspace/matplotlib/lib/matplotlib/font_manager.pys   <module>"   s   0	($$					,		,		]	:	.	/				
				