Ë
    íÍ:j¥1  ã                   óä   — 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    úh/home/mcse/projects/srt_converter/srt-converter-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Ñ5°dÓ;ˆ	Ü˜	Ó"ˆØ�‰�d—o‘o t§x¡xÔ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Ÿ?™?Ñ*ˆáØ—9‘9“;ˆDØ�M‰M˜$Ÿ/™/Ô*à×$Ñ$×*Ñ*¨1¨b°$Ó7ð 'ˆE�6˜7 Qà˜5‘= &¨5¡.°'¸E±/ÐAÐAà�~‰~˜dÓ#ˆØ�‰�a˜¤I×$8Ñ$8ˆÔ9Ø×$Ñ$Ó&‰ˆˆ1Ø	ˆT‰	ˆØ	ˆT‰	ˆØ×ÑÓˆØ	ˆT‰	ˆØ�5‰y˜!˜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Š?Ø+/×+>Ñ+>¸tÀQÓ+GÑ(ˆJ˜	¡5ÙØ—>‘> $Ó'ˆDØ+/×+DÑ+DØ�a (°Xð ,Eó ,?Ñ(ˆJ˜	¡5ð ,0×+CÑ+CÀDÈ!Ó+LÑ(ˆJ˜	 5à˜2ˆuˆØ7Aò 	!Ñ3ˆJ˜	 9¨eØ& zÑ2‰NˆF�FØ�L‰L˜ %™¨9°iÐ*@Ñ@ÔAØ�L‰L˜Õ ð	!ð $ò 	!‰NˆF�FØ�L‰L˜Ô Ø�L‰L˜Õ ð	!ñ Ü—H‘H˜VÓ$ˆ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á!Ü'›M‰Mà%ˆMàˆ
Øˆ
ØˆÜ!×(Ñ(¨¨D¸8ÈhÔWò 	FˆDØ×-Ñ-¨d¯n©n¸d×>NÑ>NÓOˆJØ×Ñ˜zÔ*Ø×Ñ˜dŸf™fÔ%Ø×Ñ˜dŸf™fÔ%Ø Ò*Ø,0¯N©N×,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õ  € ð �y‰y‹{ˆØ�‰�d—o‘oÔ&à04×0DÑ0D×0JÑ0JØˆt�x‰x˜ó1Ñ-ˆˆv�w ¨ñ Ü#›ˆIá!Ü'›M‰Mà%ˆMàˆ
Øˆ
ØˆØˆà:@ò 	Ñ6ˆD�(˜E ;°°BØ×-Ñ-¨d°KÓ@ˆJØ Ñ*Ø—
‘
”Ø—‘˜dŸo™o¨t¯x©xÔ8Ø—‘ ´9×3GÑ3G�ÔHØ,0¯M©M«O�˜jÑ)à×Ñ˜bÔ!Ø×Ñ˜bÔ!Ø×Ñ˜zÔ*Ø˜dŸo™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¹KÜ—^‘^ð%ˆEð �N‰N˜E 5˜>Õ*ð	+ô ”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Ø‰EˆD÷	ð ÐÜ#›ˆIá!Ü'›M‰Mà%ˆMà57¸¸RÀ°^Ñ2ˆ�Z ¨Uð —I‘Ió 	;ˆDÜ˜DŸI™I×2Ñ2Ó4Ó5ˆDØ�y‰y× Ò Ü)Ð*SÓTÐTØ×-Ñ-¨d°D·J±JÓ?ˆJØ Ñ*Ø—
‘
”Ø—‘˜dŸo™o¨t¯x©xÔ8Ø—‘ §
¡
´)×2HÑ2H�ÔIØ,0¯M©M«O�˜jÑ)à×Ñ˜zÔ*Ø×Ñ˜dŸf™fÔ%Ø×Ñ˜dŸf™fÔ%Ø�L‰L˜Ÿ™¨$¯/©/Ñ9Ö:ð	;ð  ˆà ŸJ™Jò 	+‰LˆB��A�qØ˜"�X  Q¡¨˜|¨b°1©f°b¸1±fÐ-=Ø˜"˜q™&�\ B¨ 8¨Vð5ˆEä—[‘[Ü—[‘[¤$§+¡+¬t¯{©{¼D¿K¹KÜ—^‘^ð%ˆEð �N‰N˜E 5˜>Õ*ð	+ô ”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>¸tÈdô >ð@ 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   € à�z‰zÐ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×&=Ñ&=Ñ=Ó>ß‘9˜dŸh™hð(ˆBð %'§L¡L°·±Ó$@ˆDÔ!Ø49ˆD×!Ñ!×'Ñ'Ô1Ø!ˆD�Mð :r   )NNé   F)r‰   rŠ   r‹   rŒ   r   r   r£   Úpropertyr¦   rT   r¥   Ú__classcell__)rž   s   @r   r�   r�     sM   ø„ ñð /3Ø05õ<&ò|ò
ð ñ%ó ð%ð ñó ðö"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   