
    ^j^P                       d 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 ddlmZmZmZmZ ddlZdd	lmZmZmZ er(dd
lmZmZmZ ddlmZmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$  G d de%          Z& G d d          Z'ed         Z( G d de)e          Z*d/d0dZ+	 	 d1d2d Z,d/d3d$Z-d4d%Z.d5d'Z/ G d( d)ej0                  Z1 G d* d+e1          Z2 G d, d-e1          Z3g d.Z4dS )6ar  Text formatting, layout and display.

This module provides classes for loading styled documents from text files,
HTML files and a pyglet-specific markup format.  Documents can be styled with
multiple fonts, colours, styles, text sizes, margins, paragraph alignments,
and so on.

Using the layout classes, documents can be laid out on a single line or
word-wrapped to fit a rectangle.  A layout can then be efficiently drawn in
a window or updated incrementally (for example, to support interactive text
editing).

The label classes provide a simple interface for the common case where an
application simply needs to display some text in a window.

A plain text label can be created with::

    label = pyglet.text.Label('Hello, world',
                              font_name='Times New Roman',
                              font_size=36,
                              x=10, y=10)

Alternatively, a styled text label using HTML can be created with::

    label = pyglet.text.HTMLLabel('<b>Hello</b>, <i>world</i>',
                                  x=10, y=10)

Either label can then be drawn at any time with::

    label.draw()

For details on the subset of HTML supported, see `pyglet.text.formats.html`.

Refer to the Programming Guide for advanced usage of the document and layout
classes, including interactive editing, embedding objects within documents and
creating scrollable layouts.
    )annotations)abstractmethod)Enum)dirname)splitext)TYPE_CHECKINGAnyBinaryIOLiteralN)caretdocumentlayout)AnchorXAnchorYHorizontalAlign)BatchGroup)ShaderProgram)Location)AbstractDocumentFormattedDocumentUnformattedDocumentc                      e Zd ZdZdS )DocumentDecodeExceptionz)An error occurred decoding document text.N)__name__
__module____qualname____doc__     O/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/text/__init__.pyr   r   ;   s        3333r    r   c                  ,    e Zd ZdZed
dd	            ZdS )DocumentDecoderzAbstract document decoder.NtextstrlocationLocation | Nonereturnr   c                    dS )a  Decode document text.

        Args:
            text:
                Text to decode
            location:
                Location to use as base path for additional resources referenced within the document (for example,
                HTML images).
        Nr   )selfr$   r&   s      r!   decodezDocumentDecoder.decodeB   s      r    N)r$   r%   r&   r'   r(   r   )r   r   r   r   r   r+   r   r    r!   r#   r#   ?   s=        $$	 	 	 	 ^	 	 	r    r#   )
text/plain	text/htmltext/vnd.pyglet-attributedc                  B    e Zd ZdZdZdZdZdZ	 dZdZ	dZ
	 d	Zd
ZddZdS )WeightaY  An :py:class:`~enum.Enum` of known cross-platform font weight strings.

    Each value is both an :py:class:`~enum.Enum` and a :py:class:`str`.
    This is not a built-in Python :py:class:`~enum.StrEnum` to ensure
    compatibility with Python < 3.11.

    .. important:: Fonts will use the closest match if they lack a weight!

    The values of this enum imitate the string names for font weights
    as used in CSS and the OpenType specification. Numerical font weights
    are not supported because:

    * Integer font weight support and behavior varies by back-end
    * Some font renderers do not support or round :py:class:`float` values
    * Some font renderers lack support for variable-width fonts

    Additional weight strings may be supported by certain font-rendering
    back-ends. To learn more, please see your platform's API documentation
    and the following:

    #. `The MDN article on CSS font weights <https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight>`_
    #. `The OpenType specification <https://learn.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass>`_

    thin
extralightlightnormalmediumsemiboldbold	extrabold	ultraboldr(   r%   c                    | j         S r,   )valuer*   s    r!   __str__zWeight.__str__x   s
    zr    Nr(   r%   )r   r   r   r   THIN
