Skip to content

Commit

Permalink
Only LNX/LNS+ have a limitation of 4 lines per page
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorais-ledger committed Apr 30, 2024
1 parent 2b2a999 commit 6b1bd45
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions lib_nbgl/src/nbgl_fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,7 @@ bool nbgl_getTextMaxLenInNbLines(nbgl_font_id_e fontId,

// if \n, reset width
if (unicode == '\n') {
if (width != 0) {
maxNbLines--;
}
maxNbLines--;
width = 0;
continue;
}
Expand Down Expand Up @@ -713,13 +711,17 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
uint16_t maxWidth,
bool wrapping)
{
const nbgl_font_t *font = nbgl_getFont(fontId);
uint16_t width = 0;
uint16_t nbLines = 0;
uint16_t textLen = strlen(text);
const char *lastDelimiter = NULL;
uint32_t lenAtLastDelimiter = 0;
const char *prevText = NULL;
const nbgl_font_t *font = nbgl_getFont(fontId);
uint16_t width = 0;
#ifdef SCREEN_SIZE_NANO
uint16_t nbLines = 0;
#else // SCREEN_SIZE_NANO
uint16_t nbLines = 1;
#endif // SCREEN_SIZE_NANO
uint16_t textLen = strlen(text);
const char *lastDelimiter = NULL;
uint32_t lenAtLastDelimiter = 0;
const char *prevText = NULL;

#ifdef BUILD_SCREENSHOTS
last_nb_lines = 0;
Expand Down Expand Up @@ -751,9 +753,13 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
#ifdef BUILD_SCREENSHOTS
// Continue parsing the string, to find the real nb_lines & nb_pages!
++last_nb_pages;
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
#endif // SCREEN_SIZE_NANO
++nbLines;
#ifdef SCREEN_SIZE_NANO
}
#endif // SCREEN_SIZE_NANO
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
Expand All @@ -766,18 +772,18 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
}
// if \n, increment the number of lines
else if (unicode == '\n') {
if (width != 0) {
nbLines++;
nbLines++;
#ifdef BUILD_SCREENSHOTS
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
if (nbLines == 4) {
++last_nb_pages;
nbLines = 0;
}
#endif // BUILD_SCREENSHOTS
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
#ifdef SCREEN_SIZE_NANO
if (nbLines == 4) {
++last_nb_pages;
nbLines = 0;
}
#endif // SCREEN_SIZE_NANO
#endif // BUILD_SCREENSHOTS
width = 0;
lastDelimiter = NULL;
continue;
Expand Down Expand Up @@ -832,16 +838,19 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
#ifdef SCREEN_SIZE_NANO
if (nbLines == 4) {
++last_nb_pages;
nbLines = 0;
}
#endif // SCREEN_SIZE_NANO
#endif // BUILD_SCREENSHOTS
}
else {
width += char_width;
}
}
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
++nbLines;
}
Expand All @@ -850,6 +859,7 @@ uint16_t nbgl_getTextNbLinesInWidth(nbgl_font_id_e fontId,
last_nb_lines = nbLines;
}
#endif // BUILD_SCREENSHOTS
#endif // SCREEN_SIZE_NANO
return nbLines;
}

Expand Down Expand Up @@ -905,9 +915,13 @@ uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId,
if (unicode == '\f') {
nbPages++;
#ifdef BUILD_SCREENSHOTS
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
#endif // SCREEN_SIZE_NANO
++nbLines;
#ifdef SCREEN_SIZE_NANO
}
#endif // SCREEN_SIZE_NANO
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
Expand All @@ -918,18 +932,17 @@ uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId,
}
// if \n, increment the number of lines
else if (unicode == '\n') {
if (width != 0) {
nbLines++;
nbLines++;
#ifdef BUILD_SCREENSHOTS
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
#endif // BUILD_SCREENSHOTS
if (nbLines == nbLinesPerPage && textLen) {
nbPages++;
nbLines = 0;
}
if (nbLines == nbLinesPerPage && textLen) {
nbPages++;
nbLines = 0;
}

width = 0;
lastDelimiter = NULL;
continue;
Expand Down Expand Up @@ -996,9 +1009,11 @@ uint8_t nbgl_getTextNbPagesInWidth(nbgl_font_id_e fontId,
}
}
#ifdef BUILD_SCREENSHOTS
#ifdef SCREEN_SIZE_NANO
if (width != 0) {
++nbLines;
}
#endif // SCREEN_SIZE_NANO
if (last_nb_lines < nbLines) {
last_nb_lines = nbLines;
}
Expand Down Expand Up @@ -1062,10 +1077,8 @@ void nbgl_textWrapOnNbLines(nbgl_font_id_e fontId, char *text, uint16_t maxWidth
unicode = nbgl_popUnicodeChar((const uint8_t **) &text, &textLen, &is_unicode);
// if \n, reset width
if (unicode == '\n') {
if (width != 0) {
currentNbLines++;
}
width = 0;
width = 0;
currentNbLines++;
lastDelimiter = NULL;
continue;
}
Expand Down

0 comments on commit 6b1bd45

Please sign in to comment.