
    h3                         S SK Jr  S SKrS SKrS SKrS SKJrJ	r	  S SK
JrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  \R2                  " \5      r " S
 S5      r\" 5       r " S S\5      rg)    )OrderedDictN)_text_helpersdviread)FontPropertiesget_fontfontManager)	LoadFlags)MathTextParser)Path)
TexManager)Affine2Dc                       \ rS rSrSrSrSrS rS rS r	S r
S	 rSS
 jr  SS jr  SS jr  SS jr\S 5       rSrg)
TextToPath   z'A class that converts strings to paths.g      Y@H   c                 2    [        S5      U l        S U l        g )Npath)r
   mathtext_parser_texmanagerselfs    E/var/www/html/env/lib/python3.13/site-packages/matplotlib/textpath.py__init__TextToPath.__init__   s    -f5    c                     [         R                  " U5      n[        U5      nUR                  U R                  U R
                  5        U$ )zH
Find the `FT2Font` matching font properties *prop*, with its size set.
)_fontManager_find_fonts_by_propsr   set_size
FONT_SCALEDPI)r   prop	filenamesfonts       r   	_get_fontTextToPath._get_font   s9     !55d;		"dootxx0r   c                 "    [         R                  $ )N)r	   
NO_HINTINGr   s    r   _get_hinting_flagTextToPath._get_hinting_flag'   s    ###r   c                 `    [         R                  R                  UR                   SUS 35      $ )z?
Return a unique id for the given font and character-code set.
-x)urllibparsequotepostscript_name)r   r$   ccodes      r   _get_char_idTextToPath._get_char_id*   s-     ||!!T%9%9$:!E!9"EFFr   c                    UR                  5       nUS:X  a  [        5       R                  X5      $ X@R                  -  nU(       aU  UR	                  5       nUR                  U R                  5        U R                  R                  USU5      tpgpXe-  Xu-  X-  4$ U R                  U5      n
U
R                  US[        R                  S9  U
R                  5       u  pUS-  nUS-  nU
R                  5       nUS-  nX-  X-  X-  4$ )NTeXr   g        flagsg      P@)get_size_in_pointsr   get_text_width_height_descentr    copyr   r   r/   r%   set_textr	   r(   get_width_heightget_descent)r   sr"   ismathfontsizescalewidthheightdescent_r$   whds                 r   r:   (TextToPath.get_text_width_height_descent0   s    **,U?<==aJJ??*99;DMM$//*$$**1b$7 'E7=&.'/AA~~d#aI$8$89$$&	T		T		T	y!)QY..r   c                    US:X  a  U R                  X5      u  pEnOAU(       d&  U R                  U5      nU R                  Xr5      u  pEnOU R                  X5      u  pEn/ / pU H4  u  ppXZ   u  pUR	                  X-  X/-   5        U	R	                  U5        M6     U H'  u  pUR	                  U5        U	R	                  U5        M)     U(       d  [
        R                  " S5      nX4$ )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.
