From 9347cf115a12cee9ad3bf9ed18d23ca5336ec0e9 Mon Sep 17 00:00:00 2001 From: cflip Date: Tue, 10 Jan 2023 14:14:30 -0700 Subject: Use PSF instead of BSF format for fonts This binary file format is much easier to parse. --- font.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'font.h') diff --git a/font.h b/font.h index 3a19cb1..4f82fca 100644 --- a/font.h +++ b/font.h @@ -3,23 +3,25 @@ #include +#define PSF_MAGIC_NUMBER 0x864ab572 + typedef struct { - int code_point; - SDL_Point next_glyph_offset; - SDL_Rect bounds; - char *bitmap; - int bitmap_size; -} BDFFontChar; +} PSFFontHeader; typedef struct { - SDL_Rect bounds; - BDFFontChar *chars; - int num_chars; - int char_index_for_code_point[128]; -} BDFFontInfo; + uint32_t magic; + uint32_t version; + uint32_t header_size; + uint32_t flags; + uint32_t num_glyphs; + uint32_t bytes_per_glyph; + uint32_t height; + uint32_t width; + uint8_t *glyph_data; +} PSFFont; -BDFFontInfo font_load(const char *); -SDL_Texture *font_create_texture(SDL_Renderer *, BDFFontInfo *); -void font_destroy(BDFFontInfo *); +PSFFont font_load(const char *); +SDL_Texture *font_create_texture(SDL_Renderer *, PSFFont *); +void font_destroy(PSFFont *); #endif -- cgit v1.2.3