
    ^jF                    P   d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZmZmZ d d	D             Zd
  edd          D             d  edd          D             z  Zd dD             ZdZdZddhZh dZdhZd3dZd4d"Ze G d# d$                      Z G d% d&ej                  Z G d' d(ej                  Z  G d) d*ej!        j"                  Z# G d+ d,ej!        j$                  Z% G d- d.ej&                  Z' G d/ d0e(          Z) G d1 d2          Z*dS )5a  Abstract classes used by pyglet.font implementations.

These classes should not be constructed directly.  Instead, use the functions
in `pyglet.font` to obtain platform-specific instances.  You can use these
classes as a documented interface to the concrete classes.
    )annotationsN)	dataclass)AnyBinaryIOClassVar)image)	GL_LINEARGL_RGBAGL_TEXTURE_2Dc                ,    h | ]}t          |          S  chr.0xs     K/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/font/base.py	<setcomp>r      s+       CFF      )i	  i	  i  iW  i  i  i  i  i  i>  iW  i  i  i   i   i  i  c                ,    h | ]}t          |          S r   r   r   s     r   r   r      s    @@@qCFF@@@r   i@  E  c                ,    h | ]}t          |          S r   r   r   s     r   r   r      s    ChChChqCFFChChChr   i  i  c                ,    h | ]}t          |          S r   r   r   s     r   r   r      s    SSSAQSSSr   )i0  i2  i3  r   i  i  i  
MeMn>   CcCfZIZpMcleftstrleft_ccrightright_ccreturnboolc                    | dS | t           k    r|t          k    rdS |t          v r| t          vrdS |t          v r|t          vrdS |t          v s	|t
          v rdS |dk    r|t          vrdS | t          v rdS dS )z9Determines if there should be a break between characters.NTFr"   )_CR_LF_CATEGORY_CONTROL_OTHER_GRAPHEME_EXTEND_CATEGORY_EXTEND_EXTEND_CHARS_LOGICAL_ORDER_EXCEPTION)r#   r%   r&   r'   s       r   grapheme_breakr2   "   s     |t
 s{{u||u ###4J(J(Jt $$$6L)L)Lt
 ###u'='=u 4E)???u '''u 4r   text	list[str]c                n   g }g }d}d}| D ]}t          j        |          }|rNt          ||||          r<|                    d                    |                     |                                 |                    |           |}|}|r(|                    d                    |                     |S )zImplements Table 2 of UAX #29: Grapheme Cluster Boundaries.

    Does not currently implement Hangul syllable rules.

    Args:
        text: unicode
            String to cluster.

    Returns:
         List of Unicode grapheme clusters.
    N )unicodedatacategoryr2   appendjoinclear)r3   clusterscluster_charsr#   r%   r&   r'   s          r   get_grapheme_clustersr>   H   s     HMDG 	 	'.. 	"^D'5(KK 	"OOBGGM22333!!!U### 0..///Or   c                  @    e Zd ZU dZdZded<   ded<   ded<   ded<   dS )	GlyphPositionz Positioning offsets for a glyph.)	x_advancex_offset	y_advancey_offsetintrA   rC   rB   rD   N)__name__
__module____qualname____doc__	__slots____annotations__r   r   r   r@   r@   k   s?         **BINNNNNNMMMMMMMMr   r@   c                  X    e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   d
Z	ddZ
dS )GlyphzxA single glyph located within a larger texture.

    Glyphs are drawn most efficiently using the higher level APIs.
    r   rE   baselinelsbadvancer   r   r   r   ztuple[int, int, int, int]verticesFleft_side_bearingr(   Nonec                j    || _         || _        || _        || || j        z   | | j        z   f| _        dS )am  Set metrics for this glyph.

        Args:
            baseline:
                Distance from the bottom of the glyph to its baseline. Typically negative.
            left_side_bearing:
                Distance to add to the left edge of the glyph.
            advance:
                Distance to move the horizontal advance to the next glyph, in pixels.
        N)rN   rO   rP   widthheightrR   )selfrN   rS   rP   s       r   set_bearingszGlyph.set_bearings   sF     !$ I
