§
    õŽ’j3  ã                   óô   — 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    úAC:\Projects\DSCons\.venv\Lib\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>   € õ !Ô5°dÑ;Ô;ˆ	Ý˜	Ñ"Ô"ˆØ�Š�d”o t¤xÑ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Ð"E¸EÐ"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Ø—9’9‘;”;ˆDØ�MŠM˜$œ/Ñ*Ô*Ð*àÔ$×*Ò*¨1¨b°$Ñ7Ô7ð 'ˆE�6˜7 Qà˜5‘= &¨5¡.°'¸E±/ÐAÐAà�~Š~˜dÑ#Ô#ˆØ�Š�a˜¥IÔ$8ˆÑ9Ô9Ð9Ø×$Ò$Ñ&Ô&‰ˆˆ1Ø	ˆT‰	ˆØ	ˆT‰	ˆØ×ÒÑÔˆØ	ˆT‰	ˆØ�5‰y˜!˜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Š?ˆ?Ø+/×+>Ò+>¸tÀQÑ+GÔ+GÑ(ˆJ˜	 5 5Øð 	MØ—>’> $Ñ'Ô'ˆDØ+/×+DÒ+DØ�a (°Xð ,Eñ ,?ô ,?Ñ(ˆJ˜	 5 5ð ,0×+CÒ+CÀDÈ!Ñ+LÔ+LÑ(ˆJ˜	 5à˜2ˆuˆØ7Að 	!ð 	!Ñ3ˆJ˜	 9¨eØ& zÔ2‰NˆF�FØ�LŠL˜ %™¨9°iÐ*@Ñ@ÑAÔAÐAØ�LŠL˜Ñ Ô Ð Ð Ø#ð 	!ð 	!‰NˆF�FØ�LŠL˜Ñ Ô Ð Ø�LŠL˜Ñ Ô Ð Ð ð ð 	%Ý”H˜VÑ$Ô$ˆ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à!ð 	&Ý'™MœMˆMˆMà%ˆMàˆ
Øˆ
ØˆÝ!Ô(¨¨D¸8ÈhÐWÑWÔWð 	Fð 	FˆDØ×-Ò-¨d¬n¸dÔ>NÑOÔOˆJØ×Ò˜zÑ*Ô*Ð*Ø×Ò˜dœfÑ%Ô%Ð%Ø×Ò˜dœfÑ%Ô%Ð%Ø Ð*Ð*Ø,0¬N×,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  € ð �yŠy‰{Œ{ˆØ�Š�d”oÑ&Ô&Ð&à04Ô0D×0JÒ0JØˆtŒx˜ñ1ô 1Ñ-ˆˆv�w ¨ð ð 	&Ý#™œˆIà!ð 	&Ý'™MœMˆMˆMà%ˆMàˆ
Øˆ
ØˆØˆà:@ð 	ð 	Ñ6ˆD�(˜E ;°°BØ×-Ò-¨d°KÑ@Ô@ˆJØ Ð*Ð*Ø—
’
‘”�Ø—’˜dœo¨t¬xÑ8Ô8Ð8Ø—’ µ9Ô3G�ÑHÔHÐHØ,0¯MªM©O¬O�˜jÑ)à×Ò˜bÑ!Ô!Ð!Ø×Ò˜bÑ!Ô!Ð!Ø×Ò˜zÑ*Ô*Ð*Ø˜dœoÑ-ˆDØ�LŠL˜ÑÔÐÐàˆØ!ð 	+ð 	+‰LˆB��A�qØ˜"�X  B¨¡F˜|¨b°1©f°b¸1±fÐ-=Ø˜1‘f˜b�\ B¨ 8¨Vð5ˆEå”[Ý”[¥$¤+­t¬{½D¼KÝ”^ð%ˆEð �NŠN˜E 5˜>Ñ*Ô*Ð*Ð*å•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Ø‰EˆDð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð ÐÝ#™œˆIà!ð 	&Ý'™MœMˆMˆMà%ˆMà57¸¸RÀ°^Ñ2ˆ�Z ¨Uð ”Ið 	;ñ 	;ˆDÝ˜DœI×2Ò2Ñ4Ô4Ñ5Ô5ˆDØŒyÔ ð UÝ)Ð*SÑTÔTÐTØ×-Ò-¨d°D´JÑ?Ô?ˆJØ Ð*Ð*Ø—
’
‘”�Ø—’˜dœo¨t¬xÑ8Ô8Ð8Ø—’ ¤
µ)Ô2H�ÑIÔIÐIØ,0¯MªM©O¬O�˜jÑ)à×Ò˜zÑ*Ô*Ð*Ø×Ò˜dœfÑ%Ô%Ð%Ø×Ò˜dœfÑ%Ô%Ð%Ø�LŠL˜œ¨$¬/Ñ9Ñ:Ô:Ð:Ñ:àˆà œJð 	+ð 	+‰LˆB��A�qØ˜"�X  Q¡¨˜|¨b°1©f°b¸1±fÐ-=Ø˜"˜q™&�\ B¨ 8¨Vð5ˆEå”[Ý”[¥$¤+­t¬{½D¼KÝ”^ð%ˆEð �NŠN˜E 5˜>Ñ*Ô*Ð*Ð*å•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>¸tÈdð >ð >ð >ð >ð >ð@ 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Ô&=Ñ=Ñ>Ô>Ü˜dœhð(ˆBð %'§L¢L°´Ñ$@Ô$@ˆDÔ!Ø49ˆDÔ!Ô'Ô1Ø!ˆDŒMˆMˆMð :Ð9r   )NNr�   F)r‰   rŠ   r‹   rŒ   r   r   r¤   Úpropertyr§   rT   r¦   Ú__classcell__)rŸ   s   @r   r�   r�     s³   ø€ € € € € ðð ð /3Ø05ð<&ð <&ð <&ð <&ð <&ð <&ð|ð ð ð
ð ð ð ð%ð %ñ „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   