diff --git a/src/bolos/fonts_info.c b/src/bolos/fonts_info.c index 8af1f577..328fc6b2 100644 --- a/src/bolos/fonts_info.c +++ b/src/bolos/fonts_info.c @@ -94,6 +94,25 @@ static void parse_nbgl_font(nbgl_font_t *nbgl_font) } } +// Parse provided NBGL font and add bitmap/character pairs +static void parse_nbgl_font_12(nbgl_font_t_12 *nbgl_font) +{ + uint8_t *bitmap = nbgl_font->bitmap; + nbgl_font_character_t_12 *characters = nbgl_font->characters; + + for (uint32_t c = nbgl_font->first_char; c <= nbgl_font->last_char; + c++, characters++) { + // Be sure data is coherent + if (characters->bitmap_offset >= nbgl_font->bitmap_len) { + fprintf(stdout, "bitmap_offset (%d) is >= bitmap_len (%u)!\n", + characters->bitmap_offset, nbgl_font->bitmap_len); + return; + } + uint8_t *ptr = bitmap + characters->bitmap_offset; + add_bitmap_character(ptr, c); + } +} + // Parse provided BAGL font and add bitmap/character pairs static void parse_bagl_font(bagl_font_t *bagl_font, void *code, unsigned long text_load_addr) @@ -218,7 +237,15 @@ void parse_fonts(void *code, unsigned long text_load_addr, // Parse all those fonts and add bitmap/character pairs for (uint32_t i = 0; i < nb_fonts; i++) { if (hw_model == MODEL_STAX) { - parse_nbgl_font((void *)fonts[i]); + switch (sdk_version) { + case SDK_API_LEVEL_12: + case SDK_API_LEVEL_13: + parse_nbgl_font_12((void *)fonts[i]); + break; + default: + parse_nbgl_font((void *)fonts[i]); + break; + } } else { void *font = remap_addr(code, fonts[i], text_load_addr); diff --git a/src/fonts.h b/src/fonts.h index b7000588..797b85b1 100644 --- a/src/fonts.h +++ b/src/fonts.h @@ -81,7 +81,33 @@ typedef struct { // (They are defined in the SDK, in lib_nbgl/include/nbgl_fonts.h // ============================================================================ -// Current API_LEVEL (12) +// Current API_LEVEL (14) +typedef struct { + uint32_t encoding : 1; + uint32_t bitmap_offset : 14; + uint32_t width : 6; + uint32_t x_min_offset : 3; + uint32_t y_min_offset : 3; + uint32_t x_max_offset : 2; + uint32_t y_max_offset : 3; +} nbgl_font_character_t; + +typedef struct { + uint32_t bitmap_len; + uint8_t font_id; + uint8_t bpp; + uint8_t height; + uint8_t line_height; + uint8_t char_kerning; + uint8_t crop; + uint8_t y_min; + uint8_t first_char; + uint8_t last_char; + nbgl_font_character_t *characters; + uint8_t *bitmap; +} nbgl_font_t; + +// SDK_API_LEVEL_12 typedef struct { uint32_t encoding : 1; uint32_t bitmap_offset : 14; @@ -90,7 +116,7 @@ typedef struct { uint32_t y_min_offset : 3; uint32_t x_max_offset : 2; uint32_t y_max_offset : 3; -} nbgl_font_character_t; +} nbgl_font_character_t_12; typedef struct { uint32_t bitmap_len; @@ -102,9 +128,9 @@ typedef struct { uint8_t y_min; uint8_t first_char; uint8_t last_char; - nbgl_font_character_t *characters; + nbgl_font_character_t_12 *characters; uint8_t *bitmap; -} nbgl_font_t; +} nbgl_font_t_12; // ============================================================================