Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions shared-module/lvfontio/OnDiskFont.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -535,9 +541,9 @@ 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,
bitmap_buffer,
false);
bits_per_value,
bitmap_buffer,
false);
self->bitmap = bitmap;
}

Expand Down
Loading