py-sdl / py-sdl2

Python ctypes wrapper around SDL2
Other
296 stars 49 forks source link

Rewrite and re-document the BitmapFont class #208

Closed a-hurst closed 2 years ago

a-hurst commented 2 years ago

PR Description

This PR rewrites and re-documents the sdl.ext.BitmapFont class, fixing a wide range of bugs and API unpleasantness. The main new additions are the render_text method, which renders text to an SDL surface (converted to ARGB8888 format by default) and supports custom line heights, and a :meth:remap method for customizing the surface-to-character mappings and fine-tuning character sizes (e.g. making the "i" character narrower than the "o" character).

Additionally, this PR deprecates the render method as it returns a SoftwareSprite instead of a regular SDL_Surface (now replaced by render_text), as well as the can_render method which is no longer useful (render_text and render_on already throw an informative exception on a missing character).

Merge Checklist