
    zYHh3                         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j2                  e      Z G d
 d      Z e       Z G d de      Zy)    )OrderedDictN)_text_helpersdviread)FontPropertiesget_fontfontManager)	LoadFlags)MathTextParser)Path)
TexManager)Affine2Dc                   r    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y
)
TextToPathz'A class that converts strings to paths.g      Y@H   c                 2    t        d      | _        d | _        y )Npath)r
   mathtext_parser_texmanagerselfs    L/var/www/html/planif/env/lib/python3.12/site-packages/matplotlib/textpath.py__init__zTextToPath.__init__   s    -f5    c                     t        j                  |      }t        |      }|j                  | 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   s9     !55d;		"dootxx0r   c                 "    t         j                  S )N)r	   
NO_HINTINGr   s    r   _get_hinting_flagzTextToPath._get_hinting_flag'   s    ###r   c                 `    t         j                  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%9$:!E!9"EFFr   c                    |j                         }|dk(  rt               j                  ||      S || j                  z  }|rZ|j	                         }|j                  | j                         | j                  j                  |d|      ^}}}}	||z  ||z  ||z  fS | j                  |      }
|
j                  |dt        j                         |
j                         \  }}|dz  }|dz  }|
j                         }|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   s   **,U?<==aJJ4??*99;DMM$//*$$**1b$7 'E67Q5=&5.'E/AA~~d#aI$8$89$$&1	T		T		T	5y!e)QY..r   c                    |dk(  r| j                  ||      \  }}}n@|s(| j                  |      }| j                  ||      \  }}}n| j                  ||      \  }}}g g }	}|D ]9  \  }
}}}||
   \  }}|j	                  ||z  ||gz          |	j	                  |       ; |D ]'  \  }}|j	                  |       |	j	                  |       ) |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   s   H U?+/+>+>tQ+G(J	5>>$'D+/+D+DT1+M(J	5+/+C+CD!+L(J	52u5? 	!1HiE&x0NFFLL%9i*@@ALL 	! $ 	!NFFLL LL 	! HHV$Ee|r   Nc                    |
t               }|rt               }n|}g }g }t        j                  ||      D ]  }| j                  |j                  t        |j                              }	|j                  |	       |j                  |j                         |	|vsc|j                  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.
        r   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!'MM%M
	!((D1 	CD''DIIGGW%dff%i')-)@)@)Bg&	C S3z?*
s:&SJ
EBCu& 	&r   c                 "   |j                         }|j                  | j                         | j                  j	                  || j
                  |      \  }}}}}	|s
t               }|rt               }
n|}
g }g }g }g }|D ]  \  }}}}}| j                  ||      }||vrj|j                          |j                  | j                  | j
                         |j                  |t        j                         |j                         |
|<   |j                  |       |j                  |       |j                  |       || j                  z  }|j                  |        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}|j                  ||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   s    yy{doo&040D0D0J0Jtxx1-vw #I!'MM%M

	-3 	)D(E2r''e4Gi'

dootxx8uI,@,@A)-g&b!b!W%doo-DLL	 ! 	+LBAq"XBF|b1fb1f-=1fb\B8V5E[[[[$++t{{DKK^^%E NNE5>*	+ SJ
EBCw( 	(r   c                    t               j                  || j                        }t        j                  || j
                        5 }|\  }ddd       |
t               }|rt               }n|}g g g g f\  }	}
}}j                  D ]  }t        |j                        }| j                  ||j                        }||vr|j                          |j                  | j                  | j
                         |j                  }t        |t               r3|j#                  |      }|j%                  |t&        j(                         nQt        |t*              r3| j-                  |       |j/                  |t&        j(                         nt1        d|      |j3                         ||<   |	j5                  |       |
j5                  |j6                         |j5                  |j8                         |j5                  |j:                  | j                  z          g }|j<                  D ]  \  }}}}||f||z   |f||z   ||z   f|||z   f||fdg}t>        j@                  t>        jB                  t>        jB                  t>        jB                  t>        jB                  t>        jD                  g}|j5                  ||f        tG        tI        |	|
||            ||fS # 1 sw Y   xY w)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!'MM%M35r2r>0	:z5 II 	;DDNN+D''djj9Gi'

dootxx8&*&>&>#137 //0CDEOOE1G1GOH 3S9//5NN+93I3I # K $&E':&=%? @ @)-g&W%dff%dff%LL$//9:-	;0  JJ 	+LBAq"XQ|b1fb1f-="q&\B8V5E[[[[$++t{{DKK^^%E NNE5>*	+ SJ
EBCw( 	(c	 	s   KK!c                     dD ]  }	 | j                  |        y  t        j	                  d| j
                         y # t        t        f$ r Y Jw xY w)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1 	L LL>

K - s   <AA)F)NF)__name__
__module____qualname____doc__r   r   r   r#   r&   r/   r5   rW   rH   rI   rG   staticmethodr    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                   Z     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.
    c                 .   ddl m} t        j                  |      }||j	                         }|| _        | j                  |       d| _         ||      j                  |      \  }}t        	| (  t        j                  |||      |dd d| _        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<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 $'88;	6''a'?!5	 !&r   c                      || _         d| _        y)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    zzr   c                 :    | j                          | 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                 P   | j                   s| j                   t               j                  | j                  t
        j                  z        j                  | j                   }|j                  | j                        | _        d| j                  j                  _        d| _         yy)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19(*5l&=&==>9dhh(B %'LL$@D!49D!!''1!DM :r   )NN   F)r   r   r   r   r   r   r   propertyr   rQ   r   __classcell__)r   s   @r   r   r   %  sM     /305<&|
 % %  "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      sg    #    -  ) .   , *w"KL KL\ |h"t h"r   