rL i3ddlmZddlZddlZddlZddlmZm Z ddl m Z m Z m ZddlmZddlmZddlmZddlmZdd lmZej2eZGd d ZeZGd d eZy)) OrderedDictN) _text_helpersdviread)FontPropertiesget_font fontManager) LoadFlags)MathTextParser)Path) TexManager)Affine2DcreZdZdZdZdZdZdZdZdZ dZ dd Z dd Z dd Z dd ZedZy ) TextToPathz'A class that converts strings to paths.gY@Hc2td|_d|_y)Npath)r mathtext_parser _texmanagerselfs Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/textpath.py__init__zTextToPath.__init__s-f5ctj|}t|}|j|j|j |S)zX Find the `FT2Font` matching font properties *prop*, with its size set. ) _fontManager_find_fonts_by_propsrset_size FONT_SCALEDPI)rprop filenamesfonts r _get_fontzTextToPath._get_fonts9!55d;  " dootxx0 rc"tjS)N)r NO_HINTINGrs r_get_hinting_flagzTextToPath._get_hinting_flag's###rc`tjj|jd|dS)zO Return a unique id for the given font and character-code set. -x)urllibparsequotepostscript_name)rr"ccodes r _get_char_idzTextToPath._get_char_id*s-||!!T%9%9$:!E!9"EFFrc|j}|dk(rtj||S||jz }|rZ|j }|j |j|j j|d|^}}}} ||z||z||zfS|j|} | j|dtj| j\} } | dz} | dz} | j} | dz} | |z| |z| |zfS)NTeXrgflagsgP@)get_size_in_pointsr get_text_width_height_descentrcopyrrr+r#set_textr r%get_width_height get_descent)rsr ismathfontsizescalewidthheightdescent_r"whds rr5z(TextToPath.get_text_width_height_descent0s**, U?<==aJ J4??* 99;D MM$// *$$**1b$7 'E67Q5=&5.'E/A A~~d# aI$8$8 9$$&1 T  T      T 5y!e)QY..rc|dk(r|j||\}}}n@|s(|j|}|j||\}}}n|j||\}}}gg} }|D]9\} } } } || \}}|j || z| | gz| j |;|D]'\}}|j || j |)|st j d}|| fS)a Convert text *s* to path (a tuple of vertices and codes for matplotlib.path.Path). Parameters ---------- prop : `~matplotlib.font_manager.FontProperties` The font properties for the text. s : str The text to be converted. ismath : {False, True, "TeX"} If True, use mathtext parser. If "TeX", use tex for rendering. Returns ------- verts : list A list of arrays containing the (x, y) coordinates of the vertices. codes : list A list of path codes. Examples -------- Create a list of vertices and codes from a text, and create a `.Path` from those:: from matplotlib.path import Path from matplotlib.text import TextToPath from matplotlib.font_manager import FontProperties fp = FontProperties(family="Comic Neue", style="italic") verts, codes = TextToPath().get_text_path(fp, "ABC") path = Path(verts, codes, closed=False) Also see `TextPath` for a more direct way to create a path from a text. r1)r)get_glyphs_texr#get_glyphs_with_fontget_glyphs_mathtextextendnpempty)rr r:r; glyph_info glyph_maprectsr"vertscodesglyph_id xposition ypositionr=verts1codes1s r get_text_pathzTextToPath.get_text_pathHsH U?+/+>+>tQ+G (J 5>>$'D+/+D+DT1+M (J 5+/+C+CD!+L (J 52u5? ! 1HiE&x0NFF LL%9i*@@ A LL  !$ !NFF LL LL  ! HHV$Ee|rNc| t}|r t}n|}g}g}tj||D]}|j|jt |j } |j| |j|j| |vsc|jj|| <dgt|z} dgt|z} g} tt||| | || fS)zW Convert string *s* to vertices and codes using the provided ttf font. rg?) rrlayoutr/ ft_objectordcharappendr)get_pathlenlistzip) rr"r:rNreturn_new_glyphs_only glyph_map_new xpositions glyph_idsitemchar_id ypositionssizesrOs rrHzTextToPath.get_glyphs_with_fonts  # I !'MM%M  !((D1 CD''DIIGG   W %   dff %i')-)@)@)B g&  CS3z?* s:&SJ EBCu& &rc"|j}|j|j|jj ||j |\}}}}} |s t }|r t } n|} g} g} g} g}|D]\}}}}}|j||}||vrj|j|j|j|j |j|tj|j| |<| j|| j|| j|||jz }|j|g}| D]\}}}}||f|||zf||z||zf||z|f||fdg}tjtj tj tj tj tj"g}|j||ft%t'| | | || |fS)zW Parse mathtext string *s* and convert it to a (vertices, codes) pair. r2rr)r6rrrr+rrr/clear load_charr r%r^r]r MOVETOLINETO CLOSEPOLYr`ra)rr r:rNrbr>r?r@glyphsrOrcrdrhrerir"r<r.oxoyrgsizemyrectsrBrCvert1code1s rrIzTextToPath.get_glyphs_mathtexts yy{ doo&040D0D0J0J txx1-vw# I !'MM%M   -3  )D(E2r''e4Gi'  dootxx8uI,@,@A)- g&   b !   b !   W %doo-D LL  ! +LBAq"XBF|b1fb1f-=1fb\B8V5E[[[[$++t{{DKK^^%E NNE5> *  +SJ EBCw( (rctj||j}tj||j 5}|\}ddd| t }|r t }n|}ggggf\} } } } jD]} t| j}|j|| j}||vr|j|j|j|j | j}t|t r3|j#|}|j%|t&j(nQt|t*r3|j-||j/|t&j(nt1d||j3||<| j5|| j5| j6| j5| j8| j5| j:|jz g}|j<D]\}}}}||f||z|f||z||zf|||zf||fdg}t>j@t>jBt>jBt>jBt>jBt>jDg}|j5||ftGtI| | | | ||fS#1swYxYw)z?Convert the string *s* to vertices and codes using usetex mode.Nr2zGlyph spec of unexpected type: rk)%r make_dvirrDvirrtextr font_pathr/glyphrlrglyph_name_or_index isinstancestrget_name_index load_glyphr TARGET_LIGHTint_select_native_charmaprm TypeErrorr^r]r)y font_sizeboxesr rnrorpr`ra)rr r:rNrbdvifiledvipagercrerdrhrir{r"rgr~indexrurrrsrCrBrvrws rrGzTextToPath.get_glyphs_texs ,''4??; [[$(( + sED   # I !'MM%M35r2r>0 :z5II ;DDNN+D''djj9Gi'  dootxx8&*&>&>#137 //0CDEOOE1G1GOH 3S9//5NN+93I3I#K$&E':&=%?@@)- g&   W %   dff %   dff % LL$//9 :- ;0 JJ +LBAq"XQ|b1fb1f-="q&\B8V5E[[[[$++t{{DKK^^%E NNE5> *  +SJ EBCw( (c  s KK!cdD]} |j|ytj d|j y#ttf$rYJwxYw)N)iCBDAiBODAz#No supported encoding in font (%s).)select_charmap ValueError RuntimeError_logwarningfname)r" charmap_codes rrz!TextToPath._select_native_charmaps[ LL ##L1 L LL> K  -  s<A A)F)NF)__name__ __module__ __qualname____doc__rrrr#r&r/r5rWrHrIrG staticmethodrrrrrsn1J C $G /0:x7;49&>6:381(f15.38(tLLrrcZeZdZdZ dfd ZdZdZedZedZ dZ xZ S) TextPathz& Create a path from the text. c.ddlm}tj|}||j }||_|j |d|_||j|\}}t |(tj||||ddd|_ y) a Create a path from the text. 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. Parameters ---------- xy : tuple or array of two float values Position of the text. For no offset, use ``xy=(0, 0)``. s : str The text to convert to a path. size : float, optional Font size in points. Defaults to the size specified via the font properties *prop*. prop : `~matplotlib.font_manager.FontProperties`, optional Font property. If not provided, will use a default `.FontProperties` with parameters from the :ref:`rcParams`. _interpolation_steps : int, optional (Currently ignored) usetex : bool, default: False Whether to use tex rendering. Examples -------- The following creates a path from the string "ABC" with Helvetica font face; and another path from the latex fraction 1/2:: from matplotlib.text import TextPath from matplotlib.font_manager import FontProperties fp = FontProperties(family="Helvetica", style="italic") path1 = TextPath((12, 12), "ABC", size=12, prop=fp) path2 = TextPath((0, 0), r"$\frac{1}{2}$", size=12, usetex=True) Also see :doc:`/gallery/text_labels_and_annotations/demo_text_path`. r)TextN)usetex)r;T)_interpolation_stepsreadonlyF)matplotlib.textrr _from_anyr4_xyr_cached_vertices_preprocess_mathsuperr text_to_pathrW_should_simplify) rxyr:rtr rrrr; __class__s rrzTextPath.__init__*sZ )''- <**,D d $'88; 6   ' 'a ' ?!5 !&rc ||_d|_y)zSet the text size.TN)_size_invalid)rrts rrzTextPath.set_sizehs  rc|jS)zGet the text size.)rrs rget_sizezTextPath.get_sizems zzrc:|j|jS)zH Return the cached path after updating it if necessary. )_revalidate_pathrrs rverticeszTextPath.verticesqs $$$rc|jS)z" Return the codes )_codesrs rrQzTextPath.codesys {{rcP|js |jtj|jt j z j|j}|j|j|_d|jj_ d|_yy)z 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. NF) rrr r=rrr translater transform _verticesr3 writeable)rtrs rrzTextPath._revalidate_paths ==D119(*5l&=&==>9dhh(B%'LL$@D !49D ! ! ' ' 1!DM :r)NNF) rrrrrrrpropertyrrQr __classcell__)rs@rrr%sM/305<&| %% "rr) collectionsrlogging urllib.parser*numpyrK matplotlibrrmatplotlib.font_managerrrrrmatplotlib.ft2fontr matplotlib.mathtextr matplotlib.pathr matplotlib.texmanagerr matplotlib.transformsr getLoggerrrrrrrrrrsg#-). ,*w"KLKL\| h"th"r