EXTRALIGHTLIGHTNORMALMEDIUMSEMIBOLDBOLD	EXTRABOLD	ULTRABOLDr>   r   r    r!   r1   r1   R   sg         2 DJEF(FHD0II     r    r1   filename
str | NonemimetypeSupportedMimeTypes | Noner(   c                J   |-t          |           \  }}|                                dv rd}nd}|dk    rddlm} |                                S |dk    rddlm} |                                S |dk    rdd	lm} |                                S d
| d}t          |          )a  Get a document decoder for the given filename and MIME type.

    If ``mimetype`` is omitted it is guessed from the filename extension.

    The following MIME types are supported:

    ``text/plain``
        Plain text
    ``text/html``
        HTML 4 Transitional
    ``text/vnd.pyglet-attributed``
        Attributed text; see `pyglet.text.formats.attributed`

    Args:
        filename:
            Filename to guess the MIME type from.  If a MIME type is given, the filename is ignored.
        mimetype:
            MIME type to lookup, or ``None`` to guess the type from the filename.

    Raises:
        DocumentDecodeException: If MIME type is not from the supported types.
    N)z.htmz.htmlz.xhtmlr.   r-   r   )	plaintext)htmlr/   )
attributedzUnknown format "")
	_splitextlowerpyglet.text.formatsrN   PlainTextDecoderrO   HTMLDecoderrP   AttributedTextDecoderr   )rI   rK   _extrN   rO   rP   msgs           r!   get_decoderr[   |   s    . 8$$399;;555"HH#H<111111))+++;,,,,,,!!!///222222//111
(X
(
(
(C
!#
&
&&r    r%   fileBinaryIO | Noner   c                   t          | |          }|s<t          |           5 }|                                }ddd           n# 1 swxY w Y   n(|                                }|                                 t	          |d          r|                                }t          j                            t          |                     }|                    ||          S )a  Load a document from a file.

    Args:
        filename:
            Filename of document to load.
        file:
            File object containing encoded data.  If omitted, ``filename`` is
            loaded from disk.
        mimetype:
            MIME type of the document.  If omitted, the filename extension is
            used to guess a MIME type.  See `get_decoder` for a list of
            supported MIME types.
    Nr+   )
r[   openreadclosehasattrr+   pygletresourceFileLocation_dirname)rI   r\   rK   decoderffile_contentsr&   s          r!   loadrj      s      (H--G (^^ 	%qFFHHM	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 		

}h'' /%,,..++HX,>,>??H>>-222s   AA
Ar$   r&   r   c                N    t          dd          }|                    | |          S )zCreate a document directly from some HTML formatted text.

    Args:
        text:
            HTML data to decode.
        location:
            Location giving the base path for additional resources referenced from the document (e.g., images).
    Nr.   r[   r+   )r$   r&   rg   s      r!   decode_htmlrm      s'     $,,G>>$)))r    c                L    t          dd          }|                    |           S )zCreate a document directly from some attributed text.

    See `pyglet.text.formats.attributed` for a description of attributed text.
    Nr/   rl   r$   rg   s     r!   decode_attributedrp      s&    
 $ <==G>>$r    r   c                L    t          dd          }|                    |           S )z0Create a document directly from some plain text.Nr-   rl   ro   s     r!   decode_textrr      s#    $--G>>$r    c                      e Zd ZdZ	 	 	 	 	 	 	 dCdD fd"ZedEd$            Zej        dFd&            ZedGd(            Zej        dHd*            ZedId,            Z	e	j        dJd.            Z	edKd0            Z
e
j        dLd2            Z
edMd3            Zej        dNd5            ZedEd6            Zej        dOd8            ZedPd:            Zej        dQd<            ZdRd?ZdSdAZdTdBZ xZS )UDocumentLabelz~Base label class.

    A label is a layout that exposes convenience methods for manipulating the
    associated document.
            NleftbaselineFTr   r   xfloatyzwidth
