From 31e5b187f9e285e91a3cc2d543a222038c634f32 Mon Sep 17 00:00:00 2001 From: Roy Date: Fri, 4 Dec 2026 12:07:01 +0800 Subject: [PATCH 1/2] lvfontio: pass bits per value, not the value count, to the bitmap The glyph cache bitmap was created with 1 << bits_per_pixel as its bits per value. That is the number of values, so 1, 2 and 4 bpp fonts used 2, 4 and 16 bits per pixel, and an 8 bpp font failed with "Invalid bits per value". Round the font's bpp up to a power of two instead. --- shared-module/lvfontio/OnDiskFont.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/shared-module/lvfontio/OnDiskFont.c b/shared-module/lvfontio/OnDiskFont.c index a93b8485b7f..f219f3b8b3d 100644 --- a/shared-module/lvfontio/OnDiskFont.c +++ b/shared-module/lvfontio/OnDiskFont.c @@ -515,10 +515,16 @@ void common_hal_lvfontio_ondiskfont_construct(lvfontio_ondiskfont_t *self, return; } + // The bitmap takes the number of bits per value, a power of two, not the + // number of values. Round the font's bpp (1, 2, 3, 4 or 8) up to it. + uint32_t bits_per_value = 1; + while (bits_per_value < self->header.bits_per_pixel) { + bits_per_value <<= 1; + } + // Calculate bitmap stride - uint32_t bits_per_pixel = 1 << self->header.bits_per_pixel; uint32_t width = self->header.default_advance_width * max_glyphs; - uint32_t row_width = width * bits_per_pixel; + uint32_t row_width = width * bits_per_value; uint16_t stride = (row_width + 31) / 32; // Align to uint32_t (32 bits) // Allocate buffer for bitmap data @@ -535,7 +541,7 @@ void common_hal_lvfontio_ondiskfont_construct(lvfontio_ondiskfont_t *self, common_hal_displayio_bitmap_construct_from_buffer(bitmap, self->header.default_advance_width * max_glyphs, self->header.font_size, - 1 << self->header.bits_per_pixel, + bits_per_value, bitmap_buffer, false); self->bitmap = bitmap; From 0b564ff600f32273f03e054af8b8986f613584a0 Mon Sep 17 00:00:00 2001 From: Roy Date: Fri, 4 Dec 2026 12:12:48 +0800 Subject: [PATCH 2/2] lvfontio: fix indentation of the bitmap construction call --- shared-module/lvfontio/OnDiskFont.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-module/lvfontio/OnDiskFont.c b/shared-module/lvfontio/OnDiskFont.c index f219f3b8b3d..7cebca04350 100644 --- a/shared-module/lvfontio/OnDiskFont.c +++ b/shared-module/lvfontio/OnDiskFont.c @@ -542,8 +542,8 @@ void common_hal_lvfontio_ondiskfont_construct(lvfontio_ondiskfont_t *self, self->header.default_advance_width * max_glyphs, self->header.font_size, bits_per_value, - bitmap_buffer, - false); + bitmap_buffer, + false); self->bitmap = bitmap; }