
    
3j1                         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
S
S.S jjr  SS
S
S.S jjr  SS jr  SS j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    M/home/wildlama/miniconda3/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      $ )z6Return a unique id for the given font and glyph index.-x)urllibparsequotepostscript_name)r   r$   glyphs      r   _get_glyph_reprTextToPath._get_glyph_repr*   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_descent.   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   Nfeatureslanguagec                   US:X  a  U R                  X5      u  pgnO@U(       d%  U R                  U5      n	U R                  XXES9u  pgnOU R                  X5      u  pgn/ / pU H6  u  ppX|   u  nnU
R	                  UU-  X/-   5        UR	                  U5        M8     U H(  u  nnU
R	                  U5        UR	                  U5        M*     U
(       d  [
        R                  " S5      n
X4$ )ah  
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.
language : str, optional
    The language of the text in a format accepted by libraqm, namely `a BCP47
    language code <https://www.w3.org/International/articles/language-tags/>`_.

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   rK   )r      )get_glyphs_texr%   get_glyphs_with_fontget_glyphs_mathtextextendnpempty)r   r"   r?   r@   rL   rM   
glyph_info	glyph_maprectsr$   vertscodes
glyph_repr	xposition	ypositionrB   verts1codes1s                     r   get_text_pathTextToPath.get_text_pathF   s    N U?+/+>+>t+G(J5>>$'D+/+D+D( ,E ,?(J5 ,0+C+CD+L(J52u7A3J9&2NFFLL%9*@@ALL  8B $NFFLL LL  $ HHV$E|r   c                   Uc
  [        5       nU(       a  [        5       nOUn/ n/ n	/ n
[        R                  " X!XVS9 H  nU R                  UR                  UR
                  5      nU
R                  U5        UR                  UR                  5        U	R                  UR                  5        X;  d  Mw  UR                  R                  5       X|'   M     S/[        U5      -  n/ n[        [        XX5      5      X~4$ )zG
Convert string *s* to vertices and codes using the provided ttf font.
rK   g      ?)r   r   layoutr3   	ft_objectglyph_indexappendr-   yget_pathlenlistzip)r   r$   r?   rW   return_new_glyphs_onlyrL   rM   glyph_map_new
xpositions
ypositionsglyph_reprsitemr[   sizesrX   s                  r   rQ   TextToPath.get_glyphs_with_font   s     #I!'MM%M

!((8WD--dnnd>N>NOJz*dff%dff%*,0NN,C,C,E) X s:&S*DE& 	&r   c                 4   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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_glyphr	   r(   rh   rf   r   MOVETOLINETO	CLOSEPOLYrj   rk   )r   r"   r?   rW   rl   rC   rD   rE   glyphsrX   rm   rn   ro   rp   rr   r$   rA   ccodere   oxoyr[   sizemyrectsrG   rH   vert1code1s                               r   rR   TextToPath.get_glyphs_mathtext   s    yy{doo&040D0D0J0Jxx1-w #I!'MM%M

:@6D(E;B--dK@J*

dootxx893G3GH,0MMOj)b!b!z*doo-DLL ;A !LBAq"XBF|b1fb1f-=1fb\B8V5E[[[[$++t{{DKK^^%E NNE5>* " S*DEw( 	(r   c                 R   [        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HL  n[        UR                  R                  5       5      nUR                  R                  (       a  [        S5      eU R                  XR                  5      nX;  ap  UR                  5         UR!                  U R                  U R
                  5        UR#                  UR                  [$        R&                  S9  UR)                  5       X'   U	R+                  U5        U
R+                  UR,                  5        UR+                  UR.                  5        UR+                  UR0                  U R                  -  5        GMO     / nUR2                   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[4        R6                  [4        R8                  [4        R8                  [4        R8                  [4        R8                  [4        R:                  /nUR+                  UU45        M     [=        [?        XX5      5      UU4$ ! , (       d  f       GNU= f)z?Convert the string *s* to vertices and codes using usetex mode.Nz'Indexing TTC fonts is not supported yetr7   ru   ) r   make_dvir    r   Dvir!   r   textr   r$   resolve_pathsubfontNotImplementedErrorr3   indexrv   r   rw   r	   TARGET_LIGHTrh   rf   r-   rg   	font_sizeboxesr   rx   ry   rz   rj   rk   )r   r"   r?   rW   rl   dvifiledvipagerm   rp   rn   ro   rr   r   r$   r[   r   r}   r~   rH   rG   r   r   s                          r   rP   TextToPath.get_glyphs_tex   s   
 ,''??;[[((+sED , #I!'MM%M57R^2 IIDDII2245Dyy  )*STT--dJJ?J*

dootxx8

)2H2HI,0MMO)z*dff%dff%LL$//9:    JJLBAq"XQ|b1fb1f-="q&\B8V5E[[[[$++t{{DKK^^%E NNE5>* ' S*DEw( 	(S ,+s   J
J&)r   r   )F)NF)__name__
__module____qualname____firstlineno____doc__r    r!   r   r%   r)   r3   r:   r`   rQ   rR   rP   __static_attributes__ r   r   r   r      sl    1J
C $G/0>td >@ 7;49&GK&*&B 6:381(f 15.30(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_sizeS  s    
r   c                     U R                   $ )zGet the text size.)r   r   s    r   get_sizeTextPath.get_sizeX  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.vertices\  s    
 	$$$r   c                     U R                   $ )z
Return the codes
)_codesr   s    r   rZ   TextPath.codesd  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_pathk  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   rZ   r   r   __classcell__)r   s   @r   r   r     sR     /305<&|
 % %  " "r   r   )collectionsr   loggingurllib.parser.   numpyrT   
matplotlibr   r   matplotlib.font_managerr   r   r   r   matplotlib.ft2fontr	   matplotlib.mathtextr
   matplotlib.pathr   matplotlib.texmanagerr   matplotlib.transformsr   	getLoggerr   _logr   r   r   r   r   r   <module>r      sc    #    -  ) .   , *"v( v(r |h"t h"r   