
    P/Ph3                         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                   z    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
dd
Z	 	 ddZ	 	 ddZ	 	 ddZe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    S/var/www/html/test/jupyter/venv/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 )zO
        Return a unique id for the given font and character-code set.
        -x)urllibparsequotepostscript_name)r   r"   ccodes      r   _get_char_idzTextToPath._get_char_id*   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_descent0   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   Fc                 
   |dk    r|                      ||          \  }}}nL|s0|                     |          }|                     ||          \  }}}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.

        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_fontget_glyphs_mathtextextendnpempty)r   r    r:   r;   
glyph_info	glyph_maprectsr"   vertscodesglyph_id	xposition	ypositionr=   verts1codes1s                   r   get_text_pathzTextToPath.get_text_pathH   sA   H U??+/+>+>tQ+G+G(J	55 	M>>$''D+/+D+DT1+M+M(J	55+/+C+CD!+L+L(J	52u5? 	! 	!1HiE&x0NFFLL%9i*@@AAALL    # 	! 	!NFFLL   LL      	%HV$$Ee|r   Nc                    |t                      }|rt                      }n|}g }g }t          j        ||          D ]~}|                     |j        t          |j                            }	|                    |	           |                    |j                   |	|vr|j        	                                ||	<   dgt          |          z  }
dgt          |          z  }g }t          t          |||
|                    ||fS )zW
        Convert string *s* to vertices and codes using the provided ttf font.
        Nr   g      ?)r   r   layoutr/   	ft_objectordcharappendr)   get_pathlenlistzip)r   r"   r:   rN   return_new_glyphs_onlyglyph_map_new
xpositions	glyph_idsitemchar_id
ypositionssizesrO   s                r   rH   zTextToPath.get_glyphs_with_font   s    #I! 	&'MMMM%M
	!(D11 	C 	CD''DIGGGW%%%df%%%i'')-)@)@)B)Bg&S3z??*
s:&SJ
EBBCCu& 	&r   c                 .   |                                 }|                    | 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_charr	   r%   r^   r]   r   MOVETOLINETO	CLOSEPOLYr`   ra   )r   r    r:   rN   rb   r>   r?   r@   glyphsrO   rc   rd   rh   re   ri   r"   r<   r.   oxoyrg   sizemyrectsrB   rC   vert1code1s                              r   rI   zTextToPath.get_glyphs_mathtext   s2    yy{{do&&&040D0J0Jtx1 1-vw  	&#I! 	&'MMMM%M

	-3 	 	)D(E2r''e44Gi''

dotx888uI,@AAA)-g&b!!!b!!!W%%%do-DLL! 	+ 	+LBAq"XBF|b1fb1f-=1fb\B8V5E[[$+t{DK^%E NNE5>****SJ
EBBCC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                  }||vr|                                 |                    | j        | j                   |j        }t          |t                     r7|                    |          }|                    |t&          j                   n^t          |t*                    r7|                     |           |                    |t&          j                   nt1          d|          |                                ||<   |	                    |           |
                    |j                   |                    |j                   |                    |j        | j        z             g }|j        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           tG          tI          |	|
||                    ||fS )z?Convert the string *s* to vertices and codes using usetex mode.Nr2   zGlyph spec of unexpected type: rk   )%r   make_dvir   r   Dvir   r   textr   	font_pathr/   glyphrl   r   glyph_name_or_index
isinstancestrget_name_index
load_glyphr	   TARGET_LIGHTint_select_native_charmaprm   	TypeErrorr^   r]   r)   y	font_sizeboxesr   rn   ro   rp   r`   ra   )r   r    r:   rN   rb   dvifiledvipagerc   re   rd   rh   ri   r{   r"   rg   r~   indexru   rr   rs   rC   rB   rv   rw   s                            r   rG   zTextToPath.get_glyphs_tex   s+   
 ,,''4?;;[$(++ 	sED	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 #I! 	&'MMMM%M35r2r>0	:z5 I 	; 	;DDN++D''dj99Gi''

dotx888&*&>#1377 	@ //0CDDEOOE1GOHHHH 3S99 @//555NN+93I # K K K K $ %?':%? %? @ @ @)-g&W%%%df%%%df%%%LL$/9:::: J 	+ 	+LBAq"XQ|b1fb1f-="q&\B8V5E[[$+t{DK^%E NNE5>****SJ
EBBCCw( 	(s   AAAc                     dD ]1}	 |                      |            d S # t          t          f$ r Y .w xY wt                              d| j                   d S )N)iCBDAiBODAz#No supported encoding in font (%s).)select_charmap
ValueErrorRuntimeError_logwarningfname)r"   charmap_codes     r   r   z!TextToPath._select_native_charmap  s}    
 	L 	LL##L111  -   
 LL>
KKKKKs   22)F)NF)__name__
__module____qualname____doc__r   r   r   r#   r&   r/   r5   rW   rH   rI   rG   staticmethodr    r   r   r   r      s        11J
C       $ $ $G G G/ / /0: : : :x 7;49& & & &> 6:381( 1( 1( 1(f 15.38( 8( 8( 8(t L L \L L L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_pathrW   _should_simplify)
r   xyr:   rt   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   rt   s     r   r   zTextPath.set_sizeh  s    
r   c                     | j         S )zGet the text size.)r   r   s    r   get_sizezTextPath.get_sizem  s
    zr   c                 8    |                                   | j        S )zH
        Return the cached path after updating it if necessary.
        )_revalidate_pathr   r   s    r   verticeszTextPath.verticesq  s    
 	$$r   c                     | j         S )z"
        Return the codes
        )_codesr   s    r   rQ   zTextPath.codesy  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_path  s     = 	"D19(**5l&==>>dh(B %'LL$@$@D!49D!'1!DMMM :9r   )NNr   F)r   r   r   r   r   r   r   propertyr   rQ   r   __classcell__)r   s   @r   r   r   %  s          /305<& <& <& <& <& <&|  
   % % X%   X" " " " " " "r   r   )collectionsr   loggingurllib.parser*   numpyrK   
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      st   # # # # # #          - - - - - - - -          ) ( ( ( ( ( . . . . . .             , , , , , , * * * * * *w""KL KL KL KL KL KL KL KL\ z||h" h" h" h" h"t h" h" h" h" h"r   