*I#	%r   N)rN   rE   rS   rE   rP   rE   r(   rT   )rF   rG   rH   rI   rN   rK   rO   rP   rR   coloredrY   r   r   r   rM   rM   u   s           HCLLLLG +7H6666 G% % % % % %r   rM   c                      e Zd ZdZeZdS )GlyphTexturezA texture containing a glyph.N)rF   rG   rH   rI   rM   region_classr   r   r   r\   r\      s        ''LLLr   r\   c                  B     e Zd ZdZeZddeeefd fdZdd fdZ	 xZ
S )GlyphTextureAtlasz'A texture atlas containing many glyphs.i   rV   rE   rW   fmt
min_filter
mag_filterr(   rT   c           	         t                                          ||           | j                            ||t          ||||          | _        t          j                            ||          | _	        d S )N)r`   )
super__init__texture_classcreater   texturer   atlas	Allocator	allocator)rX   rV   rW   r`   ra   rb   	__class__s         r   re   zGlyphTextureAtlas.__init__   sd    ''')00sT^`jps0tt..uf==r   r   imgimage.AbstractImageborderrM   c                H    t                                          ||          S N)rd   add)rX   rm   ro   rl   s      r   rr   zGlyphTextureAtlas.add   s    ww{{3'''r   )rV   rE   rW   rE   r`   rE   ra   rE   rb   rE   r(   rT   )r   )rm   rn   ro   rE   r(   rM   )rF   rG   rH   rI   r\   rf   r
   r	   re   rr   __classcell__)rl   s   @r   r_   r_      s}        11 M$(dm#,> > > > > > >( ( ( ( ( ( ( ( ( ( (r   r_   c                  $    e Zd ZdZeeedfddZdS )GlyphTextureBinz@Same as a TextureBin but allows you to specify filter of Glyphs.r   rm   rn   r`   rE   ra   rb   ro   r(   rM   c                   t          | j                  D ]d}	 |                    ||          c S # t          j        j        $ r3 |j        dk     r%|j        dk     r| j                            |           Y aw xY wt          | j
        | j        |||          }| j                            |           |                    ||          S )N@   )listatlasesrr   r   ri   AllocatorExceptionrV   rW   remover_   texture_widthtexture_heightr9   )rX   rm   r`   ra   rb   ro   ri   s          r   rr   zGlyphTextureBin.add   s    $,'' 	/ 	/E/yyf-----;1 / / / 9r>>cj2ooL''...	/ "$"4d6I3PZ\fggE"""yyf%%%s   0AA76A7N)rm   rn   r`   rE   ra   rE   rb   rE   ro   rE   r(   rM   )rF   rG   rH   rI   r
   r	   rr   r   r   r   ru   ru      s>        JJ7>R['q& & & & & & &r   ru   c                  ^    e Zd ZdZej        dd            Zej        dd
            ZddZdS )GlyphRendererz)Abstract class for creating glyph images.fontFontr(   rT   c                    || _         dS )zInitialize the glyph renderer.

        Args:
            font: The :py:class:`~pyglet.font.base.Font` object to be rendered.
        N)r   rX   r   s     r   re   zGlyphRenderer.__init__   s     			r   r3   r$   rM   c                    dS )zRender the string of text into an image.

        Args:
            text: The initial string to be rendered, typically one character.

        Returns:
             A Glyph with the proper metrics for that specific character.
        Nr   rX   r3   s     r   renderzGlyphRenderer.render         r   c           	         t          j        dddt          g d                    }| j                            |          }|                    | j        j         dd           |S )zZero glyph is a 1x1 image that has a -1 advance.

        This is to fill in for potential substitutions since font system requires 1 glyph per character in a string.
           RGBArQ   r   )r   	ImageDatabytesr   create_glyphrY   descent)rX   
image_dataglyphs      r   create_zero_glyphzGlyphRenderer.create_zero_glyph   s_    
 _Q653F3FGG
	&&z22DI--q"555r   Nr   r   r(   rT   )r3   r$   r(   rM   )r(   rM   )	rF   rG   rH   rI   abcabstractmethodre   r   r   r   r   r   r   r      st        33    	        r   r   c                      e Zd ZdZdS )FontExceptionz]Generic exception related to errors from the font module.  Typically, from invalid font data.N)rF   rG   rH   rI   r   r   r   r   r      s        ggggr   r   c                     e Zd ZU dZded<   dZded<   dZded<   dZded	<   d
