ó
±éRc           @  s  d  d l  m Z d  d l 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 m Z d  d l m Z d  d l m Z d  d l j 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   print_functionN(   t   Path(   t   rcParams(   t   FT2Fontt   KERNING_DEFAULTt   LOAD_NO_HINTING(   t   LOAD_TARGET_LIGHT(   t   MathTextParser(   t   FontProperties(   t   Affine2Dt
   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(   sF   
    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(   s    
        Initialization
        t   pathiÿÿÿÿ(   t   maxdicti2   N(	   R   t   mathtext_parsert   Nonet   tex_font_mapt   matplotlib.cbookR   t	   _ps_fontdt   _texmanagert   _adobe_standard_encoding(   t   selfR   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   __init__   s    		c         C  sP   t  j d ƒ } t  j | ƒ } t g  t | j ƒ D] \ } } | | f ^ q1 ƒ S(   Ns   8a.enc(   t   dvireadt   find_tex_filet   Encodingt   dictt	   enumeratet   encoding(   R   t   enc_namet   enct   it   c(    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_adobe_standard_encoding*   s    c         C  s;   t  j | ƒ } t t | ƒ ƒ } | j |  j |  j ƒ | S(   s"   
        find a ttf font.
        (   t   font_managert   findfontR   t   strt   set_sizet
   FONT_SCALEt   DPI(   R   t   propt   fnamet   font(    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt	   _get_font/   s    c         C  s   t  S(   N(   R   (   R   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_hinting_flag9   s    c         C  sg   | j  ƒ  } y | d	 j d ƒ } Wn$ t k
 rI | d
 j d ƒ } n Xt j d | | f ƒ } | S(   sO   
        Return a unique id for the given font and character-code set.
        i   i    i   t   macromani   i	  s   utf-16bes   %s-%x(   i   i    i    i   (   i   i   i	  i   (   t   get_sfntt   decodet   KeyErrort   urllibt   quote(   R   R)   t   ccodet   sfntt   ps_namet   char_id(    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_char_id<   s    c         C  s-   | j  ƒ  d } t j d | | f ƒ } | S(   sY   
        Return a unique id for the given font and character-code set (for tex).
        i   s   %s-%d(   t   get_ps_font_infoR0   R1   (   R   R)   R2   R4   R5   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_char_id_psH   s    g        c         C  sG   | j  ƒ  \ } } | d k r= | d d … d f c | 7<n  | | f S(   sB   
        convert the ft2font glyph to vertices and codes.
        g        Ni    (   t   get_path(   R   R)   t   currxt   vertst   codes(    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   glyph_to_pathP   s    c         C  sK  t  d rP |  j ƒ  } | j ƒ  } | j | | d d  ƒ\ } } } | | | f S| j ƒ  } t | ƒ |  j }	 | rÑ | j ƒ  } | j |  j ƒ |  j	 j
 | d | ƒ \ }
 } } } } |
 |	 | |	 | |	 f S|  j | ƒ } | j | d d t ƒ| j ƒ  \ } } | d :} | d :} | j ƒ  } | d :} | |	 | |	 | |	 f S(   Ns   text.usetext   rendereriH   g        t   flagsg      P@(   R   t   get_texmanagert   get_size_in_pointst   get_text_width_height_descentR   t   floatR%   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)   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyRB   Y   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(   s`  
        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'   RI   RJ   t   usetexR)   t
   glyph_infot	   glyph_mapt   rectsR;   R<   t   glyph_idt	   xpositiont	   ypositionRP   t   verts1t   codes1(    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   get_text_pathu   s&    c         C  s¡  | j  ƒ  } d } d } g  } g  }	 | d k r< t ƒ  } n  | rN 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} | } q[ Wd g t | ƒ } d g t | ƒ } g  } t |	 | | | ƒ |
 | f S(   sc   
        convert the string *s* to vertices and codes using the
        provided ttf font.
        i    t   ?R?   g      ð@g      P@g      ð?N(   t   get_charmapR   R   t   ordt   gett   get_kerningR   t	   load_charR   t   linearHoriAdvanceR6   R=   t   appendRY   t   zip(   R   R)   RI   R_   t   return_new_glyphs_onlyt   cmapt   lastgindR:   t
   xpositionst	   glyph_idst   glyph_map_newR   R2   t   gindt   kernt   glypht   horiz_advanceR5   t
   ypositionst   sizesR`   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyRV   ¢   sD    		

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 | | | | ƒ |
 | f S(   sc   
        convert the string *s* to vertices and codes by parsing it with
        mathtext.
        i    R?   (   i    i    (   i    i    (   RD   R$   R%   R   RE   R&   R   R6   t   clearRl   R   R=   Rn   R   t   MOVETOt   LINETOt	   CLOSEPOLYRo   (   R   R'   RI   R_   Rp   RQ   RR   RS   t   glyphsR`   Ru   Rs   Rz   Rt   R{   R:   t   curryR)   RL   R2   t   oxt   oyR5   Rx   t   sizet   myrectsRM   RN   t   vert1t   code1(    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyRW   à   sH    	!
'c         C  s5   |  j  d k r. d d l m } | ƒ  |  _  n  |  j  S(   sO   
        return the :class:`matplotlib.texmanager.TexManager` instance
        iÿÿÿÿ(   t
   TexManagerN(   R   R   t   matplotlib.texmanagerRˆ   (   R   Rˆ   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyR@     s    c   )      C  sp  |  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 ƒ } z t t | ƒ ƒ }
 Wd | j ƒ  X| d k rt ƒ  } n  | rt ƒ  } n | } g  g  g  g  f \ } } } } xj|
 j D]_\ } } } } } |  j j | j ƒ } |  j | j } | d k r�t t | j ƒ ƒ } xZ d d g D]2 \ } } y | j | ƒ Wn t k
 ràq°XPq°Wd } t j d	 | j ƒ | d k rm| j rmt j  | j ƒ } t g  t! | j ƒ D]' \ } } | |  j j | d ƒ f ^ q:ƒ } n	 t ƒ  } | | f |  j | j <n | \ } } t" } |  j# | | ƒ } | | k ri| 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 ƒ qH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/ | | | | ƒ | |" f S(   sf   
        convert the string *s* to vertices and codes using matplotlib's usetex
        mode.
        s
   pdftex.mapt   get_dviNt   ADOBE_CUSTOMiCBDAt   ADOBE_STANDARDiBODAt    s#   No supported encoding in font (%s).R?   sU   The glyph (%d) of font (%s) cannot be converted with the encoding. Glyph may be wrongi    (   R‹   iCBDA(   RŒ   iBODA(   i    i    (0   R@   R   R   R   t
   PsfontsMapR   R   R    RA   t   hasattrRŠ   R%   t   DviFromFileLikeR&   t   make_dvit   Dvit   nextt   itert   closeR   t   textR   Rj   t   texnameR   R#   t   filenamet   select_charmapt
   ValueErrort   warningst   warnR   R   R   R   R8   R|   R$   Rl   R=   Rn   R„   t   boxesR   R}   R~   R   Ro   ()   R   R'   RI   R_   Rp   RK   RL   t   dvifileliket   dvit   dvifilet   pageRu   Rt   Rs   Rz   R{   t   x1t   y1t   dvifontRx   RQ   t   font_and_encodingt
   font_bunchR)   t   charmap_namet   charmap_codet   enc0R   R   R   t   ft2font_flagR5   t   charcodet   glyph0R…   R‚   Rƒ   RN   RM   R†   R‡   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyRX     s’    	 	@	
	'N(   t   __name__t
   __module__t   __doc__R%   R&   R   R    R*   R+   R6   R8   R=   RB   t   FalseRf   R   RV   RW   R@   RX   (    (    (    sM   /opt/xtal/ccp4-6.5-linux32/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(   s&   
    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(   sK  
        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]   s   path.simplify_thresholdN(   R   R   RA   t   _xyR$   t   _cached_verticest   text_get_vertices_codest	   _verticest   _codesR°   t   _should_simplifyR   t   _simplify_thresholdt   _has_nonfinitet   _interpolation_steps(	   R   t   xyRI   R„   R'   Rº   R]   t   klt   kwargs(    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyR   œ  s    					c         C  s   | |  _  t |  _ d S(   s*   
        set the size of the text
        N(   t   _sizet   Truet   _invalid(   R   R„   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyR$   ¿  s    	c         C  s   |  j  S(   s*   
        get the size of the text
        (   R¾   (   R   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   get_sizeÆ  s    c         C  s   |  j  ƒ  |  j S(   sH   
        Return the cached path after updating it if necessary.
        (   t   _revalidate_pathR³   (   R   (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   _get_verticesÌ  s    
c         C  s   |  j  S(   s"   
        Return the codes
        (   R¶   (   R   (    (    sM   /opt/xtal/ccp4-6.5-linux32/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(   sÍ   
        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	   RP   R¾   t   text_to_pathR%   t	   translateR²   t	   transformRµ   R°   (   R   t   tr(    (    sM   /opt/xtal/ccp4-6.5-linux32/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(   sM   
        Returns True if the given string *s* contains any mathtext.
        t   $s   \$i    i   s   text.usetext   TeXN(   t   countR   R¿   t   replaceR°   (   R   RI   t   dollar_countt   even_dollars(    (    sM   /opt/xtal/ccp4-6.5-linux32/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(   sš   
        convert the string *s* to vertices and codes using the
        provided font property *prop*. Mostly copied from
        backend_svg.py.
        R]   RJ   (   RÅ   Rf   R¿   RÏ   (   R   R'   RI   R]   R;   R<   t
   clean_lineRJ   (    (    sM   /opt/xtal/ccp4-6.5-linux32/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´   (    (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyR±   —  s   "						(   t
   __future__R    R›   R0   t   numpyRZ   t   matplotlib.pathR   t
   matplotlibR   t   matplotlib.font_managerR!   t   matplotlib.ft2fontR   R   R   R   t   matplotlib.mathtextR   t   matplotlib.dvireadR   R   t   matplotlib.transformsR	   t   objectR
   RÅ   R±   (    (    (    sM   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/textpath.pyt   <module>   s    ÿ �	