
    \
j<                        d Z ddlZddlT ddlmZ  e eeg d                    Z e ee e e	dd                     e e	dd	                    z                       Z
d
 ZdZdZd Zd Zd Zd Zd Zd Z G d dej                  Z G d dej                  Z G d d          Z G d de          Z G d d          ZdS )a  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.
    N)*)image)i	  i	  i  iW  i  i  i  i  i  i>  iW  i  i        i  i  i@  E  i  i  c                     |dv p| t           v S )N)MeMn_other_grapheme_extendcccs     J/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/font/base.py<lambda>r   5   s    |!3!Rq<R7R     
c                 V    |dv o%| t          t          t          g d                    vS )N)ZIZpCcCf)   
   r   r   )listmapchrr   s     r   r   r   9   s5    77 :c#77788	9	99 r   c                 n    t          | |          p%| t          t          t          g d                    v S )N)i0  i2  i3  r   i  i  i  )_grapheme_extendr   r   r   r   s     r   r   r   ;   s;    (B// Kc#HHHII	J	JJ r   c                     | t           v S N)_logical_order_exceptionr   s     r   r   r   =   s    66 r   c                      |dk    o| t           vS )NMcr   r   s     r   r   r   >   s    bDjLQ6L-L r   c                 B   | dS | t           k    r|t          k    rdS t          j        |           }t	          | |          rdS t          j        |          }t	          ||          rdS t          ||          rdS t          ||          rdS t          | |          rdS dS )NTF)_CR_LFunicodedatacategory_control_extend_spacing_mark_prepend)leftrightleft_ccright_ccs       r   _grapheme_breakr3   A   s    |t
 s{{u||u"4((G g t#E**H x   t
 uh u UH%% u g u 4r   c                     g }d}d}| D ]J}|r(t          ||          r|                    |           d}n|r|                    d           ||z  }|}K|r|                    |           |S )a2  Implements Table 2 of UAX #29: Grapheme Cluster Boundaries.

    Does not currently implement Hangul syllable rules.
    
    :Parameters:
        `text` : unicode
            String to cluster.

    .. versionadded:: 1.1.2

    :rtype: List of `unicode`
    :return: List of Unicode grapheme clusters
     Nu   ​)r3   append)textclustersclusterr/   r0   s        r   get_grapheme_clustersr:   j   s     HGD   	'tU33 	'OOG$$$GG 	'OOI&&&5  !   Or   c                   @    e Zd ZdZdZdZdZdZdZd
dZ	d Z
d Zd Zd	S )Glyphaj  A single glyph located within a larger texture.

    Glyphs are drawn most efficiently using the higher level APIs, for example
    `GlyphString`.

    :Ivariables:
        `advance` : int
            The horizontal advance of this glyph, in pixels.
        `vertices` : (int, int, int, int)
            The vertices of this glyph, with (0,0) originating at the
            left-side bearing at the baseline.
        `colored` : bool
            If a glyph is colored by the font renderer, such as an emoji, it may
            be treated differently by pyglet. For example, being omitted from text color shaders.

    r   )r   r   r   r   Fc                     || _         || _        || _        ||z   | |z   || j        z   |z   | | j        z   |z   f| _        dS )an  Set metrics for this glyph.

        :Parameters:
            `baseline` : int
                Distance from the bottom of the glyph to its baseline;
                typically negative.
            `left_side_bearing` : int
                Distance to add to the left edge of the glyph.
            `advance` : int
                Distance to move the horizontal advance to the next glyph.
            `offset_x` : int
                Distance to move the glyph horizontally from it's default position.
            `offset_y` : int
                Distance to move the glyph vertically from it's default position.
        N)baselinelsbadvancewidthheightvertices)selfr>   left_side_bearingr@   x_offsety_offsets         r   set_bearingszGlyph.set_bearings   sZ      !$ (I 
*X5I#h.	0r   c                     t          t          | j        j                   t	          t
                     |                                  t                       dS )z^Debug method.
        
        Use the higher level APIs for performance and kerning.
        N)glBindTextureGL_TEXTURE_2DowneridglBeginGL_QUADSdraw_quad_verticesglEndrD   s    r   drawz