Zded<   e	Z
ded<   eZded<   eZded<   dZded<   dZded<   eZded<   eZded<   ded<   ded<   ded<   ded<   ded<   dBd!ZdBd"ZdCd$ZdCd%Zeej        dDd'                        ZedEd,            ZedFd/            ZdGdHd6ZdId9Z dJd<Z!ej        dKd=            Z"dLd@Z#dDdAZ$d0S )Mr   aP  Abstract font class able to produce glyphs.

    To construct a font, use :py:func:`pyglet.font.load`, which will instantiate the
    platform-specific font class.

    Internally, this class is used by the platform classes to manage the set
    of textures into which glyphs are written.

    Attributes:
        texture_width:
            Default Texture width to use if ``optimize_glyph`` is False.
        texture_height:
            Default Texture height to use if ``optimize_glyph`` is False.
        optimize_fit:
            Determines max texture size by the ``glyph_fit`` attribute. If False, ``texture_width`` and
            ``texture_height`` are used.
        glyph_fit:
            Standard keyboard characters amount to around ~100 alphanumeric characters. This value is used to
             pre-calculate how many glyphs can be saved into a single texture atlas. Increase this if you plan to
             support more than this standard scenario. Performance is increased the less textures are used. However,
             it does consume more video memory.
        texture_internalformat:
            Determines how textures are stored in internal format. By default, ``GL_RGBA``.
        texture_min_filter:
            The default minification filter for glyph textures. By default, ``GL_LINEAR``. Can be changed to
            ``GL_NEAREST`` to prevent aliasing with pixelated fonts.
        texture_mag_filter:
            The default magnification filter for glyph textures. By default, ``GL_LINEAR``. Can be changed to
            ``GL_NEAREST`` to prevent aliasing with pixelated fonts.
    z(dict[str | int | tuple[Any, int], Glyph]glyphsi   rE   r|   r}   Toptimize_fitd   	glyph_fittexture_internalformattexture_min_filtertexture_mag_filterr   ascentr   zClassVar[type[GlyphRenderer]]glyph_renderer_classzClassVar[type[GlyphTextureBin]]rf   z
list[Font]	fallbackszGlyphRenderer | None_glyph_rendererzGlyph | None_missing_glyph_zero_glyphfloat
pixel_sizer(   rT   c                h    d| _         d| _        d| _        d| _        d| _        i | _        g | _        dS )z/Initialize a font that can be used with Pyglet.N)texture_binhb_resourcer   r   r   r   r   rX   s    r   re   zFont.__init__+  s@     # #  r   c                    | j         sY|                     |           | _         | j                             d          | _        | j                                         | _        dS dS )zInitialize the glyph renderer and cache it on the Font.

        This way renderers for fonts that have been loaded but not used will not have unnecessary loaders.
         N)r   r   r   r   r   r   r   s    r   _initialize_rendererzFont._initialize_renderer9  sh    
 # 	H#'#<#<T#B#BD "&"6"="=c"B"BD#3EEGGD	H 	Hr   r   c                `    || j         vs
J d            | j                             |           d S )NzFont is already added.)r   r9   r   s     r   add_fallbackzFont.add_fallbackC  s:    4>)))+C)))d#####r   c                `    || j         vs
J d            | j                             |           d S )NzFont has not been added.)r   r{   r   s     r   remove_fallbackzFont.remove_fallbackG  s:    4>)))+E)))d#####r   r$   c                    dS )z/Return the Family Name of the font as a string.Nr   r   s    r   namez	Font.nameK  r   r   cls
type[Font]datar   c                    dS )a  Add font data to the font loader.

        This is a class method and affects all fonts loaded.  Data must be
        some byte string of data, for example, the contents of a TrueType font
        file.  Subclasses can override this method to add the font data into
        the font registry.

        There is no way to instantiate a font given the data directly, you
        must use :py:func:`pyglet.font.load` specifying the font name.
        Nr   )r   r   s     r   add_font_datazFont.add_font_dataP  r   r   r   r)   c                    dS )zDetermine if a font with the given name is installed.

        Args:
            name:
                Name of a font to search for.
        Tr   )r   r   s     r   	have_fontzFont.have_font]  s	     tr   Nrm   rn   r`   
int | NonerM   c                    | j         H| j        r"|                     |          \  | _        | _        t          | j        | j                  | _         | j                             ||p| j        | j        | j	        d          S )a4  Create a glyph using the given image.

        This is used internally by `Font` subclasses to add glyph data
        to the font.  Glyphs are packed within large textures maintained by the
        `Font` instance.  This method inserts the image into a texture atlas managed by the font.

        Applications should not use this method directly.

        Args:
            img:
                The image to write to the font texture.
            fmt:
                Override for the format and internalformat of the atlas texture. None will use default.
        Nr   )ro   )
r   r   _get_optimal_atlas_sizer|   r}   ru   rr   r   r   r   )rX   rm   r`   s      r   r   zFont.create_glyphg  s     #  \:>:V:VWZ:[:[7"D$7.t/A4CVWWD##33T5LdNeno $ q q 	qr   r   tuple[int, int]c                    | j         | j        }}d}d}|s]||j        dz   z
  |j        dz   z  dz   ||j        dz   z
  |j        dz   z  dz   z  }|| j        k    r||f}|dz  r|dz  }n|dz  }|dz  }|]|S )z[Retrieves the optimal atlas size to fit ``image_data`` with ``glyph_fit`` number of glyphs.Nr      r   )r|   r}   rV   rW   r   )rX   r   awah
