)Uc@sdZddlZddlZddlZddlZddlZyeWn!ek rmddlm ZnXddl Z ddl m Z ddl m Z ddl m Z mZddlmZddlmZmZyddlZWnek rddlZnXeZe jZi d d 6d d 6d d6dd6dd6dd6dd6dd6d d6de6Zi dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6Zidd+6dd,6dd"6dd-6dd.6d!d6d!d/6d#d06d#d16d#d26d%d36d'd46d'd56d)d66Zed7d8d9d:d;d<d=gZd>Zd?d@gZ dAdBdCdDgZ!dEdFdGgZ"e rej#j$dHZ%e%ek rej&j'e%dIdJZ&e"j(e&ej&j'e%dKZ&e!j(e&nndLZ)dMZ*edNdOZ+dPZ,edNdQZ-dRZ.dNdSZ/edNdTZ0dUZ1dVe2fdWYZ3dXZ4dYZ5dNdZZ6d[e2fd\YZ7d]Z8d^Z9d_Z:d`fdaYZ;iZ<dbZ=ea>ej&j'edcZ?ddZ@eoejAdekr6ddlBZBdfZCeBjDdgZEiZFdNdhZGnpyVe:e?a>eHt>di pdt>jIe;jJkrqe@net>_KejLdje?Wne@nXdkZGdS(ls 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 `_. 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. iN(tSet(tafm(tft2font(trcParamst get_configdir(tis_string_like(tparse_fontconfig_patterntgenerate_fontconfig_patterngI +?sxx-smallgh|?5?sx-smallg-?tsmallg?tmediumg333333?tlargeg ףp= ?sx-largegS?sxx-largetlargertsmalleridsultra-condensedisextra-condensedi,t condensedissemi-condenseditnormaliXs semi-expandeditexpandedi sextra-expandedisultra-expandedt ultralighttlighttregulartbooktromantsemiboldtdemiboldtdemitboldtheavys extra boldtblacktserifs sans-serifs sans seriftcursivetfantasyt monospacetsanss@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folderss2SOFTWARE\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/tHOMEtLibrarytFontss.fontscCsidd6dd6dd6|S(ss Return a list of file extensions extensions that are synonyms for the given file extension *fileext*. tttftotfR(R#R$(R#R$(safm((tfontext((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytget_fontext_synonymss cCsyddl}Wntk r#noXyZ|j|jt}z0y|j|ddSWntk rjnXWd|j|XWntk rnXtj j tj ddS(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. iNR"itWINDIR( t_winregt ImportErrortOpenKeytHKEY_CURRENT_USERt MSFolderst QueryValueExtOSErrortCloseKeytostpathtjointenviron(R(tuser((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytwin32FontDirectorys    R#c Csddl}|dkr$t}nt|}di}}xtD]{}y|j|j|}Wntk ryqDnX|sg}x7|D]/}|jt j t j j |d|qW|Szxt |j|dD]} y|j|| \}} } t j j| s/t j j || } nt j j| j} t j j| dd|krtd||         -     c sygfd}x]tD]U}y/tjj|rPtjj||dnWqtttt fk rpqXqWS(s Return the system font directories for OS X. This is done by starting at the list of hardcoded paths in :attr:`OSXFontDirectories` and returning all nested directories within them. csj|dS(N(tappend(targRERJ(t fontpaths(sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytaddsN( tOSXFontDirectoriesR0R1tisdirtwalkR6tIOErrorR.t TypeErrort ValueError(RSRH((RRsJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytOSXFontDirectorys cCs|dkrt}nt|}g}x|D]}|dkrk|jtjtjj|dq1xf|D]^}|jtjtjj|d||jtjtjj|d|jqrWq1W|S(sJ Get list of font files on OS X - ignores font suffix by default. t*s*.N( R6RZR&R9R:R0R1R2tupper(RER%RJR1RK((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytOSXInstalledFontss     ( )7c sygfd}x]tD]U}y/tjj|rPtjj||dnWqtttt fk rpqXqWS(s Return the system font directories for X11. This is done by starting at the list of hardcoded paths in :attr:`X11FontDirectories` and returning all nested directories within them. csj|dS(N(RP(RQRERJ(RR(sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRSsN( tX11FontDirectoriesR0R1RURVR6RWR.RXRY(RSRH((RRsJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytx11FontDirectory s cCst|}i}y5tjdddgdtj}|jd}Wntk r[|SX|jdkrxl|jdD]X}|jdd}tj j |dd|kr{tj j |r{d||( RR0R1tbasenameRoRRRR(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt__repr__s$(t__name__t __module__t__doc__RR(((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRxs c Csa|j}|j}|jd}|jd}|rH|j}nd}|rc|j}nd}|jddkrd}n[|jddkrd}n=|jddkrd }n|jtj@rd}nd }|jdkrd }nd }d}x3t j D]%}|j|dkr|}PqqW|sg|jtj @r^d }qgd }nt |}|jddks|jddks|jddkrd} nW|jddkrd} n9|jddks|jddkr d} nd } |j r$d} ntt|j} d} t|j||||| | S(s A function for populating the :class:`FontKey` by extracting information from the TrueType font file. *font* is a :class:`FT2Font` instance. iiiiR`tobliquetitalicRRtcapitalss small-capsiitnarrowR tconds demi condssemi-condensedtwideRtscalable(iiii(iiii(Rs small-capsN(t family_nametget_sfnttgetR@tfindt style_flagsRtITALICR6R}RDtBOLDRRRwRt get_fontsizeRRo( tfontRtsfnttsfnt2tsfnt4RRRtwRRt size_adjust((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytttfFontPropertysZ          *  *   c Cs~|j}|jj}|jdksK|jjddkrTd}n*|jjddkrxd}nd}|jdkrd}nd}t|jj}|jddks|jddks|jd dkrd}nW|jd dkrd }n9|jd dksG|jd dkrPd }nd}d}d} t|||||||S(s A function for populating a :class:`FontKey` instance by extracting information from the AFM font file. *font* is a class:`AFM` instance. iRRRRs small-capsRR Rs demi condssemi-condensedRRR(scapitalss small-capsN( tget_familynamet get_fontnameR@t get_angleRRt get_weightR6R( tfontpathRRtfontnameRRRRRR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytafmFontPropertys, -   *  *  c Csg}i}x{|D]s}tjd|dtjj|d}||krUqn d||<|dkryt|d}Wntjd|qnXy%ztj|}Wd|jXWn%t k rtjd|qnXt ||}n~yt j t |}WnEt k r;tjd|qn!tk r[tjd qnXyt|}Wn qnX|j|qW|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. screateFontDict: %stdebugiRtrsCould not open font file %sNsCould not parse font file %ssCannot handle unicode filenames(tverbosetreportR0R1RitopenRtAFMtcloset RuntimeErrorRRtFT2FontRwt UnicodeErrorRRP( RkR%tfontlisttseentfpathRotfhRtprop((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytcreateFontList8sH        tFontPropertiesc BseZdZdddddddddZdZdZdZdZdZ dZ e Z dZ d Z d Zd Zd Zd ZdZdZeZdZeZdZdZdZdZdZdZdZRS(s A class for storing and manipulating font properties. The font properties are those described in the `W3C Cascading Style Sheet, Level 1 `_ 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 `_ pattern, if it is the only argument provided. See the documentation on `fontconfig patterns `_. 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 Cs)d|_d|_d|_d|_d|_d|_d|_|dk rb|jj |jdSt |r|dkr|dkr|dkr|dkr|dkr|dkr|j |dSn|j ||j ||j||j||j||j||j|dS(N(R6t_familyt_slantt_variantt_weightt_stretcht_sizet_filet__dict__tupdateRtset_fontconfig_patternt set_familyt set_stylet set_variantt set_weightt set_stretchtset_filetset_size( RtfamilyRRRRRRot_init((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRs4                      cCs t|S(N(R(Rtpattern((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt_parse_fontconfig_patternscCsHgt|jD]"}|t|d|f^q}tt|S(NR(tsortedRtgetattrthashtrepr(Rtktl((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt__hash__s8cCs |jS(N(tget_fontconfig_pattern(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt__str__scCs7|jdkr0td}t|r,|gS|S|jS(sL Return a list of font names that comprise the font family. s font.familyN(RR6RR(RR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt get_familys   cCstjtt|jS(s\ Return the name of the font that best matches the font properties. (RRRwtfindfontR(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytget_namescCs|jdkrtdS|jS(s^ Return the font style. Values are: 'normal', 'italic' or 'oblique'. s font.styleN(RR6R(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt get_stylescCs|jdkrtdS|jS(sY Return the font variant. Values are: 'normal' or 'small-caps'. s font.variantN(RR6R(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt get_variantscCs|jdkrtdS|jS(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' s font.weightN(RR6R(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRscCs|jdkrtdS|jS(s Return the font stretch or width. Options are: 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'. s font.stretchN(RR6R(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt get_stretchscCs|jdkrtdS|jS(s' Return the font size. s font.sizeN(RR6R(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytget_sizescCsW|jdk r7yt|jSWq7tk r3q7Xntj}|tj|jS(N(RR6RRYt fontManagertget_default_sizet font_scalingsR(Rt default_size((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytget_size_in_pointss  cCs|jS(s= Return the filename of the associated font. (R(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytget_file!scCs 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 `_. 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((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyR's cCs=|dkrd|_n!t|r0|g}n||_dS(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. N(R6RR(RR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyR5s     cCs(|dkrtdn||_dS(s[ Set the font style. Values are: 'normal', 'italic' or 'oblique'. RRRs'style must be normal, italic or obliqueN(snormalsitalicsobliqueN(R6RYR(RR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRCs cCs(|dkrtdn||_dS(sN Set the font variant. Values are: 'normal' or 'small-caps'. Rs small-capss$variant must be normal or small-capsN(snormals small-capsN(R6RYR(RR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRMs cCs|dk rry4t|}|dks3|dkr?tnWqrtk rn|tkrotdqoqrXn||_dS(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' iisweight is invalidN(R6tintRYR}R(RR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRUs    cCs|dk rry4t|}|dks3|dkr?tnWqrtk rn|tkrotdqoqrXn||_dS(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. iisstretch is invalidN(R6RRYt stretch_dictR(RR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRfs    cCsg|dk rZyt|}WqZtk rV|dk rW|tkrWtdqWqZXn||_dS(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. ssize is invalidN(R6RRYRR(RR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRws  cCs ||_dS(sw Set the filename of the fontfile to use. In this case, all other properties will be ignored. N(R(RRa((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRscCsqxj|j|jD]S\}}t|tkrRt|d||dqt|d||qWdS(sg Set the properties by parsing a fontconfig *pattern*. See the documentation on `fontconfig patterns `_. 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. tset_iN(RRGttypetlistR(RRRFtval((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRs "cCs td|S(sReturn a deep copy of selfR(R(R((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytcopysN(RRRR6RRRRRRRt get_slantRRRRRRRRtset_nameRt set_slantRRRRRRR(((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRfsD9 #                cCsg}x|jD]}x}|jD]o}xf|jD]X}xO|jD]A}x8|jD]*}x!|jD]}|j|qrWq_WqLWq9Wq&WqW|S(s< flatten a ttfdict to all the filenames it contains (tvaluesRP(tdtfnamestnamedtstyledtvariantdtweightdtstretchdRo((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pytttfdict_to_fnamess%cCs5t|d}ztj||Wd|jXdS(su Equivalent to pickle.dump(data, open(filename, 'w')) but closes the file to prevent filehandle leakage. RN(RtpickletdumpR(tdatatfilenameR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt pickle_dumpscCs4t|d}ztj|}Wd|jX|S(so Equivalent to pickle.load(open(filename, 'r')) but closes the file to prevent filehandle leakage. RN(RRtloadR(RRR((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyt pickle_loads  t FontManagercBseZdZdZdddZdZdZdZdZ dZ d Z d Z d Z d Zd ZddeedZRS(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. iRcCs2|j|_||_||_tjjtdddtjjtdddtjjtdddg}xddgD]}|tjkr|tj|}|j dd kr|j |j dq |j d d kr|j |j d q |j |q|q|Wt jd t|t|t|_id d6d d6|_i|_xe|jD]F}t jd|d|jj dd kre||jdt"j#d|j|j$|f|j%}|j&|j$||j'|||t(St"j#d||j)|ft*|j)|}n,tjd || j| j| f| j}t j j+|s|rtjd t,t-j'|||t.t(St/d n|d kr||t |`_ documentation for a description of the font finding algorithm. sfindfont returning %sRRg?O8Mg$@is6findfont: Font family %s not found. Falling back to %ss*findfont: Could not match %s. Returning %ss1findfont: Matching %s to %s (%s) with score of %fs7findfont: Found a missing font file. Rebuilding cache.sNo valid font could be foundN(0RvRRR6RRRRRRRRR0R1t commonprefixRoR'RRR*RRR-RRR8RRR3RRR=RRtwarningstwarnRRRRtFalseRt UserWarningtisfilet_rebuildRtTrueRY(RRR%REtfallback_to_defaulttrebuild_if_missingRot font_cacheRtcachedt best_scoret best_fontRtscoret default_proptresult((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRsp          !      N(RRRR R6RRRRRR'R*R-R3R8R=RER(((sJ/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/font_manager.pyRs1        cCstjj|djdkrtj|}|dkr~t|d}|jd}|j |dk}|t|s<              -   ,  ^ C .<  6