Glyph.draw   sE    
 	mTZ]333!!!r   c                    t          | j        dd           t          | j        d         | j        d                    t          | j        dd           t          | j        d         | j        d                    t          | j        dd           t          | j        d         | j        d                    t          | j        dd           t          | j        d         | j        d                    dS )	zWDebug method. 

        Use the higher level APIs for performance and kerning.
        N   r            	      )glTexCoord3f
tex_coords
glVertex2frC   rR   s    r   rP   zGlyph.draw_quad_vertices   s    
 	dobqb)**4=#T]1%5666doac*++4=#T]1%5666doac*++4=#T]1%5666doad+,,4=#T]1%566666r   c                     dS )zNot implemented.
        r    )rD   right_glyphs     r   get_kerning_pairzGlyph.get_kerning_pair   s	     qr   N)r   r   )__name__
__module____qualname____doc__r>   r?   r@   rC   coloredrH   rS   rP   ra   r_   r   r   r<   r<      sz           H
CGHG0 0 0 04  7 7 7    r   r<   c                   .    e Zd ZdZeZdZdZdZd Z	d Z
dS )GlyphTextureAtlasz0A texture within which glyphs can be drawn.
    r   c                 b    t          t          t                     t          t                     dS )zCSet the OpenGL blend state for the glyphs in this texture.
        N)glBlendFuncGL_SRC_ALPHAGL_ONE_MINUS_SRC_ALPHAglEnableGL_BLENDrR   s    r   apply_blend_statez#GlyphTextureAtlas.apply_blend_state   s)     	L"8999r   c                    |j         | j         k    s|j        | j        k    rdS | j        |j         z   | j         k    r&d| _        | xj        | j        dz   z  c_        d| _        | j        |j        z   | j        k    rdS t          | j        |j                  | _        |                     | j        | j        |j         |j                  }|j         dk    r0|                    |ddd           | xj        |j         dz   z  c_        |S )a3  Place `image` within this texture.

        :Parameters:
            `image` : `pyglet.image.AbstractImage`
                Image to place within the texture.

        :rtype: `Glyph`
        :return: The glyph representing the image from this texture, or None
            if the image doesn't fit.
        Nr   rV   )rA   rB   xyline_heightmax
