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 #ifdef SCREEN_SIZE_WALLET
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"
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"
64 #include "nbgl_font_open_sans_extrabold_11.inc"
65 #include "nbgl_font_open_sans_regular_11.inc"
66 #include "nbgl_font_open_sans_light_16.inc"
71 #include "nbgl_font_rom_struct.inc"
74 __attribute__((section(
"._nbgl_fonts_"))) const
unsigned int C_nbgl_fonts_count
75 = sizeof(C_nbgl_fonts) / sizeof(C_nbgl_fonts[0]);
77 #if (defined(HAVE_BOLOS) && !defined(BOLOS_OS_UPGRADER_APP))
78 #if !defined(HAVE_LANGUAGE_PACK)
81 #include "nbgl_font_unicode_rom_struct.inc"
86 const unsigned int C_unicode_characters_count
87 = (
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE)
88 /
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE[0]));
93 #ifdef BUILD_SCREENSHOTS
97 bool last_bold_state =
false;
100 bool hard_caesura =
false;
119 unsigned int i = C_nbgl_fonts_count;
124 if (
PIC_FONT(C_nbgl_fonts[i])->font_id == fontId) {
159 if ((cur_char >= 0xF0) && (*textLen >= 4)) {
160 unicode = (cur_char & 0x07) << 18;
161 unicode |= (*txt++ & 0x3F) << 12;
162 unicode |= (*txt++ & 0x3F) << 6;
163 unicode |= (*txt++ & 0x3F);
167 else if ((cur_char >= 0xE0) && (*textLen >= 3)) {
168 unicode = (cur_char & 0x0F) << 12;
169 unicode |= (*txt++ & 0x3F) << 6;
170 unicode |= (*txt++ & 0x3F);
175 else if ((cur_char >= 0xC2) && (*textLen >= 2)) {
176 unicode = (cur_char & 0x1F) << 6;
177 unicode |= (*txt++ & 0x3F);
183 *textLen = *textLen - (txt - *text);
196 static uint8_t getCharWidth(
const nbgl_font_t *font, uint32_t unicode,
bool is_unicode)
199 #ifdef HAVE_UNICODE_SUPPORT
201 = nbgl_getUnicodeFontCharacter(unicode);
202 if (!unicodeCharacter) {
212 if ((unicode < font->first_char) || (unicode > font->
last_char)) {
236 #ifdef BUILD_SCREENSHOTS
243 #ifdef HAVE_UNICODE_SUPPORT
247 #ifdef BUILD_SCREENSHOTS
249 bool next_bold_state = last_bold_state;
259 #ifdef HAVE_UNICODE_SUPPORT
260 if (is_unicode && !unicode_ctx) {
261 unicode_ctx = nbgl_getUnicodeFont(fontId);
264 if (unicode ==
'\n') {
265 if (breakOnLineEnd) {
273 else if (unicode ==
'\b') {
276 #ifdef HAVE_UNICODE_SUPPORT
280 #ifdef BUILD_SCREENSHOTS
281 next_bold_state =
true;
286 #ifdef HAVE_UNICODE_SUPPORT
290 #ifdef BUILD_SCREENSHOTS
291 next_bold_state =
false;
296 char_width = getCharWidth(font, unicode, is_unicode);
297 #ifdef BUILD_SCREENSHOTS
298 if (char_width != 0) {
300 last_bold_state = next_bold_state;
303 line_width += char_width;
305 if (line_width > max_width) {
306 max_width = line_width;
309 #ifdef BUILD_SCREENSHOTS
310 if (line_width != 0) {
313 last_nb_lines = nb_lines;
328 return getTextWidth(fontId, text,
true, 0xFFFF);
342 return getTextWidth(fontId, text,
true, maxLen);
354 return getTextWidth(fontId, text,
false, 0xFFFF);
370 #ifdef HAVE_UNICODE_SUPPORT
375 #ifdef HAVE_UNICODE_SUPPORT
376 if (is_unicode && !unicode_ctx) {
377 unicode_ctx = nbgl_getUnicodeFont(fontId);
381 return getCharWidth(font, unicode, is_unicode);
448 const char *origText = text;
453 else if (*text ==
'\n') {
458 return text - origText;
483 uint32_t lenAtLastDelimiter = 0, widthAtlastDelimiter = 0;
484 #ifdef HAVE_UNICODE_SUPPORT
497 #ifdef HAVE_UNICODE_SUPPORT
498 if (is_unicode && !unicode_ctx) {
499 unicode_ctx = nbgl_getUnicodeFont(fontId);
503 if ((unicode ==
'\f') || (unicode ==
'\n')) {
504 *len += curTextLen - textLen;
508 else if (unicode ==
'\b') {
511 #ifdef HAVE_UNICODE_SUPPORT
518 #ifdef HAVE_UNICODE_SUPPORT
523 *len += curTextLen - textLen;
527 char_width = getCharWidth(font, unicode, is_unicode);
528 if (char_width == 0) {
529 *len += curTextLen - textLen;
535 lenAtLastDelimiter = *len;
536 widthAtlastDelimiter = *width;
538 if ((*width + char_width) > maxWidth) {
539 if ((wrapping ==
true) && (widthAtlastDelimiter > 0)) {
540 *len = lenAtLastDelimiter + 1;
541 *width = widthAtlastDelimiter;
545 *len += curTextLen - textLen;
546 *width = *width + char_width;
574 const char *lastDelimiter = NULL;
575 uint32_t lenAtLastDelimiter = 0;
576 const char *origText = text;
577 const char *previousText;
578 #ifdef HAVE_UNICODE_SUPPORT
582 while ((textLen) && (maxNbLines > 0)) {
589 #ifdef HAVE_UNICODE_SUPPORT
590 if (is_unicode && !unicode_ctx) {
591 unicode_ctx = nbgl_getUnicodeFont(fontId);
596 lastDelimiter = text;
597 lenAtLastDelimiter = textLen;
601 if (unicode ==
'\n') {
604 if (maxNbLines == 0) {
611 else if (unicode ==
'\f') {
616 else if (unicode ==
'\b') {
619 #ifdef HAVE_UNICODE_SUPPORT
626 #ifdef HAVE_UNICODE_SUPPORT
634 char_width = getCharWidth(font, unicode, is_unicode);
635 if (char_width == 0) {
639 if ((width + char_width) > maxWidth) {
640 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
641 text = lastDelimiter;
642 lastDelimiter = NULL;
643 textLen = lenAtLastDelimiter;
646 textLen += text - previousText;
655 *len = text - origText;
656 return (maxNbLines == 0);
690 cur_char = text[textLen];
692 if (cur_char ==
'\n') {
698 if ((cur_char < font->first_char) || (cur_char > font->
last_char)) {
703 char_width = character->
width;
705 if ((*width + char_width) > maxWidth) {
709 *width = *width + char_width;
730 #ifdef SCREEN_SIZE_NANO
736 const char *lastDelimiter = NULL;
737 uint32_t lenAtLastDelimiter = 0;
738 const char *prevText = NULL;
739 #ifdef HAVE_UNICODE_SUPPORT
743 #ifdef BUILD_SCREENSHOTS
744 hard_caesura =
false;
748 bool next_bold_state = last_bold_state;
760 #ifdef HAVE_UNICODE_SUPPORT
761 if (is_unicode && !unicode_ctx) {
762 unicode_ctx = nbgl_getUnicodeFont(fontId);
768 lastDelimiter = prevText;
769 lenAtLastDelimiter = textLen;
772 if (unicode ==
'\f') {
773 #ifdef BUILD_SCREENSHOTS
781 else if (unicode ==
'\n') {
783 #if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
784 if (!(nbLines % 4)) {
791 lastDelimiter = NULL;
795 else if (unicode ==
'\b') {
798 #ifdef HAVE_UNICODE_SUPPORT
802 #ifdef BUILD_SCREENSHOTS
803 next_bold_state =
true;
808 #ifdef HAVE_UNICODE_SUPPORT
812 #ifdef BUILD_SCREENSHOTS
813 next_bold_state =
false;
819 char_width = getCharWidth(font, unicode, is_unicode);
820 if (char_width == 0) {
823 #ifdef BUILD_SCREENSHOTS
825 last_bold_state = next_bold_state;
829 if ((width + char_width) > maxWidth) {
830 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
831 text = lastDelimiter + 1;
832 lastDelimiter = NULL;
833 textLen = lenAtLastDelimiter;
837 #ifdef BUILD_SCREENSHOTS
844 #if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
845 if (!(nbLines % 4)) {
856 #ifdef SCREEN_SIZE_NANO
861 #ifdef BUILD_SCREENSHOTS
862 last_nb_lines = nbLines;
887 const char *lastDelimiter = NULL;
888 uint32_t lenAtLastDelimiter = 0;
889 const char *prevText = NULL;
890 #ifdef HAVE_UNICODE_SUPPORT
894 #ifdef BUILD_SCREENSHOTS
895 last_nb_lines = nbLines;
896 last_nb_pages = nbPages;
898 bool next_bold_state = last_bold_state;
909 #ifdef HAVE_UNICODE_SUPPORT
910 if (is_unicode && !unicode_ctx) {
911 unicode_ctx = nbgl_getUnicodeFont(fontId);
917 lastDelimiter = prevText;
918 lenAtLastDelimiter = textLen;
921 if (unicode ==
'\f') {
923 #ifdef BUILD_SCREENSHOTS
924 #ifdef SCREEN_SIZE_NANO
928 #ifdef SCREEN_SIZE_NANO
931 if (last_nb_lines < nbLines) {
932 last_nb_lines = nbLines;
940 else if (unicode ==
'\n') {
942 #ifdef BUILD_SCREENSHOTS
943 if (last_nb_lines < nbLines) {
944 last_nb_lines = nbLines;
947 if (nbLines == nbLinesPerPage && textLen) {
953 lastDelimiter = NULL;
957 else if (unicode ==
'\b') {
960 #ifdef HAVE_UNICODE_SUPPORT
964 #ifdef BUILD_SCREENSHOTS
965 next_bold_state =
true;
970 #ifdef HAVE_UNICODE_SUPPORT
974 #ifdef BUILD_SCREENSHOTS
975 next_bold_state =
false;
981 char_width = getCharWidth(font, unicode, is_unicode);
982 if (char_width == 0) {
986 #ifdef BUILD_SCREENSHOTS
988 last_bold_state = next_bold_state;
992 if ((width + char_width) > maxWidth) {
993 if (lastDelimiter != NULL) {
994 text = lastDelimiter + 1;
995 lastDelimiter = NULL;
996 textLen = lenAtLastDelimiter;
1003 #ifdef BUILD_SCREENSHOTS
1004 if (last_nb_lines < nbLines) {
1005 last_nb_lines = nbLines;
1008 if (nbLines == nbLinesPerPage) {
1014 width += char_width;
1017 #ifdef BUILD_SCREENSHOTS
1018 #ifdef SCREEN_SIZE_NANO
1023 if (last_nb_lines < nbLines) {
1024 last_nb_lines = nbLines;
1026 last_nb_pages = nbPages;
1066 char *lastDelimiter = NULL;
1067 uint32_t lenAtLastDelimiter = 0;
1068 char *prevText[4] = {0};
1071 #ifdef HAVE_UNICODE_SUPPORT
1082 prevText[3] = prevText[2];
1083 prevText[2] = prevText[1];
1084 prevText[1] = prevText[0];
1088 if (unicode ==
'\n') {
1091 lastDelimiter = NULL;
1094 #ifdef HAVE_UNICODE_SUPPORT
1095 if (is_unicode && !unicode_ctx) {
1096 unicode_ctx = nbgl_getUnicodeFont(fontId);
1099 char_width = getCharWidth(font, unicode, is_unicode);
1100 if (char_width == 0) {
1106 lastDelimiter = prevText[0];
1107 lenAtLastDelimiter = textLen + 1;
1110 if ((width + char_width) > maxWidth) {
1113 if (currentNbLines < nbLines) {
1116 if (lastDelimiter != NULL) {
1117 *lastDelimiter++ =
'\n';
1118 text = lastDelimiter;
1119 lastDelimiter = NULL;
1120 textLen = lenAtLastDelimiter - 1;
1123 textLen += text - prevText[0];
1134 for (i = 0; i < 2; i++) {
1135 if ((prevText[i + 1] != NULL)
1136 && ((prevWidth[i] + (3 * getCharWidth(font,
'.',
false))) <= maxWidth)) {
1141 if (prevText[i + 1] != NULL) {
1142 memcpy(prevText[i + 1],
"...", 4);
1148 prevWidth[1] = prevWidth[0];
1149 prevWidth[0] = width;
1150 width += char_width;
1170 const char *origText,
1177 uint16_t textLen = strlen(origText);
1180 uint32_t i = 0, j = 0;
1183 if ((nbLines & 0x1) == 0) {
1187 while ((i < textLen) && (j < reducedTextLen)) {
1191 curChar = origText[i];
1193 char_width = getCharWidth(font, curChar,
false);
1194 if (char_width == 0) {
1195 reducedText[j] = curChar;
1202 if ((width + char_width) > maxWidth) {
1208 else if ((currentNbLines == ((nbLines / 2) + 1)) && ((width + char_width) > halfWidth)) {
1209 uint32_t halfFullWidth = (nbLines / 2) * maxWidth + halfWidth;
1210 uint32_t countDown = textLen;
1212 reducedText[j - 1] =
'.';
1213 reducedText[j] =
'.';
1214 reducedText[j + 1] =
'.';
1217 while (width < halfFullWidth) {
1219 curChar = origText[countDown];
1220 char_width = getCharWidth(font, curChar,
false);
1221 width += char_width;
1223 memcpy(&reducedText[j + 2], &origText[countDown + 1], textLen - countDown + 1);
1227 reducedText[j] = curChar;
1231 width += char_width;
1233 reducedText[j] =
'\0';
1236 #ifdef HAVE_UNICODE_SUPPORT
1246 if ((unicodeCtx.
font != NULL) && (unicodeCtx.
font->
font_id == fontId)) {
1249 #if defined(HAVE_LANGUAGE_PACK)
1255 unicodeCtx.
bitmap = (
const uint8_t *) (ptr + language_pack->bitmaps_offset);
1257 for (uint32_t i = 0; i < language_pack->nb_fonts; i++) {
1258 if (font->
font_id == fontId) {
1260 unicodeCtx.
font = font;
1267 unicodeCtx.
characters += language_pack->nb_characters;
1286 #if defined(HAVE_LANGUAGE_PACK)
1289 uint32_t n = language_pack->nb_characters;
1290 if (characters == NULL) {
1295 for (
unsigned i = 0; i < n - 1; i++, characters++) {
1299 = (characters + 1)->bitmap_offset - characters->
bitmap_offset;
1323 uint32_t nbgl_getUnicodeFontCharacterByteCount(
void)
1325 #ifdef HAVE_LANGUAGE_PACK
1332 #ifdef HAVE_LANGUAGE_PACK
1343 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