tests/pygame_font.py
changeset 56 282a07d20680
parent 55 1ab0edd5d784
child 57 911927edbdde
equal deleted inserted replaced
55:1ab0edd5d784 56:282a07d20680
     1 #!/usr/bin/env python3
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 import pygame
       
     5 
       
     6 pygame.init()
       
     7 
       
     8 font = pygame.font.SysFont('dejavusansmono', 14)
       
     9 
       
    10 print('Size: %s %s' % font.size('Q'))
       
    11 print('Linesize: %s' % font.get_linesize())
       
    12 print('Height: %s' % font.get_height())
       
    13 print('Ascent: %s' % font.get_ascent())
       
    14 print('Descent: %s' % font.get_descent())
       
    15 
       
    16 chars = '┌─┐└─┘│'
       
    17 metrics = font.metrics(chars)
       
    18 print('metrics=(minx, maxx, miny, maxy, advance)')
       
    19 
       
    20 for c, m in zip(chars, metrics):
       
    21     s = font.size(c)
       
    22     surface = font.render(c, False, (255,255,255), (0,0,0))
       
    23     ss = surface.get_size()
       
    24     ssg = None
       
    25     if hasattr(font, 'render_glyph'):
       
    26         surface_glyph = font.render_glyph(c, False, (255,255,255), (0,0,0))
       
    27         ssg = surface_glyph.get_size()
       
    28     print('%s metrics=%s size=%s surface_size=%s glyph_size=%s' % (c, m, s, ss, ssg))
       
    29