Skip to content

Commit

Permalink
Remove language dependency from NBGL
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Aug 21, 2024
1 parent fddeb90 commit 285b5bf
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 124 deletions.
11 changes: 8 additions & 3 deletions lib_nbgl/include/nbgl_fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ extern "C" {
* INCLUDES
*********************/
#include "nbgl_types.h"
#ifdef HAVE_LANGUAGE_PACK
#include "ux_loc_nbgl.h"
#endif // HAVE_LANGUAGE_PACK

/*********************
* DEFINES
*********************/
#define PIC_CHAR(x) ((const nbgl_font_character_t *) PIC(x))
#define PIC_BMP(x) ((uint8_t const *) PIC(x))

#ifndef HAVE_LANGUAGE_PACK
#define LANGUAGE_PACK void
#endif // HAVE_LANGUAGE_PACK

/**
* @brief fonts nicknames to be used for various wallet size targets (non-Nano)
*
Expand Down Expand Up @@ -212,9 +219,7 @@ uint32_t nbgl_popUnicodeChar(const uint8_t **text, uint16_t *text_length, bool *
nbgl_unicode_ctx_t *nbgl_getUnicodeFont(nbgl_font_id_e font_id);
const nbgl_font_unicode_character_t *nbgl_getUnicodeFontCharacter(uint32_t unicode);
uint32_t nbgl_getUnicodeFontCharacterByteCount(void);
#ifdef HAVE_LANGUAGE_PACK
void nbgl_refreshUnicodeFont(void);
#endif
void nbgl_refreshUnicodeFont(const LANGUAGE_PACK *lp);
#endif // HAVE_UNICODE_SUPPORT

/**********************
Expand Down
24 changes: 8 additions & 16 deletions lib_nbgl/include/nbgl_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,14 @@ typedef char *(*onTextDrawCallback_t)(uint8_t token);
*
*/
typedef struct PACKED__ nbgl_button_s {
nbgl_obj_t obj; ///< common part
color_t innerColor; ///< color set inside of the button
color_t borderColor; ///< color set to button's border
color_t foregroundColor; ///< color set to '1' bits in icon, and text. '0' are set to
///< innerColor color.
nbgl_radius_t radius; ///< radius of the corners, must be a multiple of 4.
nbgl_font_id_e fontId; ///< id of the font to use, if any
bool localized; ///< if set to true, means the following 'text' field is considered as a
const char *text; ///< single line UTF-8 text (NULL terminated)
#ifdef HAVE_LANGUAGE_PACK
UX_LOC_STRINGS_INDEX textId; ///< id of the text single line UTF-8 text
#endif // HAVE_LANGUAGE_PACK
nbgl_obj_t obj; ///< common part
color_t innerColor; ///< color set inside of the button
color_t borderColor; ///< color set to button's border
color_t foregroundColor; ///< color set to '1' bits in icon, and text. '0' are set to
///< innerColor color.
nbgl_radius_t radius; ///< radius of the corners, must be a multiple of 4.
nbgl_font_id_e fontId; ///< id of the font to use, if any
const char *text; ///< single line UTF-8 text (NULL terminated)
onTextDrawCallback_t onDrawCallback; ///< function called if not NULL, with above token as
///< parameter to get the text of the button
uint8_t token; ///< token to use as param of onDrawCallback
Expand All @@ -421,17 +417,13 @@ typedef struct PACKED__ nbgl_text_area_s {
nbgl_aligment_t textAlignment; ///< alignment of text within the area
nbgl_style_t style; ///< to define the style of border
nbgl_font_id_e fontId; ///< id of the font to use
bool localized; ///< if set to true, use textId instead of text
bool autoHideLongLine; ///< if set to true, replace beginning of line by ... to keep it single
///< line
bool wrapping; ///< if set to true, break lines on ' ' when possible
uint8_t nbMaxLines; ///< if >0, replace end (3 last chars) of line (nbMaxLines-1) by "..." and
///< stop display here
const char *text; ///< ASCII text to draw (NULL terminated). Can be NULL.
uint16_t len; ///< number of bytes to write (if 0, max number of chars or strlen is used)
#ifdef HAVE_LANGUAGE_PACK
UX_LOC_STRINGS_INDEX textId; ///< id of the UTF-8 text
#endif // HAVE_LANGUAGE_PACK
onTextDrawCallback_t
onDrawCallback; ///< function called if not NULL to get the text of the text area
uint8_t token; ///< token to use as param of onDrawCallback
Expand Down
14 changes: 7 additions & 7 deletions lib_nbgl/src/nbgl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,10 @@ nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area,
{
// text is a series of characters, each character being a bitmap
// we need to align bitmaps on width multiple of 4 limitation.
int16_t x = area->x0;
nbgl_area_t rectArea;
const nbgl_font_t *font = nbgl_getFont(fontId);
int16_t x = area->x0;
nbgl_area_t rectArea;
const nbgl_font_t *font = nbgl_getFont(fontId);
nbgl_unicode_ctx_t *unicode_ctx = NULL;

LOG_DEBUG(DRAW_LOGGER,
"nbgl_drawText: x0 = %d, y0 = %d, w = %d, h = %d, fontColor = %d, "
Expand All @@ -558,10 +559,6 @@ nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area,
area->backgroundColor,
text);

#ifdef HAVE_UNICODE_SUPPORT
nbgl_unicode_ctx_t *unicode_ctx = nbgl_getUnicodeFont(fontId);
#endif // HAVE_UNICODE_SUPPORT

rectArea.backgroundColor = area->backgroundColor;
rectArea.bpp = (nbgl_bpp_t) font->bpp;

Expand All @@ -583,6 +580,9 @@ nbgl_font_id_e nbgl_drawText(const nbgl_area_t *area,

if (is_unicode) {
#ifdef HAVE_UNICODE_SUPPORT
if (unicode_ctx == NULL) {
unicode_ctx = nbgl_getUnicodeFont(fontId);
}
const nbgl_font_unicode_character_t *unicodeCharacter
= nbgl_getUnicodeFontCharacter(unicode);
// if not supported char, go to next one
Expand Down
Loading

0 comments on commit 285b5bf

Please sign in to comment.