tests/pygame_font.py
author Radek Brich <radek.brich@devl.cz>
Tue, 11 Oct 2011 10:09:58 +0200
changeset 26 37745c5abc49
parent 25 f69a1f0382ce
permissions -rwxr-xr-x
DriverPygame: add mouse events and key press autorepeat.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pygame

pygame.init()

font = pygame.font.SysFont('dejavusansmono', 14)

print('Size: %s %s' % font.size('Q'))
print('Linesize: %s' % font.get_linesize())
print('Height: %s' % font.get_height())
print('Ascent: %s' % font.get_ascent())
print('Descent: %s' % font.get_descent())

chars = '┌─┐└─┘│'
metrics = font.metrics(chars)
print('metrics=(minx, maxx, miny, maxy, advance)')

for c, m in zip(chars, metrics):
    s = font.size(c)
    surface = font.render(c, False, (255,255,255), (0,0,0))
    ss = surface.get_size()
    ssg = None
    if hasattr(font, 'render_glyph'):
        surface_glyph = font.render_glyph(c, False, (255,255,255), (0,0,0))
        ssg = surface_glyph.get_size()
    print('%s metrics=%s size=%s surface_size=%s glyph_size=%s' % (c, m, s, ss, ssg))