ó
º¶Y]c           @` sI  d  d l  m Z m Z m Z m Z d  d l m Z d  d l Z d  d l m	 Z	 d  d l
 Z
 d  d l Z d  d l m Z d  d l m Z d  d l j Z d  d l m Z m Z d  d l m Z d  d	 l m Z d  d l j Z d  d
 l m Z m Z d  d l m Z d  d l m  Z! d e" f d „  ƒ  YZ# e# ƒ  Z$ d e f d „  ƒ  YZ% d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   OrderedDictN(   t   zip(   t   Path(   t   rcParams(   t   KERNING_DEFAULTt   LOAD_NO_HINTING(   t   LOAD_TARGET_LIGHT(   t   MathTextParser(   t   FontPropertiest   get_font(   t   Affine2D(   t   quotet
   TextToPathc           B` sª   e  Z d  Z d Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 d
 „ Z d „  Z e e d „ Z d e d „ Z d e d „ Z d „  Z d e d „ Z RS(   uF   
    A class that convert a given text to a path using ttf fonts.
    g      Y@iH   c         C` sM   t  d ƒ |  _ d |  _ d d l m } | d ƒ |  _ d |  _ d |  _ d S(   u    
        Initialization
        u   pathi    (   t   maxdicti2   N(	   R   t   mathtext_parsert   Nonet   tex_font_mapt   matplotlib.cbookR   t	   _ps_fontdt   _texmanagert   _adobe_standard_encoding(   t   selfR   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   __init__#   s    		c         C` s5   t  j d ƒ } t  j | ƒ } d „  t | j ƒ Dƒ S(   Nu   8a.encc         S` s   i  |  ] \ } } | | “ q S(    (    (   t   .0t   it   c(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pys
   <dictcomp>4   s   	 (   t   dvireadt   find_tex_filet   Encodingt	   enumeratet   encoding(   R   t   enc_namet   enc(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_adobe_standard_encoding1   s    c         C` s5   t  j | ƒ } t | ƒ } | j |  j |  j ƒ | S(   u"   
        find a ttf font.
        (   t   font_managert   findfontR   t   set_sizet
   FONT_SCALEt   DPI(   R   t   propt   fnamet   font(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt	   _get_font6   s    c         C` s   t  S(   N(   R	   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_hinting_flag@   s    c         C` sd   | j  ƒ  } y | d	 j d ƒ } Wn$ t k
 rI | d
 j d ƒ } n Xt d | | f ƒ } | S(   uO   
        Return a unique id for the given font and character-code set.
        i   i    i   u	   mac_romani   i	  u   utf-16beu   %s-%x(   i   i    i    i   (   i   i   i	  i   (   t   get_sfntt   decodet   KeyErrort   urllib_quote(   R   R-   t   ccodet   sfntt   ps_namet   char_id(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_char_idC   s    c         C` s*   | j  ƒ  d } t d | | f ƒ } | S(   uY   
        Return a unique id for the given font and character-code set (for tex).
        i   u   %s-%d(   t   get_ps_font_infoR3   (   R   R-   R4   R6   R7   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_char_id_psO   s    g        c         C` sG   | j  ƒ  \ } } | d k r= | d d … d f c | 7<n  | | f S(   uB   
        convert the ft2font glyph to vertices and codes.
        g        Ni    (   t   get_path(   R   R-   t   currxt   vertst   codes(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   glyph_to_pathW   s    c         C` sE  t  d rP |  j ƒ  } | j ƒ  } | j | | d d  ƒ\ } } } | | | f S| j ƒ  } | |  j }	 | rË | j ƒ  } | j |  j ƒ |  j j	 | d | ƒ \ }
 } } } } |
 |	 | |	 | |	 f S|  j
 | ƒ } | j | d d t ƒ| j ƒ  \ } } | d } | d } | j ƒ  } | d } | |	 | |	 | |	 f S(   Nu   text.usetext   rendereriH   g        t   flagsg      P@(   R   t   get_texmanagert   get_size_in_pointst   get_text_width_height_descentR   R)   t   copyR(   R   t   parseR.   t   set_textR	   t   get_width_heightt   get_descent(   R   t   sR+   t   ismatht
   texmanagert   fontsizet   wt   ht   dt   scalet   widtht   heightt   descentt   trasht   used_charactersR-   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyRD   `   s*    
'


c         C` s-  | sW | s9 |  j  | ƒ } |  j | | ƒ \ } } } qr |  j | | ƒ \ } } } n |  j | | ƒ \ } } } g  g  }	 }
 xp | D]h \ } } } } | | \ } } t | ƒ r† t j | ƒ | | | g } |	 j | ƒ |
 j | ƒ q† q† Wx. | D]& \ } } |	 j | ƒ |
 j | ƒ qù W|	 |
 f S(   u`  
        convert text *s* to path (a tuple of vertices and codes for
        matplotlib.path.Path).

        *prop*
          font property

        *s*
          text to be converted

        *usetex*
          If True, use matplotlib usetex mode.

        *ismath*
          If True, use mathtext parser. Effective only if usetex == False.


        (   R.   t   get_glyphs_with_fontt   get_glyphs_mathtextt   get_glyphs_text   lent   npt   arrayt   extend(   R   R+   RJ   RK   t   usetexR-   t
   glyph_infot	   glyph_mapt   rectsR=   R>   t   glyph_idt	   xpositiont	   ypositionRQ   t   verts1t   codes1(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   get_text_path|   s&    c         C` s›  d } d } g  } g  } | d k r0 t ƒ  } n  | rB t ƒ  }	 n | }	 x| D]ú }
 t |
 ƒ } | j | ƒ } | d k r‘ t d ƒ } d } n  | d k	 rµ | j | | t ƒ } n d } | j | d t ƒ} | j d } |  j	 | | ƒ } | | k r|  j
 | ƒ |	 | <n  | | d 7} | j | ƒ | j | ƒ | | 7} | } qO Wd g t | ƒ } d g t | ƒ } g  } t t | | | | ƒ ƒ |	 | f S(   uc   
        convert the string *s* to vertices and codes using the
        provided ttf font.
        i    u   ?RA   g      ð@g      P@g      ð?N(   R   R   t   ordt   get_char_indext   get_kerningR   t	   load_charR	   t   linearHoriAdvanceR8   R?   t   appendRZ   t   listR   (   R   R-   RJ   R`   t   return_new_glyphs_onlyt   lastgindR<   t
   xpositionst	   glyph_idst   glyph_map_newR   R4   t   gindt   kernt   glypht   horiz_advanceR7   t
   ypositionst   sizesRa   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyRW   ©   sB    		

c         C` s&  | j  ƒ  } | j |  j ƒ |  j j | |  j | ƒ \ } } } } }	 | sX t ƒ  } n  | rj t ƒ  }
 n | }
 g  } g  } g  } g  } d \ } } xÇ | D]¿ \ } } } } } |  j | | ƒ } | | k r| j ƒ  | j |  j |  j ƒ | j	 | d t
 ƒ} |  j | ƒ |
 | <n  | j | ƒ | j | ƒ | j | ƒ | |  j } | j | ƒ q› Wg  } x |	 D]• \ } } } } | | f | | | f | | | | f | | | f | | f d g } t j t j t j t j t j t j g } | j | | f ƒ qkWt t | | | | ƒ ƒ |
 | f S(   uc   
        convert the string *s* to vertices and codes by parsing it with
        mathtext.
        i    RA   (   i    i    (   i    i    (   RE   R(   R)   R   RF   R*   R   R8   t   clearRk   R	   R?   Rm   R   t   MOVETOt   LINETOt	   CLOSEPOLYRn   R   (   R   R+   RJ   R`   Ro   RR   RS   RT   t   glyphsRa   Rs   Rq   Rx   Rr   Ry   R<   t   curryR-   RM   R4   t   oxt   oyR7   Rv   t   sizet   myrectsRN   RO   t   vert1t   code1(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyRX   æ   sH    	!
'c         C` s5   |  j  d k r. d d l m } | ƒ  |  _  n  |  j  S(   uO   
        return the :class:`matplotlib.texmanager.TexManager` instance
        i    (   t
   TexManagerN(   R   R   t   matplotlib.texmanagerR†   (   R   R†   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyRB     s    c   '   	   ` sx  ˆ  j  ƒ  } ˆ  j d k r9 t j t j d ƒ ƒ ˆ  _ n  ˆ  j d k rZ ˆ  j ƒ  ˆ  _ n  | j ƒ  } t	 | d ƒ r¢ | j
 | ˆ  j ƒ } t j | ˆ  j ƒ } n* | j | ˆ  j ƒ }	 t j |	 ˆ  j ƒ } |  t t | ƒ ƒ }
 Wd QX| d k rt ƒ  } n  | rt ƒ  } n | } g  g  g  g  f \ } } } } xq|
 j D]f\ } } } } } ˆ  j j | j ƒ } ˆ  j | j } | d k r‘| j d k r·t d | j | j f ƒ ‚ n  t | j ƒ } x` d d g D]8 \ } } y | j | ƒ Wn t t f k
 r	qÓXPqÓWd	 } t j d
 | j ƒ | d k rr| j rrt j  | j ƒ } ‡  f d †  t! | j ƒ Dƒ } n i  } | | f ˆ  j | j <n | \ } } t" } ˆ  j# | | ƒ } | | k rk| j$ ƒ  | j% ˆ  j ˆ  j ƒ | rü| j | d ƒ } n | } | d k	 r&| j& | d | ƒ} n/ t j d | | j f ƒ | j& | d | ƒ} ˆ  j' | ƒ | | <n  | j( | ƒ | j( | ƒ | j( | ƒ | j( | j) ˆ  j ƒ qCWg  }  x  |
 j* D]• \ }! }" }# }$ |! |" f |! |$ |" f |! |$ |" |# f |! |" |# f |! |" f d g }% t+ j, t+ j- t+ j- t+ j- t+ j- t+ j. g }& |  j( |% |& f ƒ q½Wt/ t0 | | | | ƒ ƒ | |  f S(   uf   
        convert the string *s* to vertices and codes using matplotlib's usetex
        mode.
        u
   pdftex.mapu   get_dviNuJ   No usable font file found for %s (%s). The font may lack a Type-1 version.u   ADOBE_CUSTOMiCBDAu   ADOBE_STANDARDiBODAu    u#   No supported encoding in font (%s).c         ` s.   i  |  ]$ \ } } ˆ  j  j | d  ƒ | “ q S(   N(   R   t   getR   (   R   R   R   (   R   (    s2   lib/python2.7/site-packages/matplotlib/textpath.pys
   <dictcomp>k  s   	RA   uU   The glyph (%d) of font (%s) cannot be converted with the encoding. Glyph may be wrongi    (   u   ADOBE_CUSTOMiCBDA(   u   ADOBE_STANDARDiBODA(   i    i    (1   RB   R   R   R   t
   PsfontsMapR   R   R%   RC   t   hasattrt   get_dviR)   t   DviFromFileLikeR*   t   make_dvit   Dvit   nextt   iterR   t   textR   Rˆ   t   texnamet   filenamet
   ValueErrort   psnameR   t   select_charmapt   RuntimeErrort   warningst   warnR"   R    R!   R
   R:   Rz   R(   Rk   R?   Rm   R‚   t   boxesR   R{   R|   R}   Rn   R   ('   R   R+   RJ   R`   Ro   RL   RM   t   dvifileliket   dvit   dvifilet   pageRs   Rr   Rq   Rx   Ry   t   x1t   y1t   dvifontRv   RR   t   font_and_encodingt
   font_bunchR-   t   charmap_namet   charmap_codet   enc0R$   t   ft2font_flagR7   t   charcodet   glyph0Rƒ   R€   R   RO   RN   R„   R…   (    (   R   s2   lib/python2.7/site-packages/matplotlib/textpath.pyRY   $  s˜    	 	
	'N(   t   __name__t
   __module__t   __doc__R)   R*   R   R%   R.   R/   R8   R:   R?   RD   t   FalseRg   R   RW   RX   RB   RY   (    (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyR      s&   			
					-<4		t   TextPathc           B` sz   e  Z d  Z d
 d
 d e d „ Z d „  Z d „  Z d „  Z d „  Z	 e
 e ƒ Z e
 e	 ƒ Z d „  Z d „  Z d	 „  Z RS(   u&   
    Create a path from the text.
    i   c   	      O` s¢   | d k r t ƒ  } n  | d k r3 | j ƒ  } n  | |  _ |  j | ƒ d |  _ |  j | | d | ƒ\ |  _ |  _ t	 |  _
 t d |  _ t	 |  _ | |  _ d S(   uK  
        Create a path from the text. No support for TeX yet. Note that
        it simply is a path, not an artist. You need to use the
        PathPatch (or other artists) to draw this path onto the
        canvas.

        xy : position of the text.
        s : text
        size : font size
        prop : font property
        R^   u   path.simplify_thresholdN(   R   R   RC   t   _xyR(   t   _cached_verticest   text_get_vertices_codest	   _verticest   _codesR­   t   _should_simplifyR   t   _simplify_thresholdt   _has_nonfinitet   _interpolation_steps(	   R   t   xyRJ   R‚   R+   R·   R^   t   klt   kwargs(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyR   ¦  s    					c         C` s   | |  _  t |  _ d S(   u*   
        set the size of the text
        N(   t   _sizet   Truet   _invalid(   R   R‚   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyR(   É  s    	c         C` s   |  j  S(   u*   
        get the size of the text
        (   R»   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   get_sizeÐ  s    c         C` s   |  j  ƒ  |  j S(   uH   
        Return the cached path after updating it if necessary.
        (   t   _revalidate_pathR°   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_verticesÖ  s    
c         C` s   |  j  S(   u"   
        Return the codes
        (   R³   (   R   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt
   _get_codesÝ  s    c         C` sr   |  j  s |  j d k rn t ƒ  j |  j t j |  j t j ƒ j |  j	 Œ  } | j
 |  j ƒ |  _ t |  _  n  d S(   uÍ   
        update the path if necessary.

        The path for the text is initially create with the font size
        of FONT_SCALE, and this path is rescaled to other size when
        necessary.

        N(   R½   R°   R   R   RQ   R»   t   text_to_pathR)   t	   translateR¯   t	   transformR²   R­   (   R   t   tr(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyR¿   æ  s    			c         C` sv   | j  d ƒ | j  d ƒ } | d k o5 | d d k } t d rL | d f S| r\ | t f S| j d d ƒ t f Sd S(   uM   
        Returns True if the given string *s* contains any mathtext.
        u   $u   \$i    i   u   text.usetexu   TeXN(   t   countR   R¼   t   replaceR­   (   R   RJ   t   dollar_countt   even_dollars(    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   is_math_text÷  s    


c         C` sd   | r' t  j | | d t ƒ\ } } n3 |  j | ƒ \ } } t  j | | d | ƒ\ } } | | f S(   uš   
        convert the string *s* to vertices and codes using the
        provided font property *prop*. Mostly copied from
        backend_svg.py.
        R^   RK   (   RÂ   Rg   R¼   RÊ   (   R   R+   RJ   R^   R=   R>   t
   clean_lineRK   (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyR±   
  s    !N(   Rª   R«   R¬   R   R­   R   R(   R¾   RÀ   RÁ   t   propertyt   verticesR>   R¿   RÊ   R±   (    (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyR®   ¡  s   "						(&   t
   __future__R    R   R   R   t   collectionsR   t   sixt	   six.movesR   R˜   t   numpyR[   t   matplotlib.pathR   t
   matplotlibR   t   matplotlib.font_managerR&   t   matplotlib.ft2fontR   R	   R
   t   matplotlib.mathtextR   t   matplotlib.dvireadR   R   R   t   matplotlib.transformsR   t   six.moves.urllib.parseR   R3   t   objectR   RÂ   R®   (    (    (    s2   lib/python2.7/site-packages/matplotlib/textpath.pyt   <module>   s&   "ÿ „	