atlas_sizeifits          r   r   zFont._get_optimal_atlas_size~  s     #T%8B-1
  	**Q./Z5E5IJQN:,q01z7H17LMPQQSC dn$$ "X
1u aaFA  	 r   r3   'tuple[list[Glyph], list[GlyphPosition]]c           	     h   d}g }g }t          t          |                    D ]}|dk    rd}|| j        vr4|s|                     |           }|                    |          | j        |<   |                    | j        |                    |                    t          dddd                     ||fS )zCreate and return a list of Glyphs for `text`.

        If any characters do not have a known glyph representation in this
        font, a substitution will be made.

        Args:
            text:
                Text to render.
        N	r   r   )r>   r$   r   r   r   r9   r@   )rX   r3   glyph_rendererr   offsetscs         r   
get_glyphszFont.get_glyphs  s     &s4yy11 
	6 
	6A Dyy##% E%)%>%>t%D%DN!/!6!6q!9!9AMM$+a.)))NN=Aq!445555wr   c                    dS )zReturn's an estimated width and height of text using glyph metrics without rendering..

        This does not take into account any shaping.
        Nr   r   s     r   get_text_sizezFont.get_text_size  r   r   rV   list[Glyph]c                   d}g }g }|D ]}|dk    r||z  } n|| j         vr4|s|                     |           }|                    |          | j         |<   | j         |         }|                    |           ||j        z  }|dcxk    rt          |          k     rn n n|dv r||z  }g }t          |          dk    r|}|S )a  Return a list of glyphs for ``text`` that fit within the given width.

        If the entire text is larger than 'width', as much as possible will be
        used while breaking after a space or zero-width space character.  If a
        newline is encountered in text, only text up to that newline will be
        used.  If no break opportunities (newlines or spaces) occur within
        `width`, the text up to the first break opportunity will be used (this
        will exceed `width`).  If there are no break opportunities, the entire
        text will be used.

        You can assume that each character of the text is represented by
        exactly one glyph; so the amount of text "used up" can be determined
        by examining the length of the returned glyph list.

        Args:
            text:
                Text to render.
            width:
                Maximum width of returned glyphs.
        Nr   r   u    ​)r   r   r   r9   rP   len)rX   r3   rV   r   glyph_bufferr   r   r   s           r   get_glyphs_for_widthzFont.get_glyphs_for_width  s   *  	" 	"ADyy,& ##% E%)%>%>t%D%DN!/!6!6q!9!9AKNE &&&U]"E ''''CKK''''' N"",&! v;;!!Fr   c                0    | j         j         d| j         dS )Nz('z'))rl   rF   r   r   s    r   __repr__zFont.__repr__  s     .)::TY::::r   )r(   rT   r   )r(   r$   )r   r   r   r   r(   rT   )r   r   r   r$   r(   r)   rq   )rm   rn   r`   r   r(   rM   )r   rn   r(   r   )r3   r$   r(   r   )r3   r$   r(   r   )r3   r$   rV   rE   r(   r   )%rF   rG   rH   rI   rK   r|   r}   r   r   r
   r   r	   r   r   r   r   r   r   ru   rf   re   r   r   r   propertyr   r   r   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r      s         > 5444 MNLI")))))'''''''''' FOOOOG ;HGGGG 6EMDDDD ))))        H H H H$ $ $ $$ $ $ $ > > >  X> 
 
 
 [
    [q q q q q.   4   8 	   5 5 5 5n; ; ; ; ; ;r   r   )
r#   r$   r%   r$   r&   r$   r'   r$   r(   r)   )r3   r$   r(   r4   )+rI   
__future__r   r   r7   dataclassesr   typingr   r   r   pygletr   	pyglet.glr	   r
   r   r.   ranger1   r0   r+   r,   r/   r-   _CATEGORY_SPACING_MARKr2   r>   r@   TextureRegionrM   Texturer\   ri   TextureAtlasr_   
TextureBinru   ABCr   	Exceptionr   r   r   r   r   <module>r      s    # " " " " " 



     ! ! ! ! ! ! * * * * * * * * * *       7 7 7 7 7 7 7 7 7 7 -   
 A@EE%,?,?@@@ChChTYTYZ_afTgTgChChChh SS!RSSS$< ,,,  # # # #L   F        "% "% "% "% "%E "% "% "%J    5=   
( ( ( ( (0 ( ( (& & & & &ek, & & &&    CG   Bh h h h hI h h hN; N; N; N; N; N; N; N; N; N;r   