r6   )r      )get_glyphs_texr%   get_glyphs_with_fontget_glyphs_mathtextextendnpempty)r   r"   r?   r@   
glyph_info	glyph_maprectsr$   vertscodesglyph_id	xposition	ypositionrB   verts1codes1s                   r   get_text_pathTextToPath.get_text_pathH   s    H U?+/+>+>t+G(J5>>$'D+/+D+DT+M(J5+/+C+CD+L(J52u5?1H&0NFLL9*@@ALL  6@ $NFLL LL  $ HHV$E|r   Nc                    Uc
  [        5       nU(       a  [        5       nOUn/ n/ n[        R                  " X!5       H  nU R                  UR                  [        UR                  5      5      n	UR                  U	5        UR                  UR                  5        X;  d  Me  UR                  R                  5       XY'   M     S/[        U5      -  n
S/[        U5      -  n/ n[        [        XvX5      5      X\4$ )zG
Convert string *s* to vertices and codes using the provided ttf font.
r   g      ?)r   r   layoutr3   	ft_objectordcharappendr-   get_pathlenlistzip)r   r$   r?   rT   return_new_glyphs_onlyglyph_map_new
xpositions	glyph_idsitemchar_id
ypositionssizesrU   s                r   rN   TextToPath.get_glyphs_with_font   s     #I!'MM%M
	!((1D''DIIGGW%dff%')-)@)@)B& 2 S3z?*
s:&S
BC& 	&r   c                 2   UR                  5       nUR                  U R                  5        U R                  R	                  X R
                  U5      u  pVpxn	U(       d
  [        5       nU(       a  [        5       n
OUn
/ n/ n/ n/ nU H  u  nnnnnU R                  UU5      nUU;  ag  UR                  5         UR                  U R                  U R
                  5        UR                  U[        R                  S9  UR                  5       U
U'   UR                  U5        UR                  U5        UR                  U5        UU R                  -  nUR                  U5        M     / nU	 H  u  nnnnUU4UUU-   4UU-   UU-   4UU-   U4UU4S/n[        R                  [        R                   [        R                   [        R                   [        R                   [        R"                  /nUR                  UU45        M     [%        ['        XX5      5      U
U4$ )zG
Parse mathtext string *s* and convert it to a (vertices, codes) pair.
r7   r   r   )r;   r   r    r   r/   r!   r   r3   clear	load_charr	   r(   re   rd   r   MOVETOLINETO	CLOSEPOLYrg   rh   )r   r"   r?   rT   ri   rC   rD   rE   glyphsrU   rj   rk   ro   rl   rp   r$   rA   r2   oxoyrn   sizemyrectsrG   rH   vert1code1s                              r   rO   TextToPath.get_glyphs_mathtext   s    yy{doo&040D0D0J0Jxx1-w #I!'MM%M

	-3)D(E2r''e4Gi'

dootxx8uI,@,@A)-g&b!b!W%doo-DLL .4 !LBAq"XBF|b1fb1f-=1fb\B8V5E[[[[$++t{{DKK^^%E NNE5>* " S
BCw( 	(r   c                    [        5       R                  X R                  5      n[        R                  " XPR
                  5       nUu  nSSS5        Uc
  [        5       nU(       a  [        5       nOUn/ / / / 4u  ppWR                   GH  n[        UR                  5      nU R                  XR                  5      nX;  a  UR                  5         UR                  U R                  U R
                  5        UR                  n[        U[         5      (       a0  UR#                  U5      nUR%                  U[&        R(                  S9  OT[        U[*        5      (       a0  U R-                  U5        UR/                  U[&        R(                  S9  O[1        SU< 35      eUR3                  5       X'   U	R5                  U5        U
R5                  UR6                  5        UR5                  UR8                  5        UR5                  UR:                  U R                  -  5        GM     / nUR<                   H  u  nnnnUU4UU-   U4UU-   UU-   4UUU-   4UU4S/n[>        R@                  [>        RB                  [>        RB                  [>        RB                  [>        RB                  [>        RD                  /nUR5                  UU45        M     [G        [I        XX5      5      UU4$ ! , (       d  f       GN= f)z?Convert the string *s* to vertices and codes using usetex mode.Nr7   zGlyph spec of unexpected type: rs   )%r   make_dvir    r   Dvir!   r   textr   	font_pathr3   glyphrt   r   glyph_name_or_index
isinstancestrget_name_index
load_glyphr	   TARGET_LIGHTint_select_native_charmapru   	TypeErrorre   rd   r-   y	font_sizeboxesr   rv   rw   rx   rg   rh   )r   r"   r?   rT   ri   dvifiledvipagerj   rl   rk   ro   rp   r   r$   rn   r   indexr}   rz   r{   rH   rG   r~   r   s                            r   rM   TextToPath.get_glyphs_tex   sr   
 ,''??;[[((+sED , #I!'MM%M35r2r>0	z IIDDNN+D''jj9G'

dootxx8&*&>&>#1377 //0CDEOOE1G1GOH 3S99//5NN+93I3I # K $&E':&=%? @ @)-&W%dff%dff%LL$//9:- 0  JJLBAq"XQ|b1fb1f-="q&\B8V5E[[[[$++t{{DKK^^%E NNE5>* ' S
BCw( 	(c ,+s   K  
K/c                     S H  n U R                  U5          g    [        R	                  SU R
                  5        g ! [        [        4 a     MM  f = f)N)iCBDAiBODAz#No supported encoding in font (%s).)select_charmap
ValueErrorRuntimeError_logwarningfname)r$   charmap_codes     r   r   !TextToPath._select_native_charmap  sT    
L##L1 
 LL>

K - s   =AA)r   r   )F)NF)__name__
__module____qualname____firstlineno____doc__r    r!   r   r%   r)   r3   r:   r]   rN   rO   rM   staticmethodr   __static_attributes__ r   r   r   r      sn    1J
C $G/0:x 7;49&> 6:381(f 15.38(t L Lr   r   c                   f   ^  \ rS rSrSr  S
U 4S jjrS rS r\S 5       r	\S 5       r
S rS	rU =r$ )TextPathi%  z
Create a path from the text.
c                 "  > SSK Jn  [        R                  " U5      nUc  UR	                  5       nXl        U R                  U5        SU l        U" US9R                  U5      u  p([        T	U ](  " [        R                  XBUS9USS.6  SU l        g)	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<customizing-with-dynamic-rc-settings>`.

_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_stepsreadonlyF)matplotlib.textr   r   	_from_anyr9   _xyr   _cached_vertices_preprocess_mathsuperr   text_to_pathr]   _should_simplify)
r   xyr?   r|   r"   r   r   r   r@   	__class__s
            r   r   TextPath.__init__*  s    Z 	)''-<**,Dd $'88;	'''?!5	 !&r   c                     Xl         SU l        g)zSet the text size.TN)_size_invalid)r   r|   s     r   r   TextPath.set_sizeh  s    
r   c                     U R                   $ )zGet the text size.)r   r   s    r   get_sizeTextPath.get_sizem  s    zzr   c                 :    U R                  5         U R                  $ )z8
Return the cached path after updating it if necessary.
)_revalidate_pathr   r   s    r   verticesTextPath.verticesq  s    
 	$$$r   c                     U R                   $ )z
Return the codes
)_codesr   s    r   rW   TextPath.codesy  s    
 {{r   c                 \   U R                   (       d  U R                  c  [        5       R                  U R                  [
        R                  -  5      R                  " U R                  6 nUR                  U R                  5      U l        SU R                  R                  l        SU l         gg)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)r   r   r   rB   r   r   r    	translater   	transform	_verticesr8   	writeable)r   trs     r   r   TextPath._revalidate_path  s     ==D119*5l&=&==>9"hh(B %'LL$@D!49D!!''1!DM :r   )r   r   r   r   r   )NN   F)r   r   r   r   r   r   r   r   propertyr   rW   r   r   __classcell__)r   s   @r   r   r   %  sR     /305<&|
 % %  " "r   r   )collectionsr   loggingurllib.parser.   numpyrQ   
matplotlibr   r   matplotlib.font_managerr   r   r   r   matplotlib.ft2fontr	   matplotlib.mathtextr
   matplotlib.pathr   matplotlib.texmanagerr   matplotlib.transformsr   	getLoggerr   r   r   r   r   r   r   r   <module>r      se    #    -  ) .   , *"KL KL\ |h"t h"r   