diff options
| author | KonAki <konaki@anokonaki.org> | 2026-10-08 17:23:50 +0800 |
|---|---|---|
| committer | KonAki <konaki@anokonaki.org> | 2026-10-08 17:23:50 +0800 |
| commit | 12c955cf1911edc3fbab9d675c14204058b4a134 (patch) | |
| tree | 5cba88af6812c89968519e02c81177e1f63dc380 /kon/konfont.h | |
| parent | f25fac99b90210cd10a77420ffa179b39be21a67 (diff) | |
Add resizable debug text with ctrl plus and minus
Diffstat (limited to 'kon/konfont.h')
| -rw-r--r-- | kon/konfont.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/kon/konfont.h b/kon/konfont.h index 822e1f3..a75c502 100644 --- a/kon/konfont.h +++ b/kon/konfont.h @@ -45,6 +45,10 @@ void kon_freeFont(kon_font_t *font); kon_image *kon_fontGetAtlas(kon_font_t *font); +/* the ttf data has to stay alive for as long as the font, resizing bakes from it again */ +float kon_fontPixelHeight(const kon_font_t *font); +int kon_fontResize(kon_font_t *font, float pixelHeight); + /*** text draw declarations ***/ void kon_drawText(kon_framebuffer_t *fb, kon_font_t *font, int x, int y, const char *text, uint32_t color); @@ -57,6 +61,7 @@ void kon_measureText(kon_font_t *font, const char *text, int *outWidth, int *out #include "stb_truetype.h" struct kon_font { + const uint8_t *ttf; stbtt_bakedchar chardata[KON_FONT_NUM_CHARS]; uint8_t *atlasPixels; int atlasSize; @@ -98,6 +103,7 @@ kon_font_t *kon_loadFont(const uint8_t *ttf_data, size_t size, float pixelHeight kon_font_t *font = malloc(sizeof(kon_font_t)); if (!font) return NULL; + font->ttf = ttf_data; font->atlasPixels = NULL; font->pixelHeight = pixelHeight; @@ -116,6 +122,25 @@ void kon_freeFont(kon_font_t *font) { free(font); } +float kon_fontPixelHeight(const kon_font_t *font) { + return font ? font->pixelHeight : 0.0f; +} + +int kon_fontResize(kon_font_t *font, float pixelHeight) { + kon_font_t next; + + if (!font || pixelHeight <= 0.0f) return 0; + + next = *font; + next.atlasPixels = NULL; + if (!kon_fontBakeAtlas(&next, font->ttf, pixelHeight)) return 0; + + free(font->atlasPixels); + next.pixelHeight = pixelHeight; + *font = next; + return 1; +} + kon_image *kon_fontGetAtlas(kon_font_t *font) { if (!font) return NULL; |
