
    l0j1                         d dl mZ d dlZd dlZd dlZd dlmZm	Z	 d dl
mZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ  ej        e          Z G d
 d          Z e            Z G d de          ZdS )    )OrderedDictN)_text_helpersdviread)FontPropertiesget_fontfontManager)	LoadFlags)MathTextParser)Path)
TexManager)Affine2Dc                   t    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
dd
d
ddZ	 	 dd
d
ddZ	 	 ddZ	 	 ddZd
S )
TextToPathz'A class that converts strings to paths.g      Y@H   c                 <    t          d          | _        d | _        d S )Npath)r
   mathtext_parser_texmanagerselfs    V/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/matplotlib/textpath.py__init__zTextToPath.__init__   s     -f55    c                     t          j        |          }t          |          }|                    | j        | j                   |S )zX
        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_fontzTextToPath._get_font   s>     !5d;;		""dotx000r   c                     t           j        S )N)r	   
NO_HINTINGr   s    r   _get_hinting_flagzTextToPath._get_hinting_flag'   s    ##r   c                 V    t           j                            |j         d|d          S )z6Return a unique id for the given font and glyph index.-x)urllibparsequotepostscript_name)r   r"   glyphs      r   _get_glyph_reprzTextToPath._get_glyph_repr*   s,    |!!T%9"E"EE"E"E"EFFFr   c                 H   |                                 }|dk    r"t                                          ||          S || j        z  }|r\|                                }|                    | j                   | j                            |d|          ^}}}}	||z  ||z  ||z  fS |                     |          }
|
	                    |dt          j                   |
                                \  }}|dz  }|dz  }|
                                }|dz  }||z  ||z  ||z  fS )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   r5   z(TextToPath.get_text_width_height_descent.   s0   **,,U??<<==aJJJ4?* 	B99;;DMM$/***$**1b$77 'E67Q5=&5.'E/AA~~d##aI$8999$$&&1	T		T		T	5y!e)QY..r   FNfeatureslanguagec                   |dk    r|                      ||          \  }}}nO|s3|                     |          }	|                     |	|||          \  }}}n|                     ||          \  }}}g g }}
|D ]D\  }}}}||         \  }}|
                    ||z  ||gz              |                    |           E|D ]/\  }}|
                    |           |                    |           0|
st          j        d          }
|
|fS )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.
        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.
        r1   rE   )r      )get_glyphs_texr#   get_glyphs_with_fontget_glyphs_mathtextextendnpempty)r   r    r:   r;   rF   rG   
glyph_info	glyph_maprectsr"   vertscodes
glyph_repr	xposition	ypositionr=   verts1codes1s                     r   get_text_pathzTextToPath.get_text_pathF   sR   N U??+/+>+>tQ+G+G(J	55 	M>>$''D+/+D+Da(X ,E ,? ,?(J	55 ,0+C+CD!+L+L(J	52u7A 	! 	!3J	9e&z2NFFLL%9i*@@AAALL    # 	! 	!NFFLL   LL      	%HV$$Ee|r   c                
   |t                      }|rt                      }n|}g }g }	g }
t          j        ||||          D ]}|                     |j        |j                  }|
                    |           |                    |j                   |	                    |j                   ||vr|j        	                                ||<   dgt          |          z  }g }t          t          |
||	|                    ||fS )zW
        Convert string *s* to vertices and codes using the provided ttf font.
        NrE   g      ?)r   r   layoutr/   	ft_objectglyph_indexappendr)   yget_pathlenlistzip)r   r"   r:   rQ   return_new_glyphs_onlyrF   rG   glyph_map_new
xpositions
ypositionsglyph_reprsitemrU   sizesrR   s                  r   rK   zTextToPath.get_glyphs_with_font   s    #I! 	&'MMMM%M

!(D8hWWW 	F 	FD--dnd>NOOJz***df%%%df%%%**,0N,C,C,E,Ej)s:&Sj*eDDEEu& 	&r   c                 0   |                                 }|                    | j                   | j                            || j        |          \  }}}}}	|st                      }|rt                      }
n|}
g }g }g }g }|D ]\  }}}}}}|                     ||          }||vrl|                                 |                    | j        | j                   |	                    |t          j                   |                                |
|<   |                    |           |                    |           |                    |           || j        z  }|                    |           g }|	D ]\  }}}}||f|||z   f||z   ||z   f||z   |f||fdg}t          j        t          j        t          j        t          j        t          j        t          j        g}|                    ||f           t%          t'          ||||                    |
|fS )zW
        Parse mathtext string *s* and convert it to a (vertices, codes) pair.
        r2   r   r   )r6   r   r   r   r+   r   r   r/   clear
load_glyphr	   r%   ra   r_   r   MOVETOLINETO	CLOSEPOLYrc   rd   )r   r    r:   rQ   re   r>   r?   r@   glyphsrR   rf   rg   rh   ri   rk   r"   r<   ccoder^   oxoyrU   sizemyrectsrB   rC   vert1code1s                               r   rL   zTextToPath.get_glyphs_mathtext   s4    yy{{do&&&040D0J0Jtx1 1-vw  	&#I! 	&'MMMM%M

:@ 	 	6D(E;B--dK@@J**

dotx88893GHHH,0MMOOj)b!!!b!!!z***do-DLL! 	+ 	+LBAq"XBF|b1fb1f-=1fb\B8V5E[[$+t{DK^%E NNE5>****Sj*eDDEEw( 	(r   c                     t                                          || j                  }t          j        || j                  5 }|\  }ddd           n# 1 swxY w Y   |t                      }|rt                      }n|}g g g g f\  }	}
}}|j        D ]?}t          |j	        
                                          }|j	        j        rt          d          |                     ||j                  }||vrq|                                 |                    | j        | j                   |                    |j        t$          j                   |                                ||<   |	                    |           |
                    |j                   |                    |j                   |                    |j        | j        z             Ag }|j        D ]\  }}}}||f||z   |f||z   ||z   f|||z   f||fdg}t4          j        t4          j        t4          j        t4          j        t4          j        t4          j        g}|                    ||f           t=          t?          |	|
||                    ||fS )z?Convert the string *s* to vertices and codes using usetex mode.Nz'Indexing TTC fonts is not supported yetr2   rm   ) r   make_dvir   r   Dvir   r   textr   r"   resolve_pathsubfontNotImplementedErrorr/   indexrn   r   ro   r	   TARGET_LIGHTra   r_   r)   r`   	font_sizeboxesr   rp   rq   rr   rc   rd   )r   r    r:   rQ   re   dvifiledvipagerf   ri   rg   rh   rk   r~   r"   rU   rx   ru   rv   rC   rB   ry   rz   s                          r   rJ   zTextToPath.get_glyphs_tex   s   
 ,,''4?;;[$(++ 	sED	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 #I! 	&'MMMM%M57R^2ZU I 	; 	;DDI224455Dy  U)*STTT--dDJ??J**

dotx888
)2HIII,0MMOOj)z***df%%%df%%%LL$/9:::: J 	+ 	+LBAq"XQ|b1fb1f-="q&\B8V5E[[$+t{DK^%E NNE5>****Sj*eDDEEw( 	(s   AAA)F)NF)__name__
__module____qualname____doc__r   r   r   r#   r&   r/   r5   rZ   rK   rL   rJ    r   r   r   r      s        11J
C       $ $ $G G G/ / /0>td > > > > >@ 7;49&GK&*& & & & &B 6:381( 1( 1( 1(f 15.30( 0( 0( 0( 0( 0(r   r   c                   f     e Zd ZdZ	 	 d fd	Zd Zd Zed             Zed	             Z	d
 Z
 xZS )TextPathz&
    Create a path from the text.
    N   Fc                 j   ddl m} t          j        |          }||                                }|| _        |                     |           d| _         ||                              |          \  }} t                      j
        t                              |||          |dd d| _        dS )	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_anyr4   _xyr   _cached_vertices_preprocess_mathsuperr   text_to_pathrZ   _should_simplify)
r   xyr:   rw   r    r   r   r   r;   	__class__s
            r   r   zTextPath.__init__  s    Z 	)((((('--<**,,Dd $D'''88;;	6''a'??!5	 	 	 	 !&r   c                 "    || _         d| _        dS )zSet the text size.TN)_size_invalid)r   rw   s     r   r   zTextPath.set_sizeS  s    
r   c                     | j         S )zGet the text size.)r   r   s    r   get_sizezTextPath.get_sizeX  s
    zr   c                 8    |                                   | j        S )zH
        Return the cached path after updating it if necessary.
        )_revalidate_pathr   r   s    r   verticeszTextPath.vertices\  s    
 	$$r   c                     | j         S )z"
        Return the codes
        )_codesr   s    r   rT   zTextPath.codesd  s    
 {r   c                    | j         s| j        y t                                          | j        t
          j        z            j        | j         }|	                    | j
                  | _        d| j        j        _        d| _         dS dS )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   r=   r   r   r   	translater   	transform	_verticesr3   	writeable)r   trs     r   r   zTextPath._revalidate_pathk  s     = 	"D19(**5l&==>>dh(B %'LL$@$@D!49D!'1!DMMM :9r   )NNr   F)r   r   r   r   r   r   r   propertyr   rT   r   __classcell__)r   s   @r   r   r     s          /305<& <& <& <& <& <&|  
   % % X%   X" " " " " " "r   r   )collectionsr   loggingurllib.parser*   numpyrN   
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      sl   # # # # # #          - - - - - - - -          ) ( ( ( ( ( . . . . . .             , , , , , , * * * * * *w""v( v( v( v( v( v( v( v(r z||h" h" h" h" h"t h" h" h" h" h"r   