10#include "app_config.h"
14#include "os_helpers.h"
17#if defined(HAVE_LANGUAGE_PACK)
24#define PIC_FONT(x) ((nbgl_font_t const *) PIC(x))
25#define BAGL_FONT_ID_MASK 0x0FFF
27#define IS_WORD_DELIM(c) (c == ' ' || c == '\n' || c == '\b' || c == '\f' || c == '-' || c == '_')
36#ifdef HAVE_UNICODE_SUPPORT
44#ifdef HAVE_LANGUAGE_PACK
48#if SMALL_FONT_HEIGHT == 24
49#include "nbgl_font_inter_regular_24.inc"
50#include "nbgl_font_inter_semibold_24.inc"
51#include "nbgl_font_inter_medium_32.inc"
52#include "nbgl_font_inter_regular_24_1bpp.inc"
53#include "nbgl_font_inter_semibold_24_1bpp.inc"
54#include "nbgl_font_inter_medium_32_1bpp.inc"
55#elif SMALL_FONT_HEIGHT == 28
56#include "nbgl_font_inter_regular_28.inc"
57#include "nbgl_font_inter_semibold_28.inc"
58#include "nbgl_font_inter_medium_36.inc"
59#include "nbgl_font_inter_regular_28_1bpp.inc"
60#include "nbgl_font_inter_semibold_28_1bpp.inc"
61#include "nbgl_font_inter_medium_36_1bpp.inc"
62#elif SMALL_FONT_HEIGHT == 18
63#include "nbgl_font_nanotext_medium_18_1bpp.inc"
64#include "nbgl_font_nanotext_bold_18_1bpp.inc"
65#include "nbgl_font_nanodisplay_semibold_24_1bpp.inc"
66#elif SMALL_FONT_HEIGHT == 11
67#include "nbgl_font_open_sans_extrabold_11.inc"
68#include "nbgl_font_open_sans_regular_11.inc"
69#include "nbgl_font_open_sans_light_16.inc"
74#include "nbgl_font_rom_struct.inc"
77__attribute__((section(
"._nbgl_fonts_"))) const
unsigned int C_nbgl_fonts_count
78 = sizeof(C_nbgl_fonts) / sizeof(C_nbgl_fonts[0]);
80#if (defined(HAVE_BOLOS) && !defined(BOLOS_OS_UPGRADER_APP))
81#if !defined(HAVE_LANGUAGE_PACK)
84#include "nbgl_font_unicode_rom_struct.inc"
89const unsigned int C_unicode_characters_count
90 = (
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE)
91 /
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE[0]));
96#ifdef BUILD_SCREENSHOTS
98uint16_t last_nb_lines = 0;
99uint16_t last_nb_pages = 0;
100bool last_bold_state =
false;
103bool hard_caesura =
false;
122 unsigned int i = C_nbgl_fonts_count;
127 if (
PIC_FONT(C_nbgl_fonts[i])->font_id == fontId) {
147 const uint8_t *txt = *text;
148 uint8_t cur_char = *txt++;
162 if ((cur_char >= 0xF0) && (*textLen >= 4)) {
163 unicode = (cur_char & 0x07) << 18;
164 unicode |= (*txt++ & 0x3F) << 12;
165 unicode |= (*txt++ & 0x3F) << 6;
166 unicode |= (*txt++ & 0x3F);
170 else if ((cur_char >= 0xE0) && (*textLen >= 3)) {
171 unicode = (cur_char & 0x0F) << 12;
172 unicode |= (*txt++ & 0x3F) << 6;
173 unicode |= (*txt++ & 0x3F);
178 else if ((cur_char >= 0xC2) && (*textLen >= 2)) {
179 unicode = (cur_char & 0x1F) << 6;
180 unicode |= (*txt++ & 0x3F);
186 *textLen = *textLen - (txt - *text);
199static uint8_t getCharWidth(
const nbgl_font_t *font, uint32_t unicode,
bool is_unicode)
202#ifdef HAVE_UNICODE_SUPPORT
204 = nbgl_getUnicodeFontCharacter(unicode);
205 if (!unicodeCharacter) {
215 if ((unicode < font->first_char) || (unicode > font->
last_char)) {
239#ifdef BUILD_SCREENSHOTS
240 uint16_t nb_lines = 0;
242 uint16_t line_width = 0;
243 uint16_t max_width = 0;
245 uint16_t textLen =
MIN(strlen(text), maxLen);
246#ifdef HAVE_UNICODE_SUPPORT
250#ifdef BUILD_SCREENSHOTS
252 bool next_bold_state = last_bold_state;
262#ifdef HAVE_UNICODE_SUPPORT
263 if (is_unicode && !unicode_ctx) {
264 unicode_ctx = nbgl_getUnicodeFont(fontId);
267 if (unicode ==
'\n') {
268 if (breakOnLineEnd) {
276 else if (unicode ==
'\b') {
279#ifdef HAVE_UNICODE_SUPPORT
283#ifdef BUILD_SCREENSHOTS
284 next_bold_state =
true;
289#ifdef HAVE_UNICODE_SUPPORT
293#ifdef BUILD_SCREENSHOTS
294 next_bold_state =
false;
299 char_width = getCharWidth(font, unicode, is_unicode);
300#ifdef BUILD_SCREENSHOTS
301 if (char_width != 0) {
303 last_bold_state = next_bold_state;
306 line_width += char_width;
308 if (line_width > max_width) {
309 max_width = line_width;
312#ifdef BUILD_SCREENSHOTS
313 if (line_width != 0) {
316 last_nb_lines = nb_lines;
331 return getTextWidth(fontId, text,
true, 0xFFFF);
345 return getTextWidth(fontId, text,
true, maxLen);
357 return getTextWidth(fontId, text,
false, 0xFFFF);
372 uint16_t textLen = 4;
373#ifdef HAVE_UNICODE_SUPPORT
378#ifdef HAVE_UNICODE_SUPPORT
379 if (is_unicode && !unicode_ctx) {
380 unicode_ctx = nbgl_getUnicodeFont(fontId);
384 return getCharWidth(font, unicode, is_unicode);
419 uint16_t nbLines = 1;
451 const char *origText = text;
456 else if (*text ==
'\n') {
461 return text - origText;
486 uint32_t lenAtLastDelimiter = 0, widthAtlastDelimiter = 0;
487#ifdef HAVE_UNICODE_SUPPORT
497 uint16_t curTextLen = textLen;
500#ifdef HAVE_UNICODE_SUPPORT
501 if (is_unicode && !unicode_ctx) {
502 unicode_ctx = nbgl_getUnicodeFont(fontId);
506 if ((unicode ==
'\f') || (unicode ==
'\n')) {
507 *len += curTextLen - textLen;
511 else if (unicode ==
'\b') {
514#ifdef HAVE_UNICODE_SUPPORT
521#ifdef HAVE_UNICODE_SUPPORT
526 *len += curTextLen - textLen;
530 char_width = getCharWidth(font, unicode, is_unicode);
531 if (char_width == 0) {
532 *len += curTextLen - textLen;
538 lenAtLastDelimiter = *len;
539 widthAtlastDelimiter = *width;
541 if ((*width + char_width) > maxWidth) {
542 if ((wrapping ==
true) && (widthAtlastDelimiter > 0)) {
543 *len = lenAtLastDelimiter + 1;
544 *width = widthAtlastDelimiter;
548 *len += curTextLen - textLen;
549 *width = *width + char_width;
575 uint16_t textLen = strlen(text);
577 const char *lastDelimiter = NULL;
578 uint32_t lenAtLastDelimiter = 0;
579 const char *origText = text;
580 const char *previousText;
581#ifdef HAVE_UNICODE_SUPPORT
585 while ((textLen) && (maxNbLines > 0)) {
592#ifdef HAVE_UNICODE_SUPPORT
593 if (is_unicode && !unicode_ctx) {
594 unicode_ctx = nbgl_getUnicodeFont(fontId);
599 lastDelimiter = text;
600 lenAtLastDelimiter = textLen;
604 if (unicode ==
'\n') {
607 if (maxNbLines == 0) {
610 lastDelimiter = NULL;
615 else if (unicode ==
'\f') {
620 else if (unicode ==
'\b') {
623#ifdef HAVE_UNICODE_SUPPORT
630#ifdef HAVE_UNICODE_SUPPORT
638 char_width = getCharWidth(font, unicode, is_unicode);
639 if (char_width == 0) {
643 if ((width + char_width) > maxWidth) {
644 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
645 text = lastDelimiter;
646 lastDelimiter = NULL;
647 textLen = lenAtLastDelimiter;
650 textLen += text - previousText;
659 *len = text - origText;
660 return (maxNbLines == 0);
694 cur_char = text[textLen];
696 if (cur_char ==
'\n') {
702 if ((cur_char < font->first_char) || (cur_char > font->
last_char)) {
707 char_width = character->
width;
709 if ((*width + char_width) > maxWidth) {
713 *width = *width + char_width;
734#ifdef SCREEN_SIZE_NANO
735 uint16_t nbLines = 0;
737 uint16_t nbLines = 1;
739 uint16_t textLen = strlen(text);
740 const char *lastDelimiter = NULL;
741 uint32_t lenAtLastDelimiter = 0;
742 const char *prevText = NULL;
743#ifdef HAVE_UNICODE_SUPPORT
747#ifdef BUILD_SCREENSHOTS
748 hard_caesura =
false;
752 bool next_bold_state = last_bold_state;
764#ifdef HAVE_UNICODE_SUPPORT
765 if (is_unicode && !unicode_ctx) {
766 unicode_ctx = nbgl_getUnicodeFont(fontId);
772 lastDelimiter = prevText;
773 lenAtLastDelimiter = textLen;
776 if (unicode ==
'\f') {
777#ifdef BUILD_SCREENSHOTS
785 else if (unicode ==
'\n') {
787#if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
788 if (!(nbLines % 4)) {
795 lastDelimiter = NULL;
799 else if (unicode ==
'\b') {
802#ifdef HAVE_UNICODE_SUPPORT
806#ifdef BUILD_SCREENSHOTS
807 next_bold_state =
true;
812#ifdef HAVE_UNICODE_SUPPORT
816#ifdef BUILD_SCREENSHOTS
817 next_bold_state =
false;
823 char_width = getCharWidth(font, unicode, is_unicode);
824 if (char_width == 0) {
827#ifdef BUILD_SCREENSHOTS
829 last_bold_state = next_bold_state;
833 if ((width + char_width) > maxWidth) {
834 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
835 text = lastDelimiter + 1;
836 lastDelimiter = NULL;
837 textLen = lenAtLastDelimiter;
841#ifdef BUILD_SCREENSHOTS
848#if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
849 if (!(nbLines % 4)) {
860#ifdef SCREEN_SIZE_NANO
865#ifdef BUILD_SCREENSHOTS
866 last_nb_lines = nbLines;
883 uint8_t nbLinesPerPage,
888 uint16_t nbLines = 0;
890 uint16_t textLen = strlen(text);
891 const char *lastDelimiter = NULL;
892 uint32_t lenAtLastDelimiter = 0;
893 const char *prevText = NULL;
894#ifdef HAVE_UNICODE_SUPPORT
898#ifdef BUILD_SCREENSHOTS
899 last_nb_lines = nbLines;
900 last_nb_pages = nbPages;
902 bool next_bold_state = last_bold_state;
913#ifdef HAVE_UNICODE_SUPPORT
914 if (is_unicode && !unicode_ctx) {
915 unicode_ctx = nbgl_getUnicodeFont(fontId);
921 lastDelimiter = prevText;
922 lenAtLastDelimiter = textLen;
925 if (unicode ==
'\f') {
927#ifdef BUILD_SCREENSHOTS
928#ifdef SCREEN_SIZE_NANO
932#ifdef SCREEN_SIZE_NANO
935 if (last_nb_lines < nbLines) {
936 last_nb_lines = nbLines;
944 else if (unicode ==
'\n') {
946#ifdef BUILD_SCREENSHOTS
947 if (last_nb_lines < nbLines) {
948 last_nb_lines = nbLines;
951 if (nbLines == nbLinesPerPage && textLen) {
957 lastDelimiter = NULL;
961 else if (unicode ==
'\b') {
964#ifdef HAVE_UNICODE_SUPPORT
968#ifdef BUILD_SCREENSHOTS
969 next_bold_state =
true;
974#ifdef HAVE_UNICODE_SUPPORT
978#ifdef BUILD_SCREENSHOTS
979 next_bold_state =
false;
985 char_width = getCharWidth(font, unicode, is_unicode);
986 if (char_width == 0) {
990#ifdef BUILD_SCREENSHOTS
992 last_bold_state = next_bold_state;
996 if ((width + char_width) > maxWidth) {
997 if (lastDelimiter != NULL) {
998 text = lastDelimiter + 1;
999 lastDelimiter = NULL;
1000 textLen = lenAtLastDelimiter;
1007#ifdef BUILD_SCREENSHOTS
1008 if (last_nb_lines < nbLines) {
1009 last_nb_lines = nbLines;
1012 if (nbLines == nbLinesPerPage) {
1018 width += char_width;
1021#ifdef BUILD_SCREENSHOTS
1022#ifdef SCREEN_SIZE_NANO
1027 if (last_nb_lines < nbLines) {
1028 last_nb_lines = nbLines;
1030 last_nb_pages = nbPages;
1069 uint8_t currentNbLines = 1;
1070 char *lastDelimiter = NULL;
1071 uint32_t lenAtLastDelimiter = 0;
1072 char *prevText[4] = {0};
1073 uint16_t prevWidth[2] = {0};
1075#ifdef HAVE_UNICODE_SUPPORT
1086 prevText[3] = prevText[2];
1087 prevText[2] = prevText[1];
1088 prevText[1] = prevText[0];
1092 if (unicode ==
'\n') {
1095 lastDelimiter = NULL;
1098#ifdef HAVE_UNICODE_SUPPORT
1099 if (is_unicode && !unicode_ctx) {
1100 unicode_ctx = nbgl_getUnicodeFont(fontId);
1103 char_width = getCharWidth(font, unicode, is_unicode);
1104 if (char_width == 0) {
1110 lastDelimiter = prevText[0];
1111 lenAtLastDelimiter = textLen + 1;
1114 if ((width + char_width) > maxWidth) {
1117 if (currentNbLines < nbLines) {
1120 if (lastDelimiter != NULL) {
1121 *lastDelimiter++ =
'\n';
1122 text = lastDelimiter;
1123 lastDelimiter = NULL;
1124 textLen = lenAtLastDelimiter - 1;
1127 textLen += text - prevText[0];
1138 for (i = 0; i < 2; i++) {
1139 if ((prevText[i + 1] != NULL)
1140 && ((prevWidth[i] + (3 * getCharWidth(font,
'.',
false))) <= maxWidth)) {
1145 if (prevText[i + 1] != NULL) {
1146 memcpy(prevText[i + 1],
"...", 4);
1152 prevWidth[1] = prevWidth[0];
1153 prevWidth[0] = width;
1154 width += char_width;
1174 const char *origText,
1178 uint16_t reducedTextLen)
1181 uint16_t textLen = strlen(origText);
1183 uint8_t currentNbLines = 1;
1184 uint32_t i = 0, j = 0;
1187 if ((nbLines & 0x1) == 0) {
1191 while ((i < textLen) && (j < reducedTextLen)) {
1195 curChar = origText[i];
1197 char_width = getCharWidth(font, curChar,
false);
1198 if (char_width == 0) {
1199 reducedText[j] = curChar;
1206 if ((width + char_width) > maxWidth) {
1212 else if ((currentNbLines == ((nbLines / 2) + 1)) && ((width + char_width) > halfWidth)) {
1213 uint32_t halfFullWidth = (nbLines / 2) * maxWidth + halfWidth;
1214 uint32_t countDown = textLen;
1216 reducedText[j - 1] =
'.';
1217 reducedText[j] =
'.';
1218 reducedText[j + 1] =
'.';
1221 while (width < halfFullWidth) {
1223 curChar = origText[countDown];
1224 char_width = getCharWidth(font, curChar,
false);
1225 width += char_width;
1227 memcpy(&reducedText[j + 2], &origText[countDown + 1], textLen - countDown + 1);
1231 reducedText[j] = curChar;
1235 width += char_width;
1237 reducedText[j] =
'\0';
1240#ifdef HAVE_UNICODE_SUPPORT
1251 if (os_sched_current_task() != TASK_BOLOS_UX) {
1254 if ((unicodeCtx.
font != NULL) && (unicodeCtx.
font->
font_id == fontId)) {
1257#if defined(HAVE_LANGUAGE_PACK)
1259 const uint8_t *ptr = (
const uint8_t *) language_pack;
1263 unicodeCtx.
bitmap = (
const uint8_t *) (ptr + language_pack->bitmaps_offset);
1265 for (uint32_t i = 0; i < language_pack->nb_fonts; i++) {
1266 if (font->
font_id == fontId) {
1268 unicodeCtx.
font = font;
1275 unicodeCtx.
characters += language_pack->nb_characters;
1295 if (os_sched_current_task() != TASK_BOLOS_UX) {
1298#if defined(HAVE_LANGUAGE_PACK)
1301 uint32_t n = language_pack->nb_characters;
1302 if (characters == NULL) {
1307 for (
unsigned i = 0; i < n - 1; i++, characters++) {
1311 = (characters + 1)->bitmap_offset - characters->
bitmap_offset;
1335uint32_t nbgl_getUnicodeFontCharacterByteCount(
void)
1338 if (os_sched_current_task() != TASK_BOLOS_UX) {
1341#ifdef HAVE_LANGUAGE_PACK
1348#ifdef HAVE_LANGUAGE_PACK
1359 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