rL i3dZddlmZddlmZddlZddlZddlmZddlZddl m Z ddl Z ddl Z ddl mZddlZddlmZddlZddlZddlZddlZddlZddlZdd lmZmZmZmZdd lmZmZdd l m!Z!e jDe#Z$d d ddddddddd Z%dddddddddddddd Z&dddddddddddddddZ'gdZ(hd Z) ejTZ+d!Z.d"d#gZ/e0e+d$z e0e+d%z gZ1d&d'd(d)d*e0eejdjgd+xse+d,z d-z e0e+d.z gZ4d/d0d1d2e0e+d3z gZ5d4Z6d5Z7d6Z8d7Z9ed8Z:ed9Z;dTd:Z<ejzd;<Gd=d>Z>d?Z?d@Z@dAZAGdBdCZBGdDdEe jZDdFZEdGZFdHZGGdIdJZHedKZIedLdMZJeKedNrejeJjOedLdPZNdUdQZOd;dRdSZPePZQeQjZReQjZSy#e,$reejZZ+YvwxYw)Va A module for finding, managing, and using fonts across platforms. This module provides a single `FontManager` instance, ``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` instance. The `FontManager` also handles Adobe Font Metrics (AFM) font files for use by the PostScript backend. The `FontManager.addfont` function adds a custom font from a file without installing it into your operating system. 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. ) annotations) b64encodeN) lru_cache)BytesIO)Number)Path)_api_afmcbookft2font)parse_fontconfig_patterngenerate_fontconfig_pattern) _validatorsgI +?gh|?5?g-??g333333?g ףp= ?gS?) zxx-smallzx-smallsmallmediumlargezx-largezxx-largelargersmallerNd,X ) zultra-condensedzextra-condensed condensedsemi-condensednormalz semi-expandedz semi-extendedexpandedextendedzextra-expandedzextra-extendedzultra-expandedzultra-extended) ultralightlightr!regularbookrromansemibolddemibolddemiboldheavyz extra boldblack))thinr) extralightr)r$r) demilight^) semilightr2)r%r)r'i|)r&r)r!r)rr)r*r)r+r)r)r) extraboldr) superboldr) ultraboldr)r,r) ultrablack) superblackr8) extrablackr8)z\bultrar8)r.r)r-r>sansserifcursivefantasy monospace sans serif sans-serifz@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Foldersz2SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fontsz/SOFTWARE\Microsoft\Windows\CurrentVersion\Fontsz%AppData/Local/Microsoft/Windows/Fontsz'AppData/Roaming/Microsoft/Windows/Fontsz/usr/X11R6/lib/X11/fonts/TTF/z/usr/X11/lib/X11/fontsz/usr/share/fonts/z/usr/local/share/fonts/z)/usr/lib/openoffice/share/fonts/truetype/ XDG_DATA_HOMEz .local/sharefontsz.fontsz/Library/Fonts/z/Network/Library/Fonts/z/System/Library/Fonts/z/opt/local/share/fontsz Library/Fontsc$dggdgdgdd|S)zh Return a list of file extensions that are synonyms for the given file extension *fileext*. afm)otfttcttf)rErFrGrHfontexts ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/font_manager.pyget_fontext_synonymsrMs& w$$$     c .|Dcgc]}d|z }}tj|Dcgc]R\}}}|D]G}t|jj |vr tj j ||ITc}}}}Scc}wcc}}}}w)zo Return a list of all fonts matching any of the extensions, found recursively under the directory. .)oswalkrsuffixlowerpathjoin) directory extensionsextdirpath_ filenamesfilenames rL list_fontsr^s (22#)2J2*,); < <%I% <H~$$**, : GGLL( + < + <<3 ?  % %'< = " H- 9,U!&v':':5'A!'D!E ,A.4-=-=eQ-GNC#-eS#9 ()(,He'<'D'D'F"IIdO ,,   0 L $0) (),, -sO DAC5 (C& C5 D& C2 /C5 1C2 2C5 5C> :DD D cT dtjddgvrtjdgStjddg}|j dDcgc] }ttj|"c}S#ttj f$rgcYSwxYwcc}w)z3Cache and list the font paths known to ``fc-list``.s--formatzfc-listz--helpz7Matplotlib needs fontconfig>=2.7 to query system fonts.z--format=%{file}\n ) subprocess check_output_logwarningrgCalledProcessErrorsplitrrQfsdecode)outfnames rL_get_fontconfig_fontsrs j55y(6KL L LLI KI%%y2G&HI36))E2B CDU# $ CC Z22 3  Cs/BB%B%B"!B"c tjtjgd\}|dDcgc]}t|dc}S#ttj tj f$rgcYSwxYwcc}w)zKCache and list the font paths known to ``system_profiler SPFontsDataType``.)system_profilerz-xmlSPFontsDataType_itemsrU)plistlibloadsrrrgrInvalidFileExceptionr)dentrys rL_get_macos_fontsrsr ^^  # #$R SU./x[ 9EDv  99 Z22H4Q4Q R  9s,A A= *A:9A:c >t}t||ztjdk(r t }g}n?t }tjdk(r|t z }gtt}nt}|jfd|Dnt|tr|g}|D]?}|jttjjt!|A|Dcgc]$}tjj#|s#|&c}Scc}w)a4 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. win32darwinc3rK|].}|jjddvr t|0yw)rlN)rSrTru).0rUfontextss rL z"findSystemFonts..)s:At KK--/3x?TAs47)rmrMsysplatformrrrX11FontDirectoriesOSXFontDirectoriesupdatertrumaprQrUabspathr^exists) fontpathsrK fontfilesinstalled_fontsrUrrs @rLfindSystemFontsrsI#G,H <<7 "8:OI35O||x'#3#55F0F3EF . AA A Is #K KRWW__jx.HIJK ) BeBGGNN5,AE BB Bs .$DDT)frozenceZdZUdZdZded<dZded<dZded<dZded<dZ d ed <dZ ded <d Z ded <ddZ ddZ y) FontEntryzj A class for storing Font properties. It is used when populating the font lookup dictionary. rurnamer!stylevariantz str | intweightstretchrsizec`|j}t|j}d|dS)Nz!) _repr_png_rdecode)self png_streampng_b64s rL _repr_html_zFontEntry._repr_html_Es0__& J'..03G9EBBrNc.ddlm}|}|jdk7rt|jnd}|j dd|j |t 5}|j|dd|jcdddS#1swYyxYw)Nr)Figurer)fonttightT) bbox_inches transparent) matplotlib.figurerrrtextrrsavefiggetvalue)rrfig font_pathbufs rLrzFontEntry._repr_png_Jsv,h(, b(8D$d  Atyyy1 Y "# KKdK C<<> " " "s $B  BN)returnru)rbytes)__name__ __module__ __qualname____doc__r__annotations__rrrrrrrrrIrNrLrr5sX E3OD#NE3GS FI GSD#C "rNrc j}j}d}d}|jg|ddjdj xs4|jg|ddjdj }|jg|ddjdj xs4|jg|ddjdj j dd k\rd}nYj d d k\rd }nB|j d d k\rd }n+t jjjvrd }nd }|j d vrd}nd }d}d} d} |jg||djd|jg|| djd|jg|| djd|jg||djd|jg|| djd|jg|| djdggtdxs jgfd} t| } tfddDrd} n dvrd} ntfddDrd} nd } js tdd}t!j"|||| | |S)a Extract information from a TrueType font file. Parameters ---------- font : `.FT2Font` The TrueType font file from which information will be extracted. Returns ------- `FontEntry` The extracted font properties. )rlrr)rli rNzlatin-1 utf_16_beobliqueritalicr&r!capitals small-capsrz utf-16-beNcjd}|r |ddk7r|dS jdjddxsd}tD].\}}t j ||tj s,|cS D]M}|jdd}tD]0\}}t j||tj s,|ccSOtjjjvryy #t$rYwxYw) NzOS/2versioni usWeightClassr rrr) get_sfnt_tableget_ps_font_inforeplace_weight_regexesre fullmatchI ValueErrorsearchr StyleFlagsBOLD style_flags)os2ps_font_info_weightregexrrrstyless rL get_weightz#ttfFontProperty..get_weights !!&) 3y>V+' ' "%%'199#rBHb "1 " v<<':BDDA!M " "EMM#r*E!0 " v99UE2440!M " "    " "d&6&6 6   s'C<< DDc3&K|]}|v ywNrIrwordsfnt4s rLrz"ttfFontProperty..s ET45= E)narrowrcondr demi condr c3&K|]}|v ywrrIrs rLrz"ttfFontProperty..s HtTU] Hrwider"r#r"z$Non-scalable fonts are not supportedscalable) family_nameget_sfntgetrrTfindr rITALICrfilter style_nameintanyrNotImplementedErrorrr)rrsfntmac_keyms_keysfnt2rr wws_subfamilytypographic_subfamilyfont_subfamilyrrrrrrs` @@rLttfFontPropertyrTs   D ==?DGFXXmmmS ) 0 0 ; A A CE XXlllC ( / / < B B D XXmmmS ) 0 0 ; A A CE XXlllC ( / / < B B D  zz)! H  " I ! #    " "d&6&6 6  zz|11MN *7*M*C077 B 27212C8?? J +7+N+S188C )6)=)3/66{C 1610137>>{K *6*>*C077 D F%vdF# $ 9(9F2 F E%D EE  " H'G H H ==!"HII D TZZugvw MMrNc |j}|jj|jdk7sd|jvrd}nd|jvrd}nd}|jdvrd}nd}|j j}|t vrd}dvrd}n0t fd d Drd }nt fd d Drd}nd}d}t|||||||S)a7 Extract information from an AFM font file. Parameters ---------- fontpath : str The filename corresponding to *font*. font : AFM The AFM font file from which information will be extracted. Returns ------- `FontEntry` The extracted font properties. rrrr!rrrr c3&K|]}|v ywrrIrrfontnames rLrz"afmFontProperty..s =$TX  =r)rrrc3&K|]}|v ywrrIrs rLrz"afmFontProperty..s K$TX  Krrr"r)get_familyname get_fontnamerT get_angler weight_dictr r) fontpathrrrrrrrrs @rLafmFontPropertyrs"    D  "((*H ~~1DJJL 8 djjl "  zz|11 __  $ $ &F [ h" =*< = = K*J K K D XtUGVWd KKrNcBtjfd}|S)a< A decorator to limit the call signature to single a positional argument or alternatively only keyword arguments. We still accept but deprecate all other call signatures. When the deprecation expires we can switch the signature to:: __init__(self, pattern=None, /, *, family=None, style=None, ...) plus a runtime check that pattern is not used alongside with the keyword arguments. This results eventually in the two possible call signatures:: FontProperties(pattern) FontProperties(family=..., size=..., ...) ct|dkDst|dk(r|rtjddt|dk(r1|s/tj|dstjdd|g|i|S)Nrlz3.10zPassing individual properties to FontProperties() positionally was deprecated in Matplotlib %(since)s and will be removed in %(removal)s. Please pass all properties via keyword arguments.)messagerzPassing family as positional argument to FontProperties() was deprecated in Matplotlib %(since)s and will be removed in %(removal)s. Please pass family names as keywordargument.)lenr warn_deprecatedr is_scalar_or_string)rargskwargs init_methods rLwrapperz-_cleanup_fontproperties_init..wrapper,s t9q=CINv  1  t9>&1J1J4PQ71S  $ 41$1&11rN) functoolswraps)r&r's` rL_cleanup_fontproperties_initr*s'&__[!2"28 NrNceZdZdZe ddZedZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZeZe Z eZ!eZ"y)FontPropertiesa A class for storing and manipulating font properties. The font properties are the six properties described in the `W3C Cascading Style Sheet, Level 1 `_ font specification and *math_fontfamily* for math fonts: - family: A list of font names in decreasing order of priority. The items may include a generic font family name, either 'sans-serif', 'serif', 'cursive', 'fantasy', or 'monospace'. In that case, the actual font to be used will be looked up from the associated rcParam during the search process in `.findfont`. Default: :rc:`font.family` - style: Either 'normal', 'italic' or 'oblique'. Default: :rc:`font.style` - variant: Either 'normal' or 'small-caps'. Default: :rc:`font.variant` - 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'. Default: :rc:`font.stretch` - 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'. Default: :rc:`font.weight` - size: Either a relative value of 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large' or an absolute font size, e.g., 10. Default: :rc:`font.size` - math_fontfamily: The family of fonts used to render math text. Supported values are: 'dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans' and 'custom'. Default: :rc:`mathtext.fontset` Alternatively, a font may be specified using the absolute path to a font file, by using the *fname* kwarg. However, in this case, it is typically simpler to just pass the path (as a `pathlib.Path`, not a `str`) to the *font* kwarg of the `.Text` object. 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 accepts a single positional string as fontconfig_ pattern_, or alternatively individual properties as keyword arguments:: FontProperties(pattern) FontProperties(*, family=None, style=None, variant=None, ...) This support does not depend on fontconfig; we are merely borrowing its pattern syntax for use here. .. _fontconfig: https://www.freedesktop.org/wiki/Software/fontconfig/ .. _pattern: https://www.freedesktop.org/software/fontconfig/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. Nc ||j||j||j||j||j ||j ||j ||j|t|tr$|!||||||j|yyyyyyyyr) set_family set_style set_variant set_weight set_stretchset_fileset_sizeset_math_fontfamilyrtruset_fontconfig_pattern) rfamilyrrrrrrmath_fontfamilys rL__init__zFontProperties.__init__s  u !  ! e d   1 vs #Mgo&.O   ' ' /:G O;IoM $rNc||St||r|St|tjr ||St|tr||S|di|S)a Generic constructor which can build a `.FontProperties` from any of the following: - a `.FontProperties`: it is passed through as is; - `None`: a `.FontProperties` using rc values is used; - an `os.PathLike`: it is used as path to the font file; - a `str`: it is parsed as a fontconfig pattern; - a `dict`: it is passed as ``**kwargs`` to `.FontProperties`. )rrI)rtrQPathLikeru)clsargs rL _from_anyzFontProperties._from_anysV ;5L S !J R[[ )S> ! S !s8O:: rNc t|j|j|j|j |j |j |j|jf}t|Sr) tuple get_family get_slant get_variantr get_stretchget_sizeget_fileget_math_fontfamilyhash)rls rL__hash__zFontProperties.__hash__sm 4??$ % ^^      __      ]]_ ]]_  % % ' )AwrNc0t|t|k(Sr)rH)rothers rL__eq__zFontProperties.__eq__sDzT%[((rNc"|jSr)get_fontconfig_patternrs rL__str__zFontProperties.__str__s**,,rNc|jS)a Return a list of individual font family names or generic family names. The font families or generic font families (which will be resolved from their respective rcParams when searching for a matching font) in the order of preference. )_familyrPs rLrAzFontProperties.get_familys||rNc>tt|jS)zT Return the name of the font that best matches the font properties. )get_fontfindfontrrPs rLget_namezFontProperties.get_names'333rNc|jS)zV Return the font style. Values are: 'normal', 'italic' or 'oblique'. )_slantrPs rL get_stylezFontProperties.get_styles{{rNc|jS)zQ Return the font variant. Values are: 'normal' or 'small-caps'. )_variantrPs rLrCzFontProperties.get_variants}}rNc|jS)z 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' )_weightrPs rLrzFontProperties.get_weights||rNc|jS)z Return the font stretch or width. Options are: 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'. )_stretchrPs rLrDzFontProperties.get_stretchs }}rNc|jS)z' Return the font size. )_sizerPs rLrEzFontProperties.get_sizezzrNc|jS)z= Return the filename of the associated font. )_filerPs rLrFzFontProperties.get_filercrNct|S)a Get a fontconfig_ pattern_ suitable for looking up the font as specified with fontconfig's ``fc-match`` utility. This support does not depend on fontconfig; we are merely borrowing its pattern syntax for use here. )rrPs rLrOz%FontProperties.get_fontconfig_patterns+400rNcb|tjd}t|tr|g}||_y)aV Change the font family. Can be either an alias (generic name is CSS parlance), such as: 'serif', 'sans-serif', 'cursive', 'fantasy', or 'monospace', a real font name or a list of real font names. Real font names are not supported when :rc:`text.usetex` is `True`. Default: :rc:`font.family` Nz font.family)mplrcParamsrtrurS)rr7s rLr.zFontProperties.set_familys/ >\\-0F fc "XF rNcn|tjd}tjgd|||_y)z Set the font style. Parameters ---------- style : {'normal', 'italic', 'oblique'}, default: :rc:`font.style` Nz font.style)r!rr)r)rhrir check_in_listrY)rrs rLr/zFontProperties.set_styles/ =LL.E :%H rNcn|tjd}tjddg|||_y)z Set the font variant. Parameters ---------- variant : {'normal', 'small-caps'}, default: :rc:`font.variant` Nz font.variantr!r)r)rhrir rkr\)rrs rLr0zFontProperties.set_variant+s3 ?ll>2G Hl3WE rNc|tjd}|tvr||_y t |}d|cxkr dkr ||_yt d|d#t $rYwxYw)aC Set the font weight. Parameters ---------- weight : int or {'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'}, default: :rc:`font.weight` If int, must be in the range 0-1000. Nz font.weightrr8zweight= is invalid)rhrirr^rrrrs rLr1zFontProperties.set_weight8s >\\-0F [ !DL  [FF"d"% #GF9K011     A A! A!c|tjd}|tvr||_y t |}d|cxkr dkr ||_yt d|d#t $rYwxYw)aP Set the font stretch or width. Parameters ---------- stretch : int or {'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'}, default: :rc:`font.stretch` If int, must be in the range 0-1000. Nz font.stretchrr8zstretch=rn)rhri stretch_dictr`rr)rrs rLr2zFontProperties.set_stretchRs ?ll>2G l "#DM  'lGG#t# ' $HG:[122    rpc r|tjd} t|}|dkrtjd|d}||_ y#t$rf t|}|t j z}nA#t$r5}tddjtttz|d}~wwxYwYwxYw)aG Set the font size. Parameters ---------- size : float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}, default: :rc:`font.size` If a float, the font size in points. The string values denote sizes relative to the default font size. N font.sizez%Size is invalid. Valid font size are , rzHFontsize %1.2f < 1.0 pt not allowed by FreeType. Setting fontsize = 1 pt)rhrifloatr font_scalings FontManagerget_default_sizeKeyErrorrVrrurinforb)rrscaleerrs rLr4zFontProperties.set_sizels <<< ,D >;D #: II015 7D  > >%d+ {;;==  C ;iiC 789:?BC C  >s5 A B6 A2B62 B0;0B++B00B65B6cL|tj||_yd|_y)zw Set the filename of the fontfile to use. In this case, all other properties will be ignored. N)rQfspathre)rfiles rLr3zFontProperties.set_files )-(8RYYt_ d rNct|jD]D\}}t|turt |d|z|d0t |d|z|Fy)z Set the properties by parsing a fontconfig_ *pattern*. This support does not depend on fontconfig; we are merely borrowing its pattern syntax for use here. set_rN)r rztypelistgetattr)rpatternrvals rLr6z%FontProperties.set_fontconfig_patterns_19??A 1HCCyD +fsl+CF3+fsl+C0  1rNc|jS)z} Return the name of the font family used for math text. The default font is :rc:`mathtext.fontset`. )_math_fontfamilyrPs rLrGz"FontProperties.get_math_fontfamilys $$$rNc|tjd}||_ytdjj }t j ||||_y)a Set the font family for text in math mode. If not set explicitly, :rc:`mathtext.fontset` will be used. Parameters ---------- fontfamily : str The name of the font family. Available font families are defined in the :ref:`default matplotlibrc file `. See Also -------- .text.Text.get_math_fontfamily Nzmathtext.fontset)r8)rhrirvalidvaluesr rkr)r fontfamily valid_fontss rLr5z"FontProperties.set_math_fontfamilysY$  &89J !+ &&89??FFHK   {J G *rNc,tj|S)zReturn a copy of self.)copyrPs rLrzFontProperties.copysyyrN)NNNNNNNN)#rrrrr*r9 classmethodr>rJrMrQrArWrZrCrrDrErFrOr.r/r0r1r2r4r3r6rGr5rset_namerB set_slantget_size_in_pointsrIrNrLr,r,LsAF"EI$(!%0"0(, )-4     1    2434<C 1%+6 HII!rNr,ceZdZfdZxZS) _JSONEncodercZt|trt|jdSt|trUt|jd} t t |djtj|d<|St|1|S#t$rY|SwxYw)Nrx __class__rr) rtrxdict__dict__rrur relative_torh get_data_pathrsuperdefault)rorrs rLrz_JSONEncoder.defaults a % m< < 9 %QZZ;7A !aj!1!=!=c>O>O>Q!RS' H7?1% %  H s;B B*)B*)rrrr __classcell__rs@rLrrs  & &rNrc|jdd}||S|dk(r6tjt}|jj ||S|dk(rgt j j|ds8t j jtj|d|d<tdi|}|Std|z)Nrrxrrz*Don't know how to deserialize __class__=%srI) poprx__new__rrrQrUisabsrVrhrrr)rr<rs rL _json_decoders %% T "C {     , ! ww}}QwZ(c&7&7&91W:FAgJ NNEKLLrNc. tj|5t|d5}tj||t dddddddy#1swYxYw#1swYyxYw#t $r }tjd|Yd}~yd}~wwxYw)a Dump `FontManager` *data* as JSON to the file named *filename*. See Also -------- json_load Notes ----- File paths that are children of the Matplotlib data path (typically, fonts shipped with Matplotlib) are stored relative to that data path (to remain valid across virtualenvs). This function temporarily locks the output file to prevent multiple processes from overwriting one another's output. wr)r<indentNz$Could not save font_manager cache %s) r _lock_pathopenjsondumprrgrr)datar]fhes rL json_dumprs"@   h ' <h)< < IIdBL ; < < < < < < @ ;Q??@sKA+ AAA A+A AA($A+(A++ B4BBczt|5}tj|tcdddS#1swYyxYw)zl Load a `FontManager` from the JSON file named *filename*. See Also -------- json_dump ) object_hookN)rrloadr)r]rs rL json_loadrs0 h72yy6777s1:ceZdZdZdZddZdZedZdZ e dZ d Z e d Z d Zd Zd ZdZdZdZ ddZdZ ddZeddZy)rxaC On import, the `FontManager` singleton instance creates a list of ttf and afm fonts and caches their `FontProperties`. The `FontManager.findfont` method does a nearest neighbor search to find the font that most closely matches the specification. If no good enough match is found, the default font is returned. Fonts added with the `FontManager.addfont` method will not persist in the cache; therefore, `addfont` will need to be called every time Matplotlib is imported. This method should only be used if and when a font cannot be installed on your operating system by other means. Notes ----- The `FontManager.addfont` method must be called on the global `FontManager` instance. Example usage:: import matplotlib.pyplot as plt from matplotlib import font_manager font_dirs = ["/resources/fonts"] # The path to the custom font file. font_files = font_manager.findSystemFonts(fontpaths=font_dirs) for font_file in font_files: font_manager.fontManager.addfont(font_file) iNc|j|_||_||_dDcgc]}t j d|}}t jd|ddd|_g|_ g|_ tjdd}|j d D]4}gt|| t| D]} |j|6 |j'ycc}w#t $r!}t j#d ||Yd}~Ud}~wt$$r!}t j#d ||Yd}~}d}~wwxYw#|j'wxYw) N)rHrE pdfcorefontsrCzfont search path %sz DejaVu Sans Helvetica)rHrEc,tjdS)Nz>Matplotlib is building the font cache; this may take a moment.)rrrIrNrLz&FontManager.__init__..Gs4<< L,NrN)rErHrJzFailed to open font file %s: %sz-Failed to extract font properties from %s: %s) __version___version_FontManager__default_weight default_sizer _get_data_pathrdebug defaultFamilyafmlistttflist threadingTimerstartraddfontrgr{ Exceptioncancel) rrrsubdirpathstimerrKrUexcs rLr9zFontManager.__init__4sY(( &  >?%%gv6?? (%0!   $NO  ) 3@oeWE@-g>@3D3 T*3 3 LLN7?*#P "CT3OO$3 #'(,c333 LLNsMC$#D>=C)D>) D;2D D> D;D61D>6D;;D>>Ectj|}t|jj dk(rRt |d5}t j|}dddt|}|jj|n;tj|}t|}|jj||jj!y#1swYxYw)a Cache the properties of the font at *path* to make it available to the `FontManager`. The type of font is inferred from the path suffix. Parameters ---------- path : str or path-like Notes ----- This method is useful for adding a custom font without installing it in your operating system. See the `FontManager` singleton instance for usage and caveats about this function. z.afmrbN)rQrrrSrTrr AFMrrappendr FT2Fontrr_findfont_cached cache_clear)rrUrrprops rLrzFontManager.addfontXs"{{4  :   " " $ .dD! $Rxx| $"4.D LL   %??4(D"4(D LL   % ))+ $ $s C$$C-c |jjDcic]\}}||j||c}}Scc}}w)NrJ)rrzrV)rrYr7s rL defaultFontzFontManager.defaultFontusI $(#5#5#;#;#=?CT]]63]77? ??sAc|jS)z1 Return the default font weight. rrPs rLget_default_weightzFontManager.get_default_weight|s$$$rNc(tjdS)z/ Return the default font size. rtrhrirIrNrLryzFontManager.get_default_sizes ||K((rNc||_y)zN Set the default font weight. The initial value is 'normal'. Nrros rLset_default_weightzFontManager.set_default_weights !'rNc:|dvrd}tjd|zS)N)r;r@rAzfont.r)r7s rL_expand_aliaseszFontManager._expand_aliasess$ + +!F||Gf,--rNct|ttfs|g}nt|dk(ry|j }dt|z }t |D]\}}|j }|t vrWgttj|j|}||vsN|j|}||t|z z|zcS||k(s{||zcSy)a& Return a match score between the list of font families in *families* and the font family name *family2*. An exact match at the head of the list returns 0.0. A match further down the list will return between 0 and 1. No match will return 1.0. rrrl) rtrr@r!rT enumeratefont_family_aliasesrrurindex)rfamiliesfamily2stepifamily1optionsidxs rL score_familyzFontManager.score_familys(T5M2 zH ]a --/3x= #H- JAwmmoG--JC 4+?+?+HIJg%!--0Cs7|!34<<G#4x rNc"||k(ry|dvr|dvryy)z Return a match score between *style1* and *style2*. An exact match returns 0.0. A match between 'italic' and 'oblique' returns 0.1. No match returns 1.0. )rrg?rrI)rstyle1style2s rL score_stylezFontManager.score_styles' V --11rNc||k(ryy)z} Return a match score between *variant1* and *variant2*. An exact match returns 0.0, otherwise 1.0. rrrI)rvariant1variant2s rL score_variantzFontManager.score_variants x rNc t|} t|}t ||z dz S#t$rtj|d}Y>wxYw#t$rtj|d}YWwxYw)z Return a match score between *stretch1* and *stretch2*. The result is the absolute value of the difference between the CSS numeric values of *stretch1* and *stretch2*, normalized between 0.0 and 1.0. rg@@)rrrrrabs)rstretch1stretch2 stretchval1 stretchval2s rL score_stretchzFontManager.score_stretchsz :h-K :h-K;,-66  :&**8S9K : :&**8S9K :s * AA  A A10A1ctj||ryt|tr|nt|}t|tr|nt|}dt ||z dz zdzS)ah Return a match score between *weight1* and *weight2*. The result is 0.0 if both weight1 and weight 2 are given as strings and have the same value. Otherwise, the result is the absolute value of the difference between the CSS numeric values of *weight1* and *weight2*, normalized between 0.05 and 1.0. rgffffff?r8g?)r _str_equalrtrrr)rweight1weight2w1w2s rL score_weightzFontManager.score_weights^   GW -"7F3WW9M"7F3WW9Ms27|d*+d22rNc|dk(ry t|} t|}t ||z dz S#t$r|jt|z}Y>wxYw#t$rYywxYw)a Return a match score between *size1* and *size2*. If *size2* (the size specified in the font file) is 'scalable', this function always returns 0.0, since any font size can be generated. Otherwise, the result is the absolute distance between *size1* and *size2*, normalized so that the usual range of font sizes (6pt - 72pt) will lie between 0.0 and 1.0. rrrH)rvrrrwr)rsize1size2sizeval1sizeval2s rL score_sizezFontManager.score_sizes~ J  @U|H U|H8h&'",,  @((=+??H @  s 0 AAA A! A!ctddD}|j||||||}t|tjr|j |S)a Find the path to the font file most closely matching the given font properties. Parameters ---------- prop : str or `~matplotlib.font_manager.FontProperties` The font properties to search for. This can be either a `.FontProperties` object or a string defining a `fontconfig patterns`_. fontext : {'ttf', 'afm'}, default: 'ttf' The extension of the font file: - 'ttf': TrueType and OpenType fonts (.ttf, .ttc, .otf) - 'afm': Adobe Font Metrics (.afm) directory : str, optional If given, only search this directory and its subdirectories. fallback_to_default : bool If True, will fall back to the default font family (usually "DejaVu Sans" or "Helvetica") if the first lookup hard-fails. rebuild_if_missing : bool Whether to rebuild the font cache and search again if the first match appears to point to a nonexisting font (i.e., the font cache contains outdated entries). Returns ------- str The filename of the best matching font. Notes ----- This performs a nearest neighbor search. Each font is given a similarity score to the target font properties. The first font with the highest score is returned. If no matches below a certain threshold are found, the default font (usually DejaVu Sans) is returned. The result is cached, so subsequent lookups don't have to perform the O(n) nearest neighbor search. See the `W3C Cascading Style Sheet, Level 1 `_ documentation for a description of the font finding algorithm. .. _fontconfig patterns: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html c3TK|] }ttj|"ywr)r@rhri)rrs rLrz'FontManager.findfont..Es"s% S 12s&()z font.serifzfont.sans-serifz font.cursivez font.fantasyzfont.monospace)r@rrtr _ExceptionInfo to_exception)rrrKrWfallback_to_defaultrebuild_if_missing rc_paramsrets rLrVzFontManager.findfont sfp? ## '9&9;M  c5// 0""$ $ rNcft|jDchc]}|jc}Scc}w)z#Return the list of available fonts.)rrr)rrs rLget_font_nameszFontManager.get_font_namesOs#4<<84TYY8998s.c tj|}g}|jD]I}|j}|j | |j |j |||d|K|sd|rW|j|} |j}|j | |j |j |||d||Std|S#t$rX|tvr6tjd|dj|j|ntjd|YwxYw)aq Find the paths to the font files most closely matching the given properties. Parameters ---------- prop : str or `~matplotlib.font_manager.FontProperties` The font properties to search for. This can be either a `.FontProperties` object or a string defining a `fontconfig patterns`_. fontext : {'ttf', 'afm'}, default: 'ttf' The extension of the font file: - 'ttf': TrueType and OpenType fonts (.ttf, .ttc, .otf) - 'afm': Adobe Font Metrics (.afm) directory : str, optional If given, only search this directory and its subdirectories. fallback_to_default : bool If True, will fall back to the default font family (usually "DejaVu Sans" or "Helvetica") if none of the families were found. rebuild_if_missing : bool Whether to rebuild the font cache and search again if the first match appears to point to a nonexisting font (i.e., the font cache contains outdated entries). Returns ------- list[str] The paths of the fonts found. Notes ----- This is an extension/wrapper of the original findfont API, which only returns a single font for given font properties. Instead, this API returns a list of filepaths of multiple fonts which closely match the given font properties. Since this internally uses the original API, there's no change to the logic of performing the nearest neighbor search. See `findfont` for more details. F)rr[findfont: Generic family %r not found because none of the following families were found: %sruz#findfont: Font family %r not found.TzFFailed to find any font, and fallback to the default font was disabled)r,r>rArr.rrVrrrrrVrr) rrrKrWrrfpathsr7cpropdfamilys rL_find_fonts_by_propsz FontManager._find_fonts_by_propsSsTZ''-oo' PFIIKE   V $ P MMw ,1+="  P0",,W5   ) MMw ,0+=" !"DEE 9 P00LLH $*>*>v*F G LL!FO Ps %CAD=<D=ic Ftj|}|j}||S|dk(r |j}n |j}d} d} t j d||D][} |+t|t| jjvr1|j|j| jdz|j|j| jz|j!|j#| j$z|j'|j)| j*z|j-|j/| j0z|j3|j5| j6z} t j d| | | | kr| } | } | dk(s\n| | dk\r|rt j9d|j|j:|t=t>j@|jD]@} | tBvs t j9d | d jE|jG| B|jI}|jK|j:||jM|||d StOjPtRd |dSt j d|| j| j| | j}tTjVjY|su|rYt j[dt]d }t_|jat_||jM|||d StOjPtRdStc|S)NrEg?O8Mzfindfont: Matching %s. zfindfont: score(%s) = %srg$@z7findfont: Font family %s not found. Falling back to %s.rruF)rzFailed to find font z/, and fallback to the default font was disabledz2findfont: Matching %s to %s (%r) with score of %f.z7findfont: Found a missing font file. Rebuilding cache.try_read_cache)rzNo valid font could be found)2r,r>rFrrrrrrparentsrrArrrZrrrCrrrrrrDrr rErrrrrurTrrVrrr.rVr rrrQrUisfiler{_load_fontmanagervarsr_cached_realpath)rrrKrWrrrrfontlist best_score best_fontrscorer7 default_propresultnew_fms rLrzFontManager._findfont_cachedsC''-   L e ||H||H   +T2 D%O4 +;+C+CC&&t'8$))DrI''(8$**EF))$*:*:*?MF!44 L"DIId.B.B6.J$KMM $yy{ ''(:(:7(CD}}\7I9>%@@ ++*4&1  JJKY^^Y__j J__Fww~~f%! MO*%@ T !!$v,/}}'9%HH ++J8VWW''rN)Nr!)rHNTT)rrrrrr9rpropertyrr staticmethodryrrrrrrrr rVrrrrrIrNrLrxrxs>K"H,:?? % )) ' ..<" 7$3$-07;>B@D:CGJNXtt_S(S(rNrxctjj|djdk(r*t |d5}|j ddk(cdddSy#1swYyxYw)z Return whether the given font is a Postscript Compact Font Format Font embedded in an OpenType wrapper. Used by the PostScript and PDF backends that cannot subset these fonts. rlz.otfrrsOTTONF)rQrUsplitextrTrread)r]fds rLis_opentype_cff_fontr4sd ww!!$**,6 (D ! )R771:( ) ) ) )s AA(@c |^}}tj|||Dcgc]}tj|||c}|Scc}w)N)_kerning_factor)_fallback_listr7)r r)font_filepathshinting_factorr7 thread_idfirst_fontpathrestfpaths rL _get_fontr?sW*NT ??    OO~ /  (   sA register_at_fork)after_in_childc@tjj|Sr)rQrUrealpath)rUs rLr&r&+s 77  D !!rNct|tttfr t |f}nt d|D}|t jd}t||t jdtjS)a= Get an `.ft2font.FT2Font` object given a list of file paths. Parameters ---------- font_filepaths : Iterable[str, Path, bytes], str, Path, bytes Relative or absolute paths to the font files to be used. If a single string, bytes, or `pathlib.Path`, then it will be treated as a list with that entry only. If more than one filepath is passed, then the returned FT2Font object will fall back through the fonts, in the order given, to find a needed glyph. Returns ------- `.ft2font.FT2Font` c32K|]}t|ywr)r&)rrs rLrzget_font..JsJ%&u-Jsztext.hinting_factorztext.kerning_factor)r7r;) rtrurrr&r@rhrir?r get_ident)r9r:rs rLrUrU2ss*.3e"45!.13J>JJ&;<   %:;%%'  rNr crttjdtjd}|rJ t |}t |dttjk(rtjd||St}t||tjd|S#t$rY8wxYw)Nz fontlist-vz.jsonrz"Using fontManager instance from %szgenerated new fontManager) rrh get_cachedirrxrrrobjectrrrrr{)r!fm_pathfms rLr$r$Ys j)@)@(AGIG 7#Br:vx0K4K4KK ?I B b'II)* I   s B** B65B6)NrHr)Tr __future__rbase64rr dataclassesr(riorrloggingnumbersrrQpathlibrrrrrr matplotlibrhr r r r matplotlib._fontconfig_patternr rmatplotlib.rcsetupr getLoggerrrrwrrrrrhome_HOMErdevnullrerprurorhrrrrMr^rjrrrr dataclassrrrr*r, JSONEncoderrrrrrxr4r?hasattrr@rr&rUr$ fontManagerrVrrIrNrLr^s;6#     11;*w"    6 DIIKEH :6877899: $/bjjnn_-G1G H      <;"@  D  D : :CDd#""$"<|N~CLL0f}"}"@ &4##&"M"@0 7o(o(d     2  ( 2!"By'<'<= 2"" $N)-$ !   ++G/  Es:H''II