diff --git a/lib_nbgl/src/nbgl_fonts.c b/lib_nbgl/src/nbgl_fonts.c index 657f03449..8c38867d1 100644 --- a/lib_nbgl/src/nbgl_fonts.c +++ b/lib_nbgl/src/nbgl_fonts.c @@ -97,7 +97,9 @@ const unsigned int C_unicode_characters_count uint16_t last_nb_lines = 0; uint16_t last_nb_pages = 0; bool last_bold_state = false; -void store_string_infos(char *text, uint16_t nb_lines, uint16_t nb_pages, bool bold); + +// Used to detect when a hyphenation (caesura) has been forced. +bool hard_caesura = false; #endif // BUILD_SCREENSHOTS /********************** @@ -723,6 +725,7 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *prevText = NULL; #ifdef BUILD_SCREENSHOTS + hard_caesura = false; last_nb_lines = 0; last_nb_pages = 1; last_bold_state = fontId == BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp; // True if Bold @@ -818,6 +821,10 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, width = 0; } else { +#ifdef BUILD_SCREENSHOTS + // An hyphenation (caesura) has been forced. + hard_caesura = true; +#endif // BUILD_SCREENSHOTS width = char_width; } nbLines++; diff --git a/lib_nbgl/src/nbgl_obj.c b/lib_nbgl/src/nbgl_obj.c index d9dc70ab7..e07d1b6fc 100644 --- a/lib_nbgl/src/nbgl_obj.c +++ b/lib_nbgl/src/nbgl_obj.c @@ -19,6 +19,9 @@ #include "nbgl_serialize.h" #include "os_io_seproxyhal.h" #endif +#ifdef BUILD_SCREENSHOTS +#include "json_scenario.h" +#endif // BUILD_SCREENSHOTS /********************* * DEFINES @@ -73,11 +76,6 @@ extern bool last_bold_state, verbose; **********************/ extern const char *get_ux_loc_string(uint32_t index); -#ifdef BUILD_SCREENSHOTS -char *get_printable_string(char *string); -void store_string_infos(const char *text, uint16_t nb_lines, uint16_t nb_pages, bool bold); -#endif // BUILD_SCREENSHOTS - /********************** * GLOBAL FUNCTIONS **********************/ @@ -388,21 +386,32 @@ static void draw_button(nbgl_button_t *obj, nbgl_obj_t *prevObj, bool computePos // draw the text (right of the icon, with 8 pixels between them) if (text != NULL) { nbgl_area_t rectArea; - textWidth = nbgl_getTextWidth(obj->fontId, text); + // Compute available with & height to display the text + rectArea.x0 = obj->obj.area.x0; + rectArea.y0 = obj->obj.area.y0; + // Only one line of text + rectArea.height = nbgl_getFontHeight(obj->fontId); + rectArea.y0 += (obj->obj.area.height - rectArea.height) / 2; + rectArea.width = obj->obj.area.width; if (obj->icon != NULL) { - rectArea.x0 = obj->obj.area.x0 + obj->obj.area.width / 2 - - (textWidth + obj->icon->width + 8) / 2 + obj->icon->width + 8; + rectArea.x0 += obj->icon->width + 8; + rectArea.width -= obj->icon->width + 8; } - else { - rectArea.x0 = obj->obj.area.x0 + (obj->obj.area.width - textWidth) / 2; + // Compute the width & number of characters displayed on first line + uint16_t textLen; + nbgl_getTextMaxLenAndWidth(obj->fontId, text, rectArea.width, &textLen, &textWidth, true); + +#ifdef BUILD_SCREENSHOTS + store_string_infos(text, obj->fontId, &rectArea, true, 1, 1, false); +#endif // BUILD_SCREENSHOTS + + // Center the text, horizontally + if (textWidth < rectArea.width) { + rectArea.x0 += (rectArea.width - textWidth) / 2; } LOG_DEBUG(OBJ_LOGGER, "draw_button(), text = %s\n", text); - rectArea.y0 - = obj->obj.area.y0 + (obj->obj.area.height - nbgl_getFontHeight(obj->fontId)) / 2; - rectArea.width = textWidth; - rectArea.height = nbgl_getFontHeight(obj->fontId); rectArea.backgroundColor = obj->innerColor; - nbgl_drawText(&rectArea, text, nbgl_getTextLength(text), obj->fontId, obj->foregroundColor); + nbgl_drawText(&rectArea, text, textLen, obj->fontId, obj->foregroundColor); } // draw the icon, if any if (obj->icon != NULL) { @@ -920,7 +929,13 @@ static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool compu if (obj->autoHideLongLine == true) { #ifdef BUILD_SCREENSHOTS nbgl_getTextNbLinesInWidth(fontId, text, obj->obj.area.width, obj->wrapping); - store_string_infos(text, last_nb_lines, last_nb_pages, last_bold_state); + store_string_infos(text, + fontId, + &obj->obj.area, + obj->wrapping, + last_nb_lines, + last_nb_pages, + last_bold_state); #endif // BUILD_SCREENSHOTS textWidth = nbgl_getSingleLineTextWidth(fontId, text); if (textWidth > obj->obj.area.width) { @@ -949,7 +964,8 @@ static void draw_textArea(nbgl_text_area_t *obj, nbgl_obj_t *prevObj, bool compu // get nb lines in the given width (depending of wrapping) nbLines = nbgl_getTextNbLinesInWidth(fontId, text, obj->obj.area.width, obj->wrapping); #ifdef BUILD_SCREENSHOTS - store_string_infos(text, last_nb_lines, last_nb_pages, last_bold_state); + store_string_infos( + text, fontId, &obj->obj.area, obj->wrapping, last_nb_lines, last_nb_pages, last_bold_state); #endif // BUILD_SCREENSHOTS // saturate nb lines if nbMaxLines is greater than 0 if ((obj->nbMaxLines > 0) && (obj->nbMaxLines < nbLines)) { diff --git a/lib_nbgl/src/nbgl_step.c b/lib_nbgl/src/nbgl_step.c index ea99dfa22..774fb0a6a 100644 --- a/lib_nbgl/src/nbgl_step.c +++ b/lib_nbgl/src/nbgl_step.c @@ -13,6 +13,9 @@ #include "glyphs.h" #include "os_pic.h" #include "os_print.h" +#ifdef BUILD_SCREENSHOTS +#include "json_scenario.h" +#endif // BUILD_SCREENSHOTS /********************* * DEFINES @@ -92,12 +95,6 @@ extern UX_LOC_STRINGS_INDEX last_string_id; extern uint16_t last_nb_lines; extern uint16_t last_nb_pages; extern bool last_bold_state; - -/********************** - * PROTOTYPES - **********************/ -void store_string_infos(const char *text, uint16_t nb_lines, uint16_t nb_pages_, bool bold); - #endif // BUILD_SCREENSHOTS /********************** @@ -411,6 +408,13 @@ nbgl_step_t nbgl_stepDrawText(nbgl_stepPosition_t pos, nbgl_contentCenteredInfoStyle_t style, bool modal) { +#ifdef BUILD_SCREENSHOTS + // Initialize a default area + nbgl_area_t area; + area.x0 = area.y0 = 0; + area.width = AVAILABLE_WIDTH; + area.height = NB_MAX_LINES * nbgl_getFontLineHeight(BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp); +#endif // BUILD_SCREENSHOTS StepContext_t *ctx = getFreeContext(TEXT_STEP, modal); if (!ctx) { return NULL; @@ -428,22 +432,50 @@ nbgl_step_t nbgl_stepDrawText(nbgl_stepPosition_t pos, ctx->textContext.nbPages = nbgl_getTextNbPagesInWidth( BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp, text, NB_MAX_LINES, AVAILABLE_WIDTH); #ifdef BUILD_SCREENSHOTS - store_string_infos(text, last_nb_lines, last_nb_pages, last_bold_state); + store_string_infos(text, + BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp, + &area, + true, + last_nb_lines, + last_nb_pages, + last_bold_state); #endif // BUILD_SCREENSHOTS } else { #ifdef BUILD_SCREENSHOTS + uint16_t nb_lines_title; // Call this function to get correct nb_lines/nb_pages for text field. nbgl_getTextNbPagesInWidth( BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp, text, NB_MAX_LINES, AVAILABLE_WIDTH); - store_string_infos(text, last_nb_lines, last_nb_pages, last_bold_state); + nb_lines_title = last_nb_lines; + // There is a sub text, so no more than 3 lines for title... + if (nb_lines_title > 3) { + nb_lines_title = 3; + } + area.height + = nb_lines_title * nbgl_getFontLineHeight(BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp); + store_string_infos(text, + BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp, + &area, + true, + last_nb_lines, + last_nb_pages, + last_bold_state); #endif // BUILD_SCREENSHOTS // NB_MAX_LINES-1 because first line is for main text ctx->textContext.nbPages = nbgl_getTextNbPagesInWidth( BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp, subText, NB_MAX_LINES - 1, AVAILABLE_WIDTH); #ifdef BUILD_SCREENSHOTS + area.height = (NB_MAX_LINES - nb_lines_title) + * nbgl_getFontLineHeight(BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp); // If subTxtid is not valid, we'll use txtId for nb_lines/nb_pages values - store_string_infos(subText, last_nb_lines, last_nb_pages, last_bold_state); + store_string_infos(subText, + BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp, + &area, + true, + last_nb_lines, + last_nb_pages, + last_bold_state); #endif // BUILD_SCREENSHOTS } LOG_DEBUG(STEP_LOGGER,