int | Noneheightanchor_xr   anchor_yr   rotation	multilinebooldpibatchBatch | NonegroupGroup | NoneprogramShaderProgram | Noneinit_documentr(   Nonec                h    t                                          |||||||||	|
|||||           dS )a   Create a label for a given document.

        Args:
            document: Document to attach to the layout.
            x: X coordinate of the label.
            y: Y coordinate of the label.
            z: Z coordinate of the label.
            width: Width of the label in pixels, or ``None``
            height:  Height of the label in pixels, or ``None``
            anchor_x:
                Anchor point of the X coordinate: one of
                ``"left"``, `"center"`` or ``"right"``.
            anchor_y:
                Anchor point of the Y coordinate: one of
                ``"bottom"``, ``"baseline"``, ``"center"`` or ``"top"``.
            rotation:
                The amount to rotate the label in degrees. A
                positive amount will be a clockwise rotation, negative
                values will result in counter-clockwise rotation.
            multiline:
                If ``True``, the label will be word-wrapped and
                accept newline characters. You must also set the width
                of the label.
            dpi: Resolution of the fonts in this layout. Defaults to 96.
            batch: Optional graphics batch to add the label to.
            group: Optional graphics group to use.
            program: Optional graphics shader to use. Will affect all glyphs.
            init_document:
                If ``True``, the document will be initialized. If you
                are passing an already-initialized document, then you can
                avoid duplicating work by setting this to ``False``.
        r   N)super__init__)r*   r   rx   rz   r{   r|   r~   r   r   r   r   r   r   r   r   r   	__class__s                   r!   r   zDocumentLabel.__init__   sU    T 	1aE68Xx"Cwm 	 	] 	] 	] 	] 	]r    r%   c                    | j         j        S )zThe text of the label.r   r$   r=   s    r!   r$   zDocumentLabel.text  s     }!!r    r$   c                    || j         _        d S r,   r   r*   r$   s     r!   r$   zDocumentLabel.text  s    !r    tuple[int, int, int, int]c                6    | j                             d          S )z\Text color.

        Color is a 4-tuple of RGBA components, each in range [0, 255].
        colorr   	get_styler=   s    r!   r   zDocumentLabel.color   s     }&&w///r    r   c                    |^}}}}||||r|d         ndf}| j                             dt          | j         j                  d|i           d S )Nr      r   r   	set_stylelenr$   )r*   r   rgbas         r!   r   zDocumentLabel.color(  s\    1a!1a+1+3t}'9#:#:We<LMMMMMr    intc                    | j         d         S )av  Blend opacity.

        This property sets the alpha component of the colour of the label's
        vertices.  With the default blend mode, this allows the layout to be
        drawn with fractional opacity, blending with the background.

        An opacity of 255 (the default) has no effect.  An opacity of 128 will
        make the label appear semi-translucent.
           )r   r=   s    r!   opacityzDocumentLabel.opacity.  s     z!}r    alphac           	         || j         d         k    r;t          t          t          g | j         d d         |R                     | _         d S d S )Nr   )r   listmapr   )r*   r   s     r!   r   zDocumentLabel.opacity;  sP    DJqM!!c#'?BQB'?'?'?@@AADJJJ "!r    str | list[str]c                6    | j                             d          S )zFont family name.

        The font name, as passed to :py:func:`pyglet.font.load`.  A list of names can
        optionally be given: the first matching font will be used.
        	font_namer   r=   s    r!   r   zDocumentLabel.font_name@  s     }&&{333r    r   c                p    | j                             dt          | j         j                  d|i           d S )Nr   r   r   )r*   r   s     r!   r   zDocumentLabel.font_nameI  4    3t}'9#:#:[)<TUUUUUr    c                6    | j                             d          S )zFont size, in points.	font_sizer   r=   s    r!   r   zDocumentLabel.font_sizeM  s     }&&{333r    r   c                p    | j                             dt          | j         j                  d|i           d S )Nr   r   r   )r*   r   s     r!   r   zDocumentLabel.font_sizeR  r   r    c                6    | j                             d          S )zThe font weight (boldness or thickness), as a string.

        See the :py:class:`~Weight` enum for valid cross-platform
        string values.
        weightr   r=   s    r!   r   zDocumentLabel.weightV  s     }&&x000r    r   c                    | j                             dt          | j         j                  dt	          |          i           d S )Nr   r   )r   r   r   r$   r%   )r*   r   s     r!   r   zDocumentLabel.weight_  s:    3t}'9#:#:Xs6{{<STTTTTr    
bool | strc                6    | j                             d          S )zItalic font style.italicr   r=   s    r!   r   zDocumentLabel.italicc  s     }&&x000r    r   c                p    | j                             dt          | j         j                  d|i           d S )Nr   r   r   )r*   r   s     r!   r   zDocumentLabel.italich  s4    3t}'9#:#:Xv<NOOOOOr    namer	   c                h    | j                             |dt          | j         j                            S )a;  Get a document style value by name.

        If the document has more than one value of the named style,
        `pyglet.text.document.STYLE_INDETERMINATE` is returned.

        Args:
            name:
                Style name to query.  See documentation from `pyglet.text.layout` for known style names.
        r   )r   get_style_ranger   r$   )r*   r   s     r!   r   zDocumentLabel.get_stylel  s+     },,T1c$-:L6M6MNNNr    r<   c                p    | j                             dt          | j         j                  ||i           dS )a  Set a document style value by name over the whole document.

        Args:
            name:
                Name of the style to set.  See documentation for
                `pyglet.text.layout` for known style names.
            value:
                Value of the style.
        r   Nr   )r*   r   r<   s      r!   r   zDocumentLabel.set_stylex  s5     	3t}'9#:#:T5MJJJJJr    c                .    |                                   d S r,   )deleter=   s    r!   __del__zDocumentLabel.__del__  s    r    )ru   ru   ru   NNrv   rw   ru   FNNNNT) r   r   rx   ry   rz   ry   r{   ry   r|   r}   r~   r}   r   r   r   r   r   ry   r   r   r   r}   r   r   r   r   r   r   r   r   r(   r   r?   r$   r%   r(   r   )r(   r   )r   r   r(   r   )r(   r   )r   r   r(   r   )r(   r   )r   r   r(   r   )r(   ry   )r   ry   r(   r   )r   r%   r(   r   )r(   r   )r   r   r(   r   )r   r%   r(   r	   )r   r%   r<   r	   r(   r   )r(   r   )r   r   r   r   r   propertyr$   setterr   r   r   r   r   r   r   r   r   __classcell__r   s   @r!   rt   rt      s         8;;?Z]7;>B,0"&+] +] +] +] +] +] +]Z " " " X" 
[" " " [" 0 0 0 X0 \N N N \N
 
 
 
 X
 ^B B B ^B 4 4 4 X4 V V V V 4 4 4 X4 V V V V 1 1 1 X1 ]U U U ]U 1 1 1 X1 ]P P P ]P
O 
O 
O 
O
K 
K 
K 
K       r    rt   c                  <     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 d0d1 fd/Z xZS )2LabelzPlain text label. ru   Nrv   rw   Fr5   r   r   r   r   r$   r%   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   str | list[str] | Noner   float | Noner   r   r   stretchr   0tuple[int, int, int, int] | tuple[int, int, int]alignr   r   r   r   r   r   r   r(   r   c                (   t          |          }|^}}}}||||r|d         ndf}t                                          |||||||||	|
||||d           | j                            dt          | j        j                  |||||||d           dS )a	  Create a plain text label.

        Args:
            text:
                Text to display.
            x:
                X coordinate of the label.
            y:
                Y coordinate of the label.
            z:
                Z coordinate of the label.
            width:
                Width of the label in pixels, or None
            height:
                Height of the label in pixels, or None
            anchor_x:
                Anchor point of the X coordinate: one of ``"left"``,
                ``"center"`` or ``"right"``.
            anchor_y:
                Anchor point of the Y coordinate: one of ``"bottom"``,
                ``"baseline"``, ``"center"`` or ``"top"``.
            rotation:
                The amount to rotate the label in degrees. A positive amount
                will be a clockwise rotation, negative values will result in
                counter-clockwise rotation.
            multiline:
                If True, the label will be word-wrapped and accept newline
                characters.  You must also set the width of the label.
            dpi:
                Resolution of the fonts in this layout.  Defaults to 96.
            font_name:
                Font family name(s).  If more than one name is given, the
                first matching name is used. A list of names can optionally
                be given: the first matching font will be used.
            font_size:
                Font size, in points.
            weight:
                The 'weight' of the font (boldness). See the :py:class:`~Weight`
                enum for valid cross-platform weight names.
            italic:
                Italic font style.
            stretch:
                 Stretch font style.
            color:
                Font color as RGBA or RGB components, each within
                ``0 <= component <= 255``.
            align:
                Horizontal alignment of text on a line, only applies if
                a width is supplied. One of ``"left"``, ``"center"``
                or ``"right"``.
            batch:
                Optional graphics batch to add the label to.
            group:
                Optional graphics group to use.
            program:
                Optional graphics shader to use. Will affect all glyphs.
        r   r   Fr   )r   r   r   r   r   r   r   N)rr   r   r   r   r   r   r$   )r*   r$   rx   rz   r{   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   docr   r   r   r   rgbar   s                               r!   r   zLabel.__init__  s    L $1a!!Q*!s*aAufh("Cwe 	 	U 	U 	U 	3t}'9#:#:""=
 =
 	 	 	 	 	r    )r   ru   ru   ru   NNrv   rw   ru   FNNNr5   FFr   rv   NNN),r$   r%   rx   ry   rz   ry   r{   ry   r|   r}   r~   r}   r   r   r   r   r   ry   r   r   r   r}   r   r   r   r   r   r%   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r   )r   r   r   r   r   r   r   s   @r!   r   r     sv         !7:;?Z]7;PTV[FZ%+>B,0U U U U U U U U U U Ur    r   c                  n     e Zd ZdZ	 	 	 	 	 	 	 d'd( fd$Zed)d%            Zej        d*d&            Z xZS )+	HTMLLabelzyHTML formatted text label.

    A subset of HTML 4.01 is supported.  See `pyglet.text.formats.html` for
    details.
    r   ru   Nrv   rw   Fr$   r%   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r&   r'   r   r   r   r   r   r   r(   r   c                    || _         || _        t          ||          }t                                          |||||||||	|
||||d           dS )aB  Create a label with an HTML string.

        Args:
            text:
                Text to display.
            x:
                X coordinate of the label.
            y:
                Y coordinate of the label.
            z:
                Z coordinate of the label.
            width:
                Width of the label in pixels, or None
            height:
                Height of the label in pixels, or None
            anchor_x:
                Anchor point of the X coordinate: one of ``"left"``,
                ``"center"`` or ``"right"``.
            anchor_y:
                Anchor point of the Y coordinate: one of ``"bottom"``,
                ``"baseline"``, ``"center"`` or ``"top"``.
            rotation:
                The amount to rotate the label in degrees. A positive amount
                will be a clockwise rotation, negative values will result in
                counter-clockwise rotation.
            multiline:
                If True, the label will be word-wrapped and accept newline
                characters.  You must also set the width of the label.
            dpi:
                Resolution of the fonts in this layout.  Defaults to 96.
            location:
                Location object for loading images referred to in the document.
                By default, the working directory is used.
            batch:
                Optional graphics batch to add the label to.
            group:
                Optional graphics group to use.
            program:
                Optional graphics shader to use. Will affect all glyphs.

        Tr   N)_text	_locationrm   r   r   )r*   r$   rx   rz   r{   r|   r~   r   r   r   r   r   r&   r   r   r   r   r   s                    r!   r   zHTMLLabel.__init__  sr    ` 
