Skip to content

Commit 6fb35df

Browse files
authored
Merge pull request #789 from pimoroni/feature/picographics-custom-fonts
PicoGraphics: Add MicroPython support for custom font data.
2 parents d523ede + b0d63ef commit 6fb35df

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

micropython/modules/picographics/picographics.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct _ModPicoGraphics_obj_t {
3737
DisplayDriver *display;
3838
void *spritedata;
3939
void *buffer;
40+
void *fontdata;
4041
_PimoroniI2C_obj_t *i2c;
4142
//mp_obj_t scanline_callback; // Not really feasible in MicroPython
4243
} ModPicoGraphics_obj_t;
@@ -520,7 +521,16 @@ mp_obj_t ModPicoGraphics_sprite(size_t n_args, const mp_obj_t *args) {
520521

521522
mp_obj_t ModPicoGraphics_set_font(mp_obj_t self_in, mp_obj_t font) {
522523
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
523-
self->graphics->set_font(mp_obj_to_string_r(font));
524+
525+
if (mp_obj_is_str(font)) {
526+
self->graphics->set_font(mp_obj_to_string_r(font));
527+
}
528+
else {
529+
mp_buffer_info_t bufinfo;
530+
mp_get_buffer_raise(font, &bufinfo, MP_BUFFER_READ);
531+
self->fontdata = bufinfo.buf;
532+
self->graphics->set_font(((bitmap::font_t *)self->fontdata));
533+
}
524534
return mp_const_none;
525535
}
526536

0 commit comments

Comments
 (0)