Test for PySDL2's BitmapFont.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To use this script, save the image from the page below as '7sled.png'. | |
# http://imgur.com/C2OLhYj | |
# The script should create a file 'test_bmp_font.bmp' that looks like this: | |
# http://imgur.com/WFJNRTT | |
import atexit | |
import sdl2 | |
import sdl2.ext | |
sdl2.ext.init() | |
atexit.register(sdl2.ext.quit) | |
ffile = b"7sled.png" | |
fwidth = 70 | |
fheight = 100 | |
surf = sdl2.sdlimage.IMG_Load(ffile).contents | |
bmpfont = sdl2.ext.BitmapFont(surf, (fwidth, fheight), ["01234-", "56789:"]) | |
s = "01 23 45\n --::-- " | |
assert bmpfont.can_render(s) | |
surf = bmpfont.render(s).surface | |
s = ": :" | |
assert bmpfont.can_render(s) | |
bmpfont.render_on(surf, s, (fwidth * 2, 0)) | |
sdl2.SDL_SaveBMP(surf, b"test_bmp_font.bmp") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment