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 == 11
62#include "nbgl_font_open_sans_extrabold_11.inc"
63#include "nbgl_font_open_sans_regular_11.inc"
64#include "nbgl_font_open_sans_light_16.inc"
69#include "nbgl_font_rom_struct.inc"
72__attribute__((section(
"._nbgl_fonts_"))) const
unsigned int C_nbgl_fonts_count
73 = sizeof(C_nbgl_fonts) / sizeof(C_nbgl_fonts[0]);
75#if (defined(HAVE_BOLOS) && !defined(BOLOS_OS_UPGRADER_APP))
76#if !defined(HAVE_LANGUAGE_PACK)
79#include "nbgl_font_unicode_rom_struct.inc"
84const unsigned int C_unicode_characters_count
85 = (
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE)
86 /
sizeof(charactersOPEN_SANS_REGULAR_11PX_UNICODE[0]));
91#ifdef BUILD_SCREENSHOTS
95bool last_bold_state =
false;
98bool hard_caesura =
false;
117 unsigned int i = C_nbgl_fonts_count;
122 if (
PIC_FONT(C_nbgl_fonts[i])->font_id == fontId) {
157 if ((cur_char >= 0xF0) && (*textLen >= 4)) {
158 unicode = (cur_char & 0x07) << 18;
159 unicode |= (*txt++ & 0x3F) << 12;
160 unicode |= (*txt++ & 0x3F) << 6;
161 unicode |= (*txt++ & 0x3F);
165 else if ((cur_char >= 0xE0) && (*textLen >= 3)) {
166 unicode = (cur_char & 0x0F) << 12;
167 unicode |= (*txt++ & 0x3F) << 6;
168 unicode |= (*txt++ & 0x3F);
173 else if ((cur_char >= 0xC2) && (*textLen >= 2)) {
174 unicode = (cur_char & 0x1F) << 6;
175 unicode |= (*txt++ & 0x3F);
181 *textLen = *textLen - (txt - *text);
194static uint8_t getCharWidth(
const nbgl_font_t *font, uint32_t unicode,
bool is_unicode)
197#ifdef HAVE_UNICODE_SUPPORT
199 = nbgl_getUnicodeFontCharacter(unicode);
200 if (!unicodeCharacter) {
210 if ((unicode < font->first_char) || (unicode > font->
last_char)) {
234#ifdef BUILD_SCREENSHOTS
241#ifdef HAVE_UNICODE_SUPPORT
245#ifdef BUILD_SCREENSHOTS
247 bool next_bold_state = last_bold_state;
257#ifdef HAVE_UNICODE_SUPPORT
258 if (is_unicode && !unicode_ctx) {
259 unicode_ctx = nbgl_getUnicodeFont(fontId);
262 if (unicode ==
'\n') {
263 if (breakOnLineEnd) {
271 else if (unicode ==
'\b') {
274#ifdef HAVE_UNICODE_SUPPORT
278#ifdef BUILD_SCREENSHOTS
279 next_bold_state =
true;
284#ifdef HAVE_UNICODE_SUPPORT
288#ifdef BUILD_SCREENSHOTS
289 next_bold_state =
false;
294 char_width = getCharWidth(font, unicode, is_unicode);
295#ifdef BUILD_SCREENSHOTS
296 if (char_width != 0) {
298 last_bold_state = next_bold_state;
301 line_width += char_width;
303 if (line_width > max_width) {
304 max_width = line_width;
307#ifdef BUILD_SCREENSHOTS
308 if (line_width != 0) {
311 last_nb_lines = nb_lines;
326 return getTextWidth(fontId, text,
true, 0xFFFF);
340 return getTextWidth(fontId, text,
true, maxLen);
352 return getTextWidth(fontId, text,
false, 0xFFFF);
368#ifdef HAVE_UNICODE_SUPPORT
373#ifdef HAVE_UNICODE_SUPPORT
374 if (is_unicode && !unicode_ctx) {
375 unicode_ctx = nbgl_getUnicodeFont(fontId);
379 return getCharWidth(font, unicode, is_unicode);
446 const char *origText = text;
451 else if (*text ==
'\n') {
456 return text - origText;
481 uint32_t lenAtLastDelimiter = 0, widthAtlastDelimiter = 0;
482#ifdef HAVE_UNICODE_SUPPORT
495#ifdef HAVE_UNICODE_SUPPORT
496 if (is_unicode && !unicode_ctx) {
497 unicode_ctx = nbgl_getUnicodeFont(fontId);
501 if ((unicode ==
'\f') || (unicode ==
'\n')) {
502 *len += curTextLen - textLen;
506 else if (unicode ==
'\b') {
509#ifdef HAVE_UNICODE_SUPPORT
516#ifdef HAVE_UNICODE_SUPPORT
521 *len += curTextLen - textLen;
525 char_width = getCharWidth(font, unicode, is_unicode);
526 if (char_width == 0) {
527 *len += curTextLen - textLen;
533 lenAtLastDelimiter = *len;
534 widthAtlastDelimiter = *width;
536 if ((*width + char_width) > maxWidth) {
537 if ((wrapping ==
true) && (widthAtlastDelimiter > 0)) {
538 *len = lenAtLastDelimiter + 1;
539 *width = widthAtlastDelimiter;
543 *len += curTextLen - textLen;
544 *width = *width + char_width;
572 const char *lastDelimiter = NULL;
573 uint32_t lenAtLastDelimiter = 0;
574 const char *origText = text;
575 const char *previousText;
576#ifdef HAVE_UNICODE_SUPPORT
580 while ((textLen) && (maxNbLines > 0)) {
587#ifdef HAVE_UNICODE_SUPPORT
588 if (is_unicode && !unicode_ctx) {
589 unicode_ctx = nbgl_getUnicodeFont(fontId);
594 lastDelimiter = text;
595 lenAtLastDelimiter = textLen;
599 if (unicode ==
'\n') {
602 if (maxNbLines == 0) {
609 else if (unicode ==
'\f') {
614 else if (unicode ==
'\b') {
617#ifdef HAVE_UNICODE_SUPPORT
624#ifdef HAVE_UNICODE_SUPPORT
632 char_width = getCharWidth(font, unicode, is_unicode);
633 if (char_width == 0) {
637 if ((width + char_width) > maxWidth) {
638 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
639 text = lastDelimiter;
640 lastDelimiter = NULL;
641 textLen = lenAtLastDelimiter;
644 textLen += text - previousText;
653 *len = text - origText;
654 return (maxNbLines == 0);
688 cur_char = text[textLen];
690 if (cur_char ==
'\n') {
696 if ((cur_char < font->first_char) || (cur_char > font->
last_char)) {
701 char_width = character->
width;
703 if ((*width + char_width) > maxWidth) {
707 *width = *width + char_width;
728#ifdef SCREEN_SIZE_NANO
734 const char *lastDelimiter = NULL;
735 uint32_t lenAtLastDelimiter = 0;
736 const char *prevText = NULL;
737#ifdef HAVE_UNICODE_SUPPORT
741#ifdef BUILD_SCREENSHOTS
742 hard_caesura =
false;
746 bool next_bold_state = last_bold_state;
758#ifdef HAVE_UNICODE_SUPPORT
759 if (is_unicode && !unicode_ctx) {
760 unicode_ctx = nbgl_getUnicodeFont(fontId);
766 lastDelimiter = prevText;
767 lenAtLastDelimiter = textLen;
770 if (unicode ==
'\f') {
771#ifdef BUILD_SCREENSHOTS
779 else if (unicode ==
'\n') {
781#if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
782 if (!(nbLines % 4)) {
789 lastDelimiter = NULL;
793 else if (unicode ==
'\b') {
796#ifdef HAVE_UNICODE_SUPPORT
800#ifdef BUILD_SCREENSHOTS
801 next_bold_state =
true;
806#ifdef HAVE_UNICODE_SUPPORT
810#ifdef BUILD_SCREENSHOTS
811 next_bold_state =
false;
817 char_width = getCharWidth(font, unicode, is_unicode);
818 if (char_width == 0) {
821#ifdef BUILD_SCREENSHOTS
823 last_bold_state = next_bold_state;
827 if ((width + char_width) > maxWidth) {
828 if ((wrapping ==
true) && (lastDelimiter != NULL)) {
829 text = lastDelimiter + 1;
830 lastDelimiter = NULL;
831 textLen = lenAtLastDelimiter;
835#ifdef BUILD_SCREENSHOTS
842#if defined(BUILD_SCREENSHOTS) && defined(SCREEN_SIZE_NANO)
843 if (!(nbLines % 4)) {
854#ifdef SCREEN_SIZE_NANO
859#ifdef BUILD_SCREENSHOTS
860 last_nb_lines = nbLines;
885 const char *lastDelimiter = NULL;
886 uint32_t lenAtLastDelimiter = 0;
887 const char *prevText = NULL;
888#ifdef HAVE_UNICODE_SUPPORT
892#ifdef BUILD_SCREENSHOTS
893 last_nb_lines = nbLines;
894 last_nb_pages = nbPages;
896 bool next_bold_state = last_bold_state;
907#ifdef HAVE_UNICODE_SUPPORT
908 if (is_unicode && !unicode_ctx) {
909 unicode_ctx = nbgl_getUnicodeFont(fontId);
915 lastDelimiter = prevText;
916 lenAtLastDelimiter = textLen;
919 if (unicode ==
'\f') {
921#ifdef BUILD_SCREENSHOTS
922#ifdef SCREEN_SIZE_NANO
926#ifdef SCREEN_SIZE_NANO
929 if (last_nb_lines < nbLines) {
930 last_nb_lines = nbLines;
938 else if (unicode ==
'\n') {
940#ifdef BUILD_SCREENSHOTS
941 if (last_nb_lines < nbLines) {
942 last_nb_lines = nbLines;
945 if (nbLines == nbLinesPerPage && textLen) {
951 lastDelimiter = NULL;
955 else if (unicode ==
'\b') {
958#ifdef HAVE_UNICODE_SUPPORT
962#ifdef BUILD_SCREENSHOTS
963 next_bold_state =
true;
968#ifdef HAVE_UNICODE_SUPPORT
972#ifdef BUILD_SCREENSHOTS
973 next_bold_state =
false;
979 char_width = getCharWidth(font, unicode, is_unicode);
980 if (char_width == 0) {
984#ifdef BUILD_SCREENSHOTS
986 last_bold_state = next_bold_state;
990 if ((width + char_width) > maxWidth) {
991 if (lastDelimiter != NULL) {
992 text = lastDelimiter + 1;
993 lastDelimiter = NULL;
994 textLen = lenAtLastDelimiter;
1001#ifdef BUILD_SCREENSHOTS
1002 if (last_nb_lines < nbLines) {
1003 last_nb_lines = nbLines;
1006 if (nbLines == nbLinesPerPage) {
1012 width += char_width;
1015#ifdef BUILD_SCREENSHOTS
1016#ifdef SCREEN_SIZE_NANO
1021 if (last_nb_lines < nbLines) {
1022 last_nb_lines = nbLines;
1024 last_nb_pages = nbPages;
1064 char *lastDelimiter = NULL;
1065 uint32_t lenAtLastDelimiter = 0;
1066 char *prevText[4] = {0};
1069#ifdef HAVE_UNICODE_SUPPORT
1080 prevText[3] = prevText[2];
1081 prevText[2] = prevText[1];
1082 prevText[1] = prevText[0];
1086 if (unicode ==
'\n') {
1089 lastDelimiter = NULL;
1092#ifdef HAVE_UNICODE_SUPPORT
1093 if (is_unicode && !unicode_ctx) {
1094 unicode_ctx = nbgl_getUnicodeFont(fontId);
1097 char_width = getCharWidth(font, unicode, is_unicode);
1098 if (char_width == 0) {
1104 lastDelimiter = prevText[0];
1105 lenAtLastDelimiter = textLen + 1;
1108 if ((width + char_width) > maxWidth) {
1111 if (currentNbLines < nbLines) {
1114 if (lastDelimiter != NULL) {
1115 *lastDelimiter++ =
'\n';
1116 text = lastDelimiter;
1117 lastDelimiter = NULL;
1118 textLen = lenAtLastDelimiter - 1;
1121 textLen += text - prevText[0];
1132 for (i = 0; i < 2; i++) {
1133 if ((prevText[i + 1] != NULL)
1134 && ((prevWidth[i] + (3 * getCharWidth(font,
'.',
false))) <= maxWidth)) {
1139 if (prevText[i + 1] != NULL) {
1140 memcpy(prevText[i + 1],
"...", 4);
1146 prevWidth[1] = prevWidth[0];
1147 prevWidth[0] = width;
1148 width += char_width;
1168 const char *origText,
1175 uint16_t textLen = strlen(origText);
1178 uint32_t i = 0, j = 0;
1181 if ((nbLines & 0x1) == 0) {
1185 while ((i < textLen) && (j < reducedTextLen)) {
1189 curChar = origText[i];
1191 char_width = getCharWidth(font, curChar,
false);
1192 if (char_width == 0) {
1193 reducedText[j] = curChar;
1200 if ((width + char_width) > maxWidth) {
1206 else if ((currentNbLines == ((nbLines / 2) + 1)) && ((width + char_width) > halfWidth)) {
1207 uint32_t halfFullWidth = (nbLines / 2) * maxWidth + halfWidth;
1208 uint32_t countDown = textLen;
1210 reducedText[j - 1] =
'.';
1211 reducedText[j] =
'.';
1212 reducedText[j + 1] =
'.';
1215 while (width < halfFullWidth) {
1217 curChar = origText[countDown];
1218 char_width = getCharWidth(font, curChar,
false);
1219 width += char_width;
1221 memcpy(&reducedText[j + 2], &origText[countDown + 1], textLen - countDown + 1);
1225 reducedText[j] = curChar;
1229 width += char_width;
1231 reducedText[j] =
'\0';
1234#ifdef HAVE_UNICODE_SUPPORT
1244 if ((unicodeCtx.
font != NULL) && (unicodeCtx.
font->
font_id == fontId)) {
1247#if defined(HAVE_LANGUAGE_PACK)
1253 unicodeCtx.
bitmap = (
const uint8_t *) (ptr + language_pack->bitmaps_offset);
1255 for (uint32_t i = 0; i < language_pack->nb_fonts; i++) {
1256 if (font->
font_id == fontId) {
1258 unicodeCtx.
font = font;
1265 unicodeCtx.
characters += language_pack->nb_characters;
1284#if defined(HAVE_LANGUAGE_PACK)
1287 uint32_t n = language_pack->nb_characters;
1288 if (characters == NULL) {
1293 for (
unsigned i = 0; i < n - 1; i++, characters++) {
1297 = (characters + 1)->bitmap_offset - characters->
bitmap_offset;
1321uint32_t nbgl_getUnicodeFontCharacterByteCount(
void)
1323#ifdef HAVE_LANGUAGE_PACK
1330#ifdef HAVE_LANGUAGE_PACK
1341 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