
    &h%                     h    S r SSKrSSKrSSKrSr " S S5      r\" 5       r\R                  " 5         g)a  pygame.examples.font_viewer
Scroll through your system fonts from a list of surfaces or one huge buffer.

This example exhibits:
* iterate over available fonts using font.get_fonts and font.SysFont()
* click and drag using mouse input
* scrolling with the scroll wheel
* save a surface to disk
* work with a very large surface
* simple mouse and keyboard scroll speed acceleration

By default this example uses the fonts returned by pygame.font.get_fonts()
and opens them using pygame.font.SysFont().
Alternatively, you may pass a path to the command line. The TTF files found
in that directory will be used instead.

Mouse Controls:
* Use the mouse wheel or click and drag to scroll

Keyboard Controls:
* Press up or down to scroll
* Press escape to exit
    NFc                   \    \ rS rSrSrSrSrS rS rSS jr	S r
S	 rSS
 jrSS jrS rSrg)
FontViewer!   z
This example is encapsulated by the fontviewer class
It initializes the pygame window, handles input, and draws itself
to the screen.

   2   c                 d   [         R                  " 5         [         R                  R                  5       nUR                  nUR
                  n[         R                  R                  [        US-  5      [        US-  5      45        US-  U l        [         R                  R                  5       U l        SU l        SU l        U R                  S5        [        (       d  S[         R"                  ;   a1  U R%                  5         U R'                  5         U R)                  5         g U R+                  5         g )Ng?   r   Fz&N abcDEF789big)pginitdisplayInfo	current_w	current_hset_modeint	font_sizetimeClockclocky_offsetgrabbedrender_fontsuse_big_surfacesysargvrender_surfacedisplay_surfacesave_pngdisplay_fonts)selfinfowhs       S/var/www/auris/envauris/lib/python3.13/site-packages/pygame/examples/font_viewer.py__init__FontViewer.__init__+   s    
	 zz NNNN


SS\3q3w<89bWW]]_
.)?esxx/!  "MMO     c                     Sn[        [        R                  5      S:  af  [        R                  R                  [        R                  S   5      (       a1  [        R                  R                  [        R                  S   S5      n[        R                  R                  U5      (       a@  [        R                  " U5       Vs/ s H  o"R                  S5      (       d  M  UPM     nnX14$ [        R                  R                  5       nX14$ s  snf )zd
Generate a font list using font.get_fonts() for system fonts or
from a path from the command line.
    z.ttf)lenr   r   ospathexistsjoinlistdirendswithr   font	get_fonts)r!   r.   r3   fontss       r%   get_font_listFontViewer.get_font_listA   s    
 sxx=1!<!<77<<R0D77>>$&(jj&6P&6d--:OT&6EP { GG%%'E{ Qs   DDc                 `   U R                   nSnSnSU l        U R                  5       u  pV/ nSnSn	U(       a  [        R                  R
                  O[        R                  R                  n
[        R                  R                  [        R                  R                  5       U5      nSSSSS	[        U5       S
3S4nU H]  nUR                  USX@R                  5      nUR                  X45        XR                  5       -  n[        XR                  5       5      n	M_     [        U5       H|  n U
" Xo-   U5      nUR!                  SU5      n UR                  USX0R                  5      n[        XR                  5       5      n	UR                  X45        XR                  5       -  nM~     Xl        Xl        Xpl        U[        R,                  R/                  5       R                  5       -
  U l        g! [         a     M  f = f! [        R"                   a  n[%        U5         SnA  M~  SnAff = f)z
Build a list that includes a surface and the running total of their
height for each font in the font list. Store the largest width and
other variables for later use.
)   r9   r9   )r9   r9   r   )r   r   r   r   z&Use the scroll wheel or click and dragzto scroll up and down.z'Fonts that don't use the Latin Alphabetzmight render incorrectly.zHere are your z fontsr*   r+   z&NN)r   
back_colorr6   r   r3   FontSysFontget_default_fontr,   renderappend
get_heightmax	get_widthsortedOSErrorreplaceerrorprinttotal_height	max_widthfont_surfacesr   get_surfacemax_y)r!   textr   colorinstruction_colorr5   r.   rJ   rH   rI   	load_fontr3   lineslinesurfnamees                    r%   r   FontViewer.render_fontsO   s    NN	)#((*	$(BGGLLbggoo	 wwrww7799E4$5'SZL/
 D;;tQ(9??KD  $!56OO--LI~~'78I	  5MD i8 <<d+D{{4E??C
 I~~'78I  $!56OO--L "" )"*!BJJ$:$:$<$G$G$II
#  
 88 as*   .G1H1
G?>G?H-H((H-c                    [         R                  R                  S5        [         R                  R                  5       n[         R                  R                  5       nUR                  5       S-  n UR                  U R                  5        U R                   H~  u  pEXTR                  5       -   nX`R                  :  d  M(  XPR                  UR                  5       -   ::  d  MJ  X4R                  5       S-  -
  nUR                  XGXPR                  -
  45        M     U R                  5       (       d  g[         R                  R                  5         UR                  S5        M  )zv
Display the visible fonts based on the y_offset value(updated in
handle_events) and the height of the pygame window.
zFont Viewer      N)r   r   set_captionrK   r   r   rB   fillr:   rJ   r@   r   blithandle_eventsfliptick)r!   r   r   centersurfacetopbottomxs           r%   r    FontViewer.display_fonts   s   
 	

}-**((*""$)LL) $ 2 21133mm+}}w/A/A/CCC!2!2!4!99ALLcMM.A*BC !3 %%''JJOOJJrN r(   c           	         [         R                  R                  U R                  U R                  45      R                  5       nUR                  U R                  5        [        S5        UR                  5       nX R                  U R                  -  -  n[        SR                  U R                  U R                  X#S-  5      5        Sn[        U R                  S-  5      nU R                   HK  u  pgUR                  5       nU[        US-  5      -
  n	UR                  XiU45        XFR                  5       -  nMM     UR                  5       [         R                   R#                  5       R                  5       -
  U l        Xl        g)a,  
Note: this method uses twice the memory and is only called if
big_surface is set to true or big is added to the command line.

Optionally generates one large buffer to draw all the font surfaces
into. This is necessary to save the display to a png file and may
be useful for testing large surfaces.
zscrolling surface createdz'Surface Size = {}x{} @ {}bpp: {:,.3f}mbg    .Ar   rX   N)r   ra   SurfacerI   rH   convertr[   r:   rG   get_bytesizeformatr   rJ   rB   r\   r@   r   rK   rL   )
r!   large_surface	byte_size
total_sizeyr`   ra   rb   r#   rd   s
             r%   r   FontViewer.render_surface   sE    

**^^T../

') 	 	4??+)* "..0	..43D3D"DE
5<< 1 199>T	
 T^^a'( ..LG!!#AQU#AwA/##%%A	 /
 #--/"**2H2H2J2U2U2WW
$r(   c           
         [         R                  R                  5       n[         R                  R	                  SSU R
                  R                  5       [        U R
                  R                  5       UR                  5       5      5      n[        UR                  5       U R
                  R                  5       -
  S-  5      nSnU(       a  U R                  5       (       d  SnUR                  U R                  5        U R                  Ul        UR                  U R
                  US4U5        [         R                  R!                  5         U R"                  R%                  S5        U(       a  M  gg)z
Display the large surface created by the render_surface method. Scrolls
based on the y_offset value(set in handle_events) and the height of the
pygame window.
r   rX   TFr	   N)r   r   rK   rectRectra   rB   minr@   r   r]   r[   r:   r   rb   r\   r^   r   r_   )r!   r   screenrq   rd   goings         r%   r   FontViewer.display_surface   s     '')
 ww||LL""$'')6+<+<+>?	
 !!#dll&<&<&>>!CD%%''KK(}}DHKKq!fd3JJOOJJOOB er(   c                     [         R                  R                  U R                  U5        [        R
                  R                  U5      S-  n[        SU SUS S35        g )Ni   zfont surface saved to z
size: ,Kb)r   imagesavera   r-   r.   getsizerG   )r!   rT   	file_sizes      r%   r   FontViewer.save_png   sI    
dllD)GGOOD)T1	&tfHYqMDEr(   c                    [         R                  R                  5       nU GH@  nUR                  [         R                  :X  a    gUR                  [         R
                  :X  a"  UR                  [         R                  :X  a    gMd  UR                  [         R                  :X  a1  U =R                  UR                  U R                  -  S-  -  sl	        M  UR                  [         R                  :X  a(  SU l        [         R                  R                  S5        M  UR                  [         R                  :X  d  GM  SU l        [         R                  R                  S5        GMC     [         R                  R!                  5       nU[         R"                     (       aN  U =R$                  S-  sl        U =R                  ['        U R(                  U R$                  S-  -  5      -  sl	        OmU[         R*                     (       aN  U =R$                  S-  sl        U =R                  ['        U R(                  U R$                  S-  -  5      -  sl	        OSU l        [         R,                  R/                  5       S   nU(       a&  U R                  (       a  U =R                  U-  sl	        [1        [3        U R                  S5      U R4                  45      U l	        g)z
This method handles user input. It returns False when it receives
a pygame.QUIT event or the user presses escape. The y_offset is
changed based on mouse and keyboard input. display_fonts() and
display_surface() use the y_offset to scroll display.
FTr+   r   r	   r   )r   eventgettypeQUITKEYDOWNkeyK_ESCAPE
MOUSEWHEELr   rn   MOUSE_SCROLL_SPEEDMOUSEBUTTONDOWNr   set_grabMOUSEBUTTONUPget_pressedK_UPkey_heldr   KEY_SCROLL_SPEEDK_DOWNmouseget_relrs   rA   rL   )r!   eventsrU   keysrn   s        r%   r]   FontViewer.handle_events   s    Avv 2::%55BKK'  (2==(t'>'>!>!CC2---#!!$'2+++$!!%( $ vv!!#=MMQMMMS!6!6$--2:M!NOOM"))_MMQMMMS!6!6$--2:M!NOOMDM HHq!MMQMS2DJJ?@r(   )r:   r   r   rJ   r   r   rI   rL   ra   rH   r   N)zA display of font &N)r   )zfont_viewer.png)__name__
__module____qualname____firstlineno____doc__r   r   r&   r6   r   r    r   r   r   r]   __static_attributes__ r(   r%   r   r   !   sA     !,7Jr6!%F :F
*r(   r   )	r   r   r-   pygamer   r   r   viewerquitr   r(   r%   <module>r      s9   .  	 q qh 
 	r(   