� �)�Uc@s�ddlZddlmZddljZddlmZmZmZm Z ddl m Z ddl j Z ddlZdefd��YZddlmZddlmZdd lmZe�Zd efd ��YZdS( i����N(tPath(tFT2FonttKERNING_DEFAULTtLOAD_NO_HINTINGtLOAD_TARGET_LIGHT(tMathTextParsert TextToPathcBs�eZdZdZdZd�Zd�Zd�Zd�Zd�Z dd �Z e e d �Z de d �Zde d �Zd �Zde d�ZRS(sF A class that convert a given text to a path using ttf fonts. gI@iHcCsDtd�|_d|_ddlm}|d�|_d|_dS(s Initialization tpathi����(tmaxdicti2N(Rtmathtext_parsertNonet tex_font_maptmatplotlib.cbookRt _ps_fontdt _texmanager(tselfR((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt__init__s  cCs;tj|�}tt|��}|j|j|j�|S(s" find a ttf font. (t font_managertfindfontRtstrtset_sizet FONT_SCALEtDPI(Rtproptfnametfont((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt _get_font#scCstS(N(R(R((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt_get_hinting_flag-scCs-|j�d}tjd||f�}|S(sO Return a unique id for the given font and character-code set. iiis%s-%d(iiii(tget_sfntturllibtquote(RRtccodetps_nametchar_id((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt _get_char_id0scCs-|j�d}tjd||f�}|S(sY Return a unique id for the given font and character-code set (for tex). is%s-%d(tget_ps_font_infoRR(RRRR R!((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt_get_char_id_ps8sgcCs�gg}}x�|jD]}|ddkr[|j|d|df�|jtj�q|ddkr�|j|d|df�|jtj�q|ddkr�|j|d|df|d|dfg�|jtjtjg�q|ddkrf|j|d|df|d|df|d|dfg�|jtjtjtjg�q|ddkr|jd�|jtj�qqWg|D]\}}|||f^q�}||fS( sB convert the ft2font glyph to vertices and codes. iiiiiii(ii( RtappendRtMOVETOtLINETOtextendtCURVE3tCURVE4t CLOSEPOLY(Rtglyphtcurrxtvertstcodeststeptxty((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt glyph_to_pathAs, " )cCs3|tkrc|tkrE|j|�}|j||�\}}}q~|j||�\}}}n|j||�\}}}gg} } xj|D]b\} } } }|| \}}|r�tj|�|| | g}n| j|�| j|�q�Wx.|D]&\}}| j|�| j|�q�W| | fS(sX convert text *s* to path (a tuple of vertices and codes for matplotlib.math.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. (tFalseRtget_glyphs_with_fonttget_glyphs_mathtexttget_glyphs_textnptarrayR((RRtstismathtusetexRt glyph_infot glyph_maptrectsR.R/tglyph_idt xpositiont ypositiontscaletverts1tcodes1((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt get_text_path`s"      cCs�|j�}d}d}g}g} |dkr<t�}n|rNt�} n|} x|D]�} t| �} |j| �} | dkr�td�} d} n|dk r�|j|| t�}nd}|j| dt�}|j d}|j || �}||kr|j |�| |<n||d7}|j |�| j |�||7}| }q[Wdgt |�}dgt |�}g}t| |||�| |fS(sc convert the string *s* to vertices and codes using the provided ttf font. it?tflagsg�@gP@g�?N(t get_charmapR tdicttordtgett get_kerningRt load_charRtlinearHoriAdvanceR"R3R%tlentzip(RRR:R>treturn_new_glyphs_onlytcmaptlastgindR-t xpositionst glyph_idst glyph_map_newtcRtgindtkernR,t horiz_advanceR!t ypositionstsizesR?((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyR5�sB                cCs2|j�}|j|j�|jj||j|�\}}}}} |dkr^t�}n|rpt�} n|} g} g} g} g}d\}}x�|D]�\}}}}}t|�}|j ||�}||kr+|j �|j|j|j�|j |dt �}|j |�| |<n| j|�| j|�| j|�||j}|j|�q�Wg}x�| D]�\}}}}||f|||f||||f|||f||fdg}tjtjtjtjtjtjg}|j||f�q}Wt| | | |�||fS(s[ convert the string *s* to vertices and codes by parsing it with mathtext. iRHN(ii(ii(tcopyRRR tparseRR RJRKR"tclearRNRR3R%RR&R'R+RQ(RRR:R>RRtwidththeighttdescenttglyphsR?RWRUR\RVR]R-tcurryRtfontsizetoxtoyRR!R,tsizetmyrectstwthtvert1tcode1((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyR6�sF  !           F cCs5|jdkr.ddlm}|�|_n|jS(sO return the :class:`matplotlib.texmanager.TexManager` instance i����(t TexManagerN(RR tmatplotlib.texmanagerRo(RRo((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pytget_texmanagersc#Csk|j�}|jdkr9tjtjd��|_n|j�}t|d�r�|j||j �}tj ||j �}n*|j ||j �} tj | |j �}t|�j�} |j�|dkr�t�}n|r�t�} n|} ggggf\} } }}x�| jD]�\}}}}}|jj|j�}|dkr�|j|j}tt|j��}y|jd�Wntk r�|jd�nX|jr�tj|j�}nd}||f|j|j<n |\}}t}|j||�}||krd|j �|j!|j |j �|j"|d|�}|j#|�| |<n| j$|�| j$|�|j$|�|j$|j%|j �qWg}x�| j&D]�\}}}} ||f|| |f|| ||f|||f||fdg}!t'j(t'j)t'j)t'j)t'j)t'j*g}"|j$|!|"f�q�Wt+| | ||�| |fS(s^ convert the string *s* to vertices and codes using matplotlib's usetex mode. s pdftex.maptget_dviiCBDAiRHN(ii(,RqR R tdvireadt PsfontsMapt find_tex_filetget_size_in_pointsthasattrRrRtDviFromFileLikeRtmake_dvitDvititertnexttcloseRJttextR RLttexnameRRtfilenametselect_charmapt ValueErrort set_charmaptencodingtEncodingRR$R`RRNR3R%RitboxesRR&R'R+RQ(#RRR:R>RRt texmanagerRft dvifileliketdvitdvifiletpageRWRVRUR\R]tx1ty1tdvifontR,Ratfont_and_encodingt font_bunchRtenct ft2font_flagR!tglyph0RjRgRhRlRkRmRn((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyR7sf               F N(t__name__t __module__t__doc__RRRRRR"R$R3R4RFR R5R6RqR7(((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyRs"   + B 6 (tFontProperties(trcParams(tAffine2DtTextPathcBszeZdZd d ded�Zd�Zd�Zd�Zd�Z e e�Z e e �Z d�Z d�Zd �ZRS( s& Create a path from the text. ic Os�|dkrt�}n|dkr3|j�}n||_|j|�d|_|j||d|�\|_|_t |_ t d|_ t |_ ||_dS(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<spath.simplify_thresholdN(R R�Rvt_xyRt_cached_verticesttext_get_vertices_codest _verticest_codesR4tshould_simplifyR�tsimplify_thresholdt has_nonfinitet_interpolation_steps( RtxyR:RiRR�R<tkltkwargs((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyRvs      $   cCs||_t|_dS(s* set the size of the text N(t_sizetTruet_invalid(RRi((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyR�s cCs|jS(s* get the size of the text (R�(R((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pytget_size�scCs|j�|jS(sH Return the cached path after updating it if necessary. (t_revalidate_pathR�(R((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt _get_vertices�s cCs|jS(s" Return the codes (R�(R((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt _get_codes�scCsr|js|jdkrnt�j|jtj|jtj�j|j �}|j |j �|_t |_ndS(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�RCR�t text_to_pathRt translateR�t transformR�R4(Rttr((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyR��s cCsv|jd�|jd�}|dko5|ddk}tdrL|dfS|r\|tfS|jdd�tfSdS(sM Returns True if the given string *s* contains any mathtext. t$s\$iis text.usetextTeXN(tcountR�R�treplaceR4(RR:t dollar_countt even_dollars((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt is_math_text�s   cCsd|r'tj||dt�\}}n3|j|�\}}tj||d|�\}}||fS(s� convert the string *s* to vertices and codes using the provided font property *prop*. Mostly copied from backend_svg.py. R<R;(R�RFR�R�(RRR:R<R.R/t clean_lineR;((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyR��s !N(R�R�R�R R4RRR�R�R�tpropertytverticesR/R�R�R�(((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyR�qs#        (Rtmatplotlib.pathRtmatplotlib.font_managerRtmatplotlib.ft2fontRRRRtmatplotlib.mathtextRtmatplotlib.dvireadRstnumpyR8tobjectRR�t matplotlibR�tmatplotlib.transformsR�R�R�(((sF/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/textpath.pyt<module>s " �]