10#include "app_config.h"
14#include "os_helpers.h"
16#if defined(HAVE_LANGUAGE_PACK)
23#define PIC_FONT(x) ((nbgl_font_t const *) PIC(x))
24#define BAGL_FONT_ID_MASK 0x0FFF
26#define IS_WORD_DELIM(c) (c == ' ' || c == '\n' || c == '\b' || c == '\f' || c == '-' || c == '_')
35#ifdef HAVE_UNICODE_SUPPORT
43#ifdef HAVE_LANGUAGE_PACK
47#if SMALL_FONT_HEIGHT == 24
48#include "nbgl_font_inter_regular_24.inc"
49#include "nbgl_font_inter_semibold_24.inc"
50#include "nbgl_font_inter_medium_32.inc"
51#include "nbgl_font_inter_regular_24_1bpp.inc"
52#include "nbgl_font_inter_semibold_24_1bpp.inc"
53#include "nbgl_font_inter_medium_32_1bpp.inc"
54#elif SMALL_FONT_HEIGHT == 28
55#include "nbgl_font_inter_regular_28.inc"
56#include "nbgl_font_inter_semibold_28.inc"
57#include "nbgl_font_inter_medium_36.inc"
58#include "nbgl_font_inter_regular_28_1bpp.inc"
59#include "nbgl_font_inter_semibold_28_1bpp.inc"
60#include "nbgl_font_inter_medium_36_1bpp.inc"
61#elif SMALL_FONT_HEIGHT == 18
62#include "nbgl_font_nanotext_medium_18_1bpp.inc"
63#include "nbgl_font_nanotext_bold_18_1bpp.inc"
64#include "nbgl_font_nanodisplay_semibold_24_1bpp.inc"
65#elif SMALL_FONT_HEIGHT == 11
66#include "nbgl_font_open_sans_extrabold_11.inc"
67#include "nbgl_font_open_sans_regular_11.inc"
68#include "nbgl_font_open_sans_light_16.inc"
73#include "nbgl_font_rom_struct.inc"
76__attribute__((section(
"._nbgl_fonts_"))) const
unsigned int C_nbgl_fonts_count
77 = sizeof(C_nbgl_fonts) / sizeof(C_nbgl_fonts[0]);
79#if (defined(HAVE_BOLOS) && !defined(BOLOS_OS_UPGRADER_APP))
80#if !defined(HAVE_LANGUAGE_PACK)
83#include "nbgl_font_unicode_rom_struct.inc"
88const unsigned int C_unicode_characters_count
89 = (
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE)
90 /
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE[0]));
95#ifdef BUILD_SCREENSHOTS
97uint16_t last_nb_lines = 0;
98uint16_t last_nb_pages = 0;
99bool last_bold_state =
false;
102bool hard_caesura =
false;
121 unsigned int i = C_nbgl_fonts_count;
126 if (
PIC_FONT(C_nbgl_fonts[i])->font_id == fontId) {
146 const uint8_t *txt = *text;
147 uint8_t cur_char = *txt++;
161 if ((cur_char >= 0xF0) && (*textLen >= 4)) {
162 unicode = (cur_char & 0x07) << 18;
163 unicode |= (*txt++ & 0x3F) << 12;
164 unicode |= (*txt++ & 0x3F) << 6;
165 unicode |= (*txt++ & 0x3F);
169 else if ((cur_char >= 0xE0) && (*textLen >= 3)) {
170 unicode = (cur_char & 0x0F) << 12;
171 unicode |= (*txt++ & 0x3F) << 6;
172 unicode |= (*txt++ & 0x3F);
177 else if ((cur_char >= 0xC2) && (*textLen >= 2)) {
178 unicode = (cur_char & 0x1F) << 6;
179 unicode |= (*txt++ & 0x3F);
185 *textLen = *textLen - (txt - *text);
198static uint8_t getCharWidth(
const nbgl_font_t *font, uint32_t unicode,
bool is_unicode)
201#ifdef HAVE_UNICODE_SUPPORT
203 = nbgl_getUnicodeFontCharacter(unicode);
204 if (!unicodeCharacter) {
214 if ((unicode < font->first_char) || (unicode > font->
last_char)) {
238#ifdef BUILD_SCREENSHOTS
239 uint16_t nb_lines = 0;
241 uint16_t line_width = 0;
242 uint16_t max_width = 0;
244 uint16_t textLen =
MIN(strlen(text), maxLen);
245#ifdef HAVE_UNICODE_SUPPORT
249#ifdef BUILD_SCREENSHOTS
251 bool next_bold_state = last_bold_state;
261#ifdef HAVE_UNICODE_SUPPORT
262 if (is_unicode && !unicode_ctx) {
263 unicode_ctx = nbgl_getUnicodeFont(fontId);
266 if (unicode ==
'\n') {
267 if (breakOnLineEnd) {
275 else if (unicode ==
'\b') {
278#ifdef HAVE_UNICODE_SUPPORT
282#ifdef BUILD_SCREENSHOTS
283 next_bold_state =
true;
288#ifdef HAVE_UNICODE_SUPPORT
292#ifdef BUILD_SCREENSHOTS
293 next_bold_state =
false;
298 char_width = getCharWidth(font, unicode, is_unicode);
299#ifdef BUILD_SCREENSHOTS
300 if (char_width != 0) {
302 last_bold_state = next_bold_state;
305 line_width += char_width;
307 if (line_width > max_width) {
308 max_width = line_width;
311#ifdef BUILD_SCREENSHOTS
312 if (line_width != 0) {
315 last_nb_lines = nb_lines;
330 return getTextWidth(fontId, text,
true, 0xFFFF);
344 return getTextWidth(fontId, text,
true, maxLen);
356 return getTextWidth(fontId, text,
false, 0xFFFF);
371 uint16_t textLen = 4;
372#ifdef HAVE_UNICODE_SUPPORT
377#ifdef HAVE_UNICODE_SUPPORT
378 if (is_unicode && !unicode_ctx) {
379 unicode_ctx = nbgl_getUnicodeFont(fontId);
383 return getCharWidth(font, unicode, is_unicode);
418 uint16_t nbLines = 1;
450 const char *origText = text;
455 else if (*text ==
'\n') {
460 return text - origText;
485 uint32_t lenAtLastDelimiter = 0, widthAtlastDelimiter = 0;
486#ifdef HAVE_UNICODE_SUPPORT
496 uint16_t curTextLen = textLen;
499#ifdef HAVE_UNICODE_SUPPORT
500 if (is_unicode && !unicode_ctx) {
501 unicode_ctx = nbgl_getUnicodeFont(fontId);
505 if ((unicode ==
'\f') || (unicode ==
'\n')) {
506 *len += curTextLen - textLen;
510 else if (unicode ==
'\b') {
513#ifdef HAVE_UNICODE_SUPPORT
520#ifdef HAVE_UNICODE_SUPPORT
525 *len += curTextLen - textLen;
529 char_width = getCharWidth(font, unicode, is_unicode);
530 if (char_width == 0) {
531 *len += curTextLen - textLen;
537 lenAtLastDelimiter = *len;
538 widthAtlastDelimiter = *width;
540 if ((*width + char_width) > maxWidth) {
541 if ((wrapping ==
true) && (widthAtlastDelimiter > 0)) {
542 *len = lenAtLastDelimiter + 1;
543 *width = widthAtlastDelimiter;
547 *len += curTextLen - textLen;
548 *width = *width + char_width;
574 uint16_t textLen = strlen(text);
576 const char *lastDelimiter = NULL;
577 uint32_t lenAtLastDelimiter = 0;
578 const char *origText = text;
579 const char *previousText;
580#ifdef HAVE_UNICODE_SUPPORT
584 while ((textLen) && (maxNbLines > 0)) {
591#ifdef HAVE_UNICODE_SUPPORT
592 if (is_unicode && !unicode_ctx) {
593 unicode_ctx = nbgl_getUnicodeFont(fontId);
598 lastDelimiter = text;
599 lenAtLastDelimiter = textLen;
603 if (unicode ==
'\n') {
606 if (maxNbLines == 0) {
613 else if (unicode ==
'\f') {
618 else if (unicode ==
'\b') {
621#ifdef HAVE_UNICODE_SUPPORT
628#ifdef HAVE_UNICODE_SUPPORT
636 char_width = getCharWidth(font, unicode, is_unicode);
637 if (char_width == 0) {
641 if ((width + char_width) > maxWidth) {
642 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
643 text = lastDelimiter;
644 lastDelimiter = NULL;
645 textLen = lenAtLastDelimiter;
648 textLen += text - previousText;
657 *len = text - origText;
658 return (maxNbLines == 0);
692 cur_char = text[textLen];
694 if (cur_char ==
'\n') {
700 if ((cur_char < font->first_char) || (cur_char > font->
last_char)) {
705 char_width = character->
width;
707 if ((*width + char_width) > maxWidth) {
711 *width = *width + char_width;
732#ifdef SCREEN_SIZE_NANO
733 uint16_t nbLines = 0;
735 uint16_t nbLines = 1;
737 uint16_t textLen = strlen(text);
738 const char *lastDelimiter = NULL;
739 uint32_t lenAtLastDelimiter = 0;
740 const char *prevText = NULL;
741#ifdef HAVE_UNICODE_SUPPORT
745#ifdef BUILD_SCREENSHOTS
746 hard_caesura =
false;
750 bool next_bold_state = last_bold_state;
762#ifdef HAVE_UNICODE_SUPPORT
763 if (is_unicode && !unicode_ctx) {
764 unicode_ctx = nbgl_getUnicodeFont(fontId);
770 lastDelimiter = prevText;
771 lenAtLastDelimiter = textLen;
774 if (unicode ==
'\f') {
775#ifdef BUILD_SCREENSHOTS
783 else if (unicode ==
'\n') {
785#if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
786 if (!(nbLines % 4)) {
793 lastDelimiter = NULL;
797 else if (unicode ==
'\b') {
800#ifdef HAVE_UNICODE_SUPPORT
804#ifdef BUILD_SCREENSHOTS
805 next_bold_state =
true;
810#ifdef HAVE_UNICODE_SUPPORT
814#ifdef BUILD_SCREENSHOTS
815 next_bold_state =
false;
821 char_width = getCharWidth(font, unicode, is_unicode);
822 if (char_width == 0) {
825#ifdef BUILD_SCREENSHOTS
827 last_bold_state = next_bold_state;
831 if ((width + char_width) > maxWidth) {
832 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
833 text = lastDelimiter + 1;
834 lastDelimiter = NULL;
835 textLen = lenAtLastDelimiter;
839#ifdef BUILD_SCREENSHOTS
846#if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
847 if (!(nbLines % 4)) {
858#ifdef SCREEN_SIZE_NANO
863#ifdef BUILD_SCREENSHOTS
864 last_nb_lines = nbLines;
881 uint8_t nbLinesPerPage,
886 uint16_t nbLines = 0;
888 uint16_t textLen = strlen(text);
889 const char *lastDelimiter = NULL;
890 uint32_t lenAtLastDelimiter = 0;
891 const char *prevText = NULL;
892#ifdef HAVE_UNICODE_SUPPORT
896#ifdef BUILD_SCREENSHOTS
897 last_nb_lines = nbLines;
898 last_nb_pages = nbPages;
900 bool next_bold_state = last_bold_state;
911#ifdef HAVE_UNICODE_SUPPORT
912 if (is_unicode && !unicode_ctx) {
913 unicode_ctx = nbgl_getUnicodeFont(fontId);
919 lastDelimiter = prevText;
920 lenAtLastDelimiter = textLen;
923 if (unicode ==
'\f') {
925#ifdef BUILD_SCREENSHOTS
926#ifdef SCREEN_SIZE_NANO
930#ifdef SCREEN_SIZE_NANO
933 if (last_nb_lines < nbLines) {
934 last_nb_lines = nbLines;
942 else if (unicode ==
'\n') {
944#ifdef BUILD_SCREENSHOTS
945 if (last_nb_lines < nbLines) {
946 last_nb_lines = nbLines;
949 if (nbLines == nbLinesPerPage && textLen) {
955 lastDelimiter = NULL;
959 else if (unicode ==
'\b') {
962#ifdef HAVE_UNICODE_SUPPORT
966#ifdef BUILD_SCREENSHOTS
967 next_bold_state =
true;
972#ifdef HAVE_UNICODE_SUPPORT
976#ifdef BUILD_SCREENSHOTS
977 next_bold_state =
false;
983 char_width = getCharWidth(font, unicode, is_unicode);
984 if (char_width == 0) {
988#ifdef BUILD_SCREENSHOTS
990 last_bold_state = next_bold_state;
994 if ((width + char_width) > maxWidth) {
995 if (lastDelimiter != NULL) {
996 text = lastDelimiter + 1;
997 lastDelimiter = NULL;
998 textLen = lenAtLastDelimiter;
1005#ifdef BUILD_SCREENSHOTS
1006 if (last_nb_lines < nbLines) {
1007 last_nb_lines = nbLines;
1010 if (nbLines == nbLinesPerPage) {
1016 width += char_width;
1019#ifdef BUILD_SCREENSHOTS
1020#ifdef SCREEN_SIZE_NANO
1025 if (last_nb_lines < nbLines) {
1026 last_nb_lines = nbLines;
1028 last_nb_pages = nbPages;
1067 uint8_t currentNbLines = 1;
1068 char *lastDelimiter = NULL;
1069 uint32_t lenAtLastDelimiter = 0;
1070 char *prevText[4] = {0};
1071 uint16_t prevWidth[2] = {0};
1073#ifdef HAVE_UNICODE_SUPPORT
1084 prevText[3] = prevText[2];
1085 prevText[2] = prevText[1];
1086 prevText[1] = prevText[0];
1090 if (unicode ==
'\n') {
1093 lastDelimiter = NULL;
1096#ifdef HAVE_UNICODE_SUPPORT
1097 if (is_unicode && !unicode_ctx) {
1098 unicode_ctx = nbgl_getUnicodeFont(fontId);
1101 char_width = getCharWidth(font, unicode, is_unicode);
1102 if (char_width == 0) {
1108 lastDelimiter = prevText[0];
1109 lenAtLastDelimiter = textLen + 1;
1112 if ((width + char_width) > maxWidth) {
1115 if (currentNbLines < nbLines) {
1118 if (lastDelimiter != NULL) {
1119 *lastDelimiter++ =
'\n';
1120 text = lastDelimiter;
1121 lastDelimiter = NULL;
1122 textLen = lenAtLastDelimiter - 1;
1125 textLen += text - prevText[0];
1136 for (i = 0; i < 2; i++) {
1137 if ((prevText[i + 1] != NULL)
1138 && ((prevWidth[i] + (3 * getCharWidth(font,
'.',
false))) <= maxWidth)) {
1143 if (prevText[i + 1] != NULL) {
1144 memcpy(prevText[i + 1],
"...", 4);
1150 prevWidth[1] = prevWidth[0];
1151 prevWidth[0] = width;
1152 width += char_width;
1172 const char *origText,
1176 uint16_t reducedTextLen)
1179 uint16_t textLen = strlen(origText);
1181 uint8_t currentNbLines = 1;
1182 uint32_t i = 0, j = 0;
1185 if ((nbLines & 0x1) == 0) {
1189 while ((i < textLen) && (j < reducedTextLen)) {
1193 curChar = origText[i];
1195 char_width = getCharWidth(font, curChar,
false);
1196 if (char_width == 0) {
1197 reducedText[j] = curChar;
1204 if ((width + char_width) > maxWidth) {
1210 else if ((currentNbLines == ((nbLines / 2) + 1)) && ((width + char_width) > halfWidth)) {
1211 uint32_t halfFullWidth = (nbLines / 2) * maxWidth + halfWidth;
1212 uint32_t countDown = textLen;
1214 reducedText[j - 1] =
'.';
1215 reducedText[j] =
'.';
1216 reducedText[j + 1] =
'.';
1219 while (width < halfFullWidth) {
1221 curChar = origText[countDown];
1222 char_width = getCharWidth(font, curChar,
false);
1223 width += char_width;
1225 memcpy(&reducedText[j + 2], &origText[countDown + 1], textLen - countDown + 1);
1229 reducedText[j] = curChar;
1233 width += char_width;
1235 reducedText[j] =
'\0';
1238#ifdef HAVE_UNICODE_SUPPORT
1248 if ((unicodeCtx.
font != NULL) && (unicodeCtx.
font->
font_id == fontId)) {
1251#if defined(HAVE_LANGUAGE_PACK)
1253 const uint8_t *ptr = (
const uint8_t *) language_pack;
1257 unicodeCtx.
bitmap = (
const uint8_t *) (ptr + language_pack->bitmaps_offset);
1259 for (uint32_t i = 0; i < language_pack->nb_fonts; i++) {
1260 if (font->
font_id == fontId) {
1262 unicodeCtx.
font = font;
1269 unicodeCtx.
characters += language_pack->nb_characters;
1288#if defined(HAVE_LANGUAGE_PACK)
1291 uint32_t n = language_pack->nb_characters;
1292 if (characters == NULL) {
1297 for (
unsigned i = 0; i < n - 1; i++, characters++) {
1301 = (characters + 1)->bitmap_offset - characters->
bitmap_offset;
1325uint32_t nbgl_getUnicodeFontCharacterByteCount(
void)
1327#ifdef HAVE_LANGUAGE_PACK
1334#ifdef HAVE_LANGUAGE_PACK
1345 unicodeCtx.
font = NULL;
#define LOG_FATAL(__logger,...)
Middle Level API of the new BOLOS Graphical Library.
void nbgl_textWrapOnNbLines(nbgl_font_id_e fontId, char *text, uint16_t maxWidth, uint8_t nbLines)
Modifies the given text to wrap it on the given max width (in pixels), in the given nbLines If possib...
void nbgl_getTextMaxLenAndWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width, bool wrapping)
compute the max width of the first line of the given text fitting in maxWidth
uint16_t nbgl_getTextNbLines(const char *text)
return the number of lines in the given text, according to the found ' 's
uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId, const char *text, uint8_t nbLinesPerPage, uint16_t maxWidth)
compute the number of pages of nbLinesPerPage lines per page of the given text fitting in the given m...
uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text until the first or \0 is encountered
uint8_t nbgl_getCharWidth(nbgl_font_id_e fontId, const char *text)
return the width in pixels of the given UTF-8 character
bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t maxNbLines, uint16_t *len, bool wrapping)
compute the len of the given text (in bytes) fitting in the given maximum nb lines,...
bool nbgl_getTextMaxLenAndWidthFromEnd(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, uint16_t *len, uint16_t *width)
compute the len and width of the given text fitting in the maxWidth, starting from end of text
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
return the height in pixels of the font with the given font ID
void nbgl_textReduceOnNbLines(nbgl_font_id_e fontId, const char *origText, uint16_t maxWidth, uint8_t nbLines, char *reducedText, uint16_t reducedTextLen)
Create a reduced version of given ASCII text to wrap it on the given max width (in pixels),...
uint32_t nbgl_popUnicodeChar(const uint8_t **text, uint16_t *textLen, bool *is_unicode)
Get the coming unicode value on the given UTF-8 string. If the value is a simple ASCII character,...
uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text)
return the max width in pixels of the given text (can be multiline)
uint16_t nbgl_getTextHeightInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
return the height of the given multiline text, with the given font.
#define BAGL_FONT_ID_MASK
uint16_t nbgl_getTextLength(const char *text)
return the number of bytes of the given text, excluding final ' ' or '\0'
uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId, const char *text, uint16_t maxWidth, bool wrapping)
compute the number of lines of the given text fitting in the given maxWidth
uint16_t nbgl_getTextHeight(nbgl_font_id_e fontId, const char *text)
return the height of the given multiline text, with the given font.
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
uint16_t nbgl_getSingleLineTextWidthInLen(nbgl_font_id_e fontId, const char *text, uint16_t maxLen)
return the max width in pixels of the given text until the first or \0 is encountered,...
__attribute__((section("._nbgl_fonts_"))) const
return the non-unicode font corresponding to the given font ID
@ BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
const nbgl_font_t * nbgl_getFont(nbgl_font_id_e fontId)
fonts nicknames to be used for various wallet size targets (non-Nano)
uint32_t width
width of character in pixels
structure defining an ASCII font
uint8_t char_kerning
kerning for the font
uint8_t first_char
ASCII code of the first character in bitmap and in characters fields.
const nbgl_font_character_t *const characters
array containing definitions of all characters
uint8_t height
height of all characters in pixels
uint8_t line_height
height of a line for all characters in pixels
uint8_t last_char
ASCII code of the last character in bitmap and in characters fields.
structure defining a unicode character (except the bitmap)
uint32_t char_unicode
plane value from 0 to 16 then 16-bit code.
uint32_t width
width of character in pixels
uint32_t bitmap_offset
offset of this character in chars buffer
structure defining a unicode font
uint16_t bitmap_len
Size in bytes of all characters bitmaps.
uint8_t font_id
ID of the font, from nbgl_font_id_e.
const nbgl_font_unicode_character_t * characters
const nbgl_font_unicode_t * font
uint32_t unicode_character_byte_count