get_region	blit_into)rD   r   regions      r   fitzGlyphTextureAtlas.fit   s     ;##u|dk'A'A46EK$*,,DFFFd&**FF D6EL 4;..4t/>>FDFEK7 7;??UAq!,,,FFekAo%FFr   N)rb   rc   rd   re   r<   region_classrq   rr   rs   ro   rx   r_   r   r   rh   rh      sP         L	A	AK      r   rh   c                       e Zd ZdZd Zd ZdS )GlyphRendererz.Abstract class for creating glyph images.
    c                     d S r"   r_   )rD   fonts     r   __init__zGlyphRenderer.__init__	  s    r   c                      t          d          )NzSubclass must overrideNotImplementedError)rD   r7   s     r   renderzGlyphRenderer.render  s    !":;;;r   N)rb   rc   rd   re   r~   r   r_   r   r   r{   r{     s<           < < < < <r   r{   c                       e Zd ZdZdS )FontExceptionzkGeneric exception related to errors from the font module.  Typically
    these relate to invalid font data.N)rb   rc   rd   re   r_   r   r   r   r     s        * *Dr   r   c                       e Zd ZdZdZdZeZeZ	eZ
dZdZeZeZd Zed             Zed             Zed             Zd Zd	 Zd
 Zd ZdS )Fonta  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.

    :Ivariables:
        `ascent` : int
            Maximum ascent above the baseline, in pixels.
        `descent` : int
            Maximum descent below the baseline, in pixels. Usually negative.
       r   c                 "    g | _         i | _        d S r"   )texturesglyphsrR   s    r   r~   zFont.__init__2  s    r   c                     t           )z/Return the Family Name of the font as a string.r   rR   s    r   namez	Font.name6  s
     "!r   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_   )clsdatas     r   add_font_datazFont.add_font_data;  s	     	r   c                     dS )zDetermine if a font with the given name is installed.

        :Parameters:
            `name` : str
                Name of a font to search for

        :rtype: bool
        Tr_   )r   r   s     r   	have_fontzFont.have_fontI  s	     tr   c                 X   d}|                      |           | j        D ]}|                    |          }|r n|sm| j                            t
          | j        | j        | j        | j	        | j
                  }| j                            d|           |                    |          }|S )a@  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
        `Font`.  This method inserts the image into a font texture and returns
        a glyph reference; it is up to the subclass to add metadata to the
        glyph.

        Applications should not use this method directly.

        :Parameters:
            `image` : `pyglet.image.AbstractImage`
                The image to write to the font texture.

        :rtype: `Glyph`
        Nr   )_adapt_texture_sizer   rx   texture_classcreate_for_sizerK   texture_widthtexture_heighttexture_internalformattexture_min_filtertexture_mag_filterinsert)rD   r   glyphtextures       r   create_glyphzFont.create_glyphU  s    "   '''} 	 	GKK&&E  	'(889=9K9=9L9=9T9=9P9=9PR RG M  G,,,KK&&Er   c                     |j         | j        k    s|j        | j        k    r-t	          |j         |j                  }|dz  x| _        | _        d S d S )N   )rA   r   rB   r   rt   )rD   r   largest_dimensions      r   r   zFont._adapt_texture_sizew  sY    ;+++u|d>Q/Q/Q #EK > >7H17LLD$"4"4"4 0R/Qr   c                    d}g }t          t          |                    D ]g}|dk    rd}|| j        vr4|s|                     |           }|                    |          | j        |<   |                    | j        |                    h|S )a)  Create 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.

        :Parameters:
            `text` : str or unicode
                Text to render.

        :rtype: list of `Glyph`
        N	 )r:   strr   glyph_renderer_classr   r6   )rD   r7   glyph_rendererr   r   s        r   
get_glyphszFont.get_glyphs|  s     &s4yy11 		* 		*A Dyy##% E%)%>%>t%D%DN!/!6!6q!9!9AMM$+a.))))r   c                 ~   d}g }g }|D ]}|dk    r||z  } n|| j         vr4|s|                     |           }|                    |          | j         |<   | j         |         }|                    |           ||j        z  }|dk    rt          |          dk    r 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.

        :Parameters:
            `text` : str or unicode
                Text to render.
            `width` : int
                Maximum width of returned glyphs.
        
        :rtype: list of `Glyph`

        :see: `GlyphString`
        Nr   r   u    ​)r   r   r   r6   r@   len)rD   r7   rA   r   glyph_bufferr   r   r   s           r   get_glyphs_for_widthzFont.get_glyphs_for_width  s   2  	" 	"ADyy,& ##% E%)%>%>t%D%DN!/!6!6q!9!9AKNE &&&U]"E zzc&kkAoo O##,&! v;;!!Fr   N)rb   rc   rd   re   r   r   GL_ALPHAr   	GL_LINEARr   r   ascentdescentr{   r   rh   r   r~   propertyr   classmethodr   r   r   r   r   r   r_   r   r   r   r     s          MN%"" FG(%M   " " X"   [ 	 	 [	     DM M M
  49 9 9 9 9r   r   )re   r)   	pyglet.glpygletr   r   r   r   r   ranger#   r    r'   r(   r+   r,   r.   r-   r3   r:   TextureRegionr<   Texturerh   r{   	Exceptionr   r   r_   r   r   <module>r      s  H               cc# (@ (@ (@ A A B B   4CeeE5.A.A)B)BTT%%PUW\J]J]E^E^)^ _ _`` RR : :K K66LL& & &R  BL L L L LE L L L^) ) ) ) ) ) ) )X< < < < < < < <	 	 	 	 	I 	 	 	y y y y y y y y y yr   