!$))aAufh("Cwd 	 	T 	T 	T 	T 	Tr    c                    | j         S )z!HTML formatted text of the label.)r   r=   s    r!   r$   zHTMLLabel.text   s     zr    c                H    || _         t          || j                  | _        d S r,   )r   rm   r   r   r   s     r!   r$   zHTMLLabel.text%  s     
#D$.99r    )r   ru   ru   ru   NNrv   rw   ru   FNNNNN) r$   r%   rx   ry   rz   ry   r{   ry   r|   r}   r~   r}   r   r   r   r   r   ry   r   r   r   r   r&   r'   r   r   r   r   r   r   r(   r   r?   r   )	r   r   r   r   r   r   r$   r   r   r   s   @r!   r   r     s          $&pt_b>B-1CG154T 4T 4T 4T 4T 4T 4Tl    X 
[: : : [: : : : :r    r   )r   r#   SupportedMimeTypesr[   rj   rm   rp   rr   rt   r   r   r   r   r,   )rI   rJ   rK   rL   r(   r#   )NN)rI   r%   r\   r]   rK   rL   r(   r   )r$   r%   r&   rJ   r(   r   )r$   r%   r(   r   )r$   r%   r(   r   )5r   
__future__r   abcr   enumr   os.pathr   rf   r   rR   typingr   r	   r
   r   rc   pyglet.textr   r   r   pyglet.customtypesr   r   r   pyglet.graphicsr   r   pyglet.graphics.shaderr   pyglet.resourcer   pyglet.text.documentr   r   r   	Exceptionr   r#   r   r%   r1   r[   rj   rm   rp   rr   
TextLayoutrt   r   r   __all__r   r    r!   <module>r      s  $ $J # " " " " "             ' ' ' ' ' ' ) ) ) ) ) ) 8 8 8 8 8 8 8 8 8 8 8 8  / / / / / / / / / /  ^DDDDDDDDDD,,,,,,,,444444((((((]]]]]]]]]]4 4 4 4 4i 4 4 4         TU ' ' ' ' 'S$ ' ' 'T)' )' )' )' )'Z "&/33 3 3 3 3>
* 
* 
* 
* 
*              b b b b bF% b b bJX X X X XM X X XvE: E: E: E: E: E: E: E:P  r    