
    ^j1                         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	d	d
dZ	 	 dd	d	d
dZ	 	 ddZ	 	 d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/opt/ringagent/.cad-venv/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 )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%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_descent.   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   Nfeatureslanguagec                   |dk(  r| j                  ||      \  }}}nC|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.
        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   s   N U?+/+>+>tQ+G(J	5>>$'D+/+D+Da(X ,E ,?(J	5 ,0+C+CD!+L(J	52u7A 	!3J	9e&z2NFFLL%9i*@@ALL 	! $ 	!NFFLL LL 	! HHV$Ee|r   c                   |
t               }|rt               }n|}g }g }	g }
t        j                  ||||      D ]  }| j                  |j                  |j
                        }|
j                  |       |j                  |j                         |	j                  |j                         ||vsu|j                  j                         ||<    dgt        |      z  }g }t        t        |
||	|            ||fS )zW
        Convert string *s* to vertices and codes using the provided ttf font.
        rE   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!'MM%M

!((D8hW 	FD--dnnd>N>NOJz*dff%dff%*,0NN,C,C,Ej)	F s:&Sj*eDE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_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   s    yy{doo&040D0D0J0Jtxx1-vw #I!'MM%M

:@ 	6D(E;B--dK@J*

dootxx893G3GH,0MMOj)b!b!z*doo-DLL	 ! 	+LBAq"XBF|b1fb1f-=1fb\B8V5E[[[[$++t{{DKK^^%E NNE5>*	+ Sj*eDEw( 	(r   c                 <   t               j                  || j                        }t        j                  || j
                        5 }|\  }ddd       |
t               }|rt               }n|}g g g g f\  }	}
}}j                  D ]J  }t        |j                  j                               }|j                  j                  rt        d      | j                  ||j                        }||vrt|j                          |j!                  | j                  | j
                         |j#                  |j                  t$        j&                         |j)                         ||<   |	j+                  |       |
j+                  |j,                         |j+                  |j.                         |j+                  |j0                  | j                  z         M g }|j2                  D ]  \  }}}}||f||z   |f||z   ||z   f|||z   f||fdg}t4        j6                  t4        j8                  t4        j8                  t4        j8                  t4        j8                  t4        j:                  g}|j+                  ||f        t=        t?        |	|
||            ||fS # 1 sw Y   IxY w)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   s8   
 ,''4??;[[$((+ 	sED	 #I!'MM%M57R^2ZU II 	;DDII2245Dyy  )*STT--dDJJ?J*

dootxx8

)2H2HI,0MMOj)z*dff%dff%LL$//9:	;   JJ 	+LBAq"XQ|b1fb1f-="q&\B8V5E[[[[$++t{{DKK^^%E NNE5>*	+ Sj*eDEw( 	(S	 	s   JJ)F)NF)__name__
__module____qualname____doc__r   r   r   r#   r&   r/   r5   rZ   rK   rL   rJ    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                   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_pathrZ   _should_simplify)
r   xyr:   rw   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   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    zzr   c                 :    | j                          | 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                 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_pathk  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   rT   r   __classcell__)r   s   @r   r   r     sM     /305<&|
 % %  "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      se    #    -  ) .   , *w"v( v(r |h"t h"r   