Embedded SDK
Embedded SDK
Macros | Functions
nbgl_fonts.c File Reference
#include <string.h>
#include "app_config.h"
#include "nbgl_debug.h"
#include "nbgl_draw.h"
#include "nbgl_fonts.h"
#include "os_helpers.h"
#include "os_pic.h"
#include "nbgl_font_inter_regular_28.inc"
#include "nbgl_font_inter_semibold_28.inc"
#include "nbgl_font_inter_medium_36.inc"
#include "nbgl_font_inter_regular_28_1bpp.inc"
#include "nbgl_font_inter_semibold_28_1bpp.inc"
#include "nbgl_font_inter_medium_36_1bpp.inc"
#include "nbgl_font_rom_struct.inc"
Include dependency graph for nbgl_fonts.c:

Go to the source code of this file.

Macros

#define PIC_FONT(x)   ((nbgl_font_t const *) PIC(x))
 
#define BAGL_FONT_ID_MASK   0x0FFF
 
#define IS_WORD_DELIM(c)   (c == ' ' || c == '\n' || c == '\b' || c == '\f' || c == '-' || c == '_')
 

Functions

 __attribute__ ((section("._nbgl_fonts_"))) const
 return the non-unicode font corresponding to the given font ID More...
 
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, is_unicode is set to false. More...
 
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 More...
 
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, or maxLen characters have been parsed. More...
 
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) More...
 
uint8_t nbgl_getCharWidth (nbgl_font_id_e fontId, const char *text)
 return the width in pixels of the given UTF-8 character More...
 
uint8_t nbgl_getFontHeight (nbgl_font_id_e fontId)
 return the height in pixels of the font with the given font ID More...
 
uint8_t nbgl_getFontLineHeight (nbgl_font_id_e fontId)
 return the height in pixels of the line of font with the given font ID More...
 
uint16_t nbgl_getTextNbLines (const char *text)
 return the number of lines in the given text, according to the found '
's More...
 
uint16_t nbgl_getTextHeight (nbgl_font_id_e fontId, const char *text)
 return the height of the given multiline text, with the given font. More...
 
uint16_t nbgl_getTextLength (const char *text)
 return the number of bytes of the given text, excluding final '
' or '\0' More...
 
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 More...
 
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, with the given maximum width More...
 
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 More...
 
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 More...
 
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 maxWidth More...
 
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. More...
 
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 possible,. More...
 
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), in the given nbLines. More...
 

Detailed Description

Implementation of fonts array

Definition in file nbgl_fonts.c.

Macro Definition Documentation

◆ BAGL_FONT_ID_MASK

#define BAGL_FONT_ID_MASK   0x0FFF

Definition at line 24 of file nbgl_fonts.c.

◆ IS_WORD_DELIM

#define IS_WORD_DELIM (   c)    (c == ' ' || c == '\n' || c == '\b' || c == '\f' || c == '-' || c == '_')

Definition at line 26 of file nbgl_fonts.c.

◆ PIC_FONT

#define PIC_FONT (   x)    ((nbgl_font_t const *) PIC(x))

Definition at line 23 of file nbgl_fonts.c.

Function Documentation

◆ __attribute__()

__attribute__ ( (section("._nbgl_fonts_"))  ) const

return the non-unicode font corresponding to the given font ID

Parameters
fontIdfont ID
Returns
the found font or NULL

Definition at line 69 of file nbgl_fonts.c.

◆ nbgl_getCharWidth()

uint8_t nbgl_getCharWidth ( nbgl_font_id_e  fontId,
const char *  text 
)

return the width in pixels of the given UTF-8 character

Parameters
fontIdfont ID
textUTF-8 character
Returns
the width in pixels of the character

Definition at line 364 of file nbgl_fonts.c.

◆ nbgl_getFontHeight()

uint8_t nbgl_getFontHeight ( nbgl_font_id_e  fontId)

return the height in pixels of the font with the given font ID

Parameters
fontIdfont ID
Returns
the height in pixels

Definition at line 390 of file nbgl_fonts.c.

◆ nbgl_getFontLineHeight()

uint8_t nbgl_getFontLineHeight ( nbgl_font_id_e  fontId)

return the height in pixels of the line of font with the given font ID

Parameters
fontIdfont ID
Returns
the height in pixels

Definition at line 402 of file nbgl_fonts.c.

◆ nbgl_getSingleLineTextWidth()

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

Parameters
fontIdfont ID
texttext in UTF8
Returns
the width in pixels of the text

Definition at line 326 of file nbgl_fonts.c.

◆ nbgl_getSingleLineTextWidthInLen()

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, or maxLen characters have been parsed.

Parameters
fontIdfont ID
texttext in UTF8
maxLenmax number of bytes to parse
Returns
the width in pixels of the text

Definition at line 340 of file nbgl_fonts.c.

◆ nbgl_getTextHeight()

uint16_t nbgl_getTextHeight ( nbgl_font_id_e  fontId,
const char *  text 
)

return the height of the given multiline text, with the given font.

Parameters
fontIdfont ID
texttext to get the height from
Returns
the height in pixels

Definition at line 433 of file nbgl_fonts.c.

◆ nbgl_getTextHeightInWidth()

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.

Parameters
fontIdfont ID
texttext to get the height from
maxWidthmaximum width in which the text must fit
wrappingif true, lines are split on separators like spaces,
...
Returns
the height in pixels

Definition at line 1040 of file nbgl_fonts.c.

◆ nbgl_getTextLength()

uint16_t nbgl_getTextLength ( const char *  text)

return the number of bytes of the given text, excluding final '
' or '\0'

Note
'
' and '\0' are considered as end of string
Parameters
texttext to get the number of bytes from
Returns
the number of bytes in the given text

Definition at line 446 of file nbgl_fonts.c.

◆ nbgl_getTextMaxLenAndWidth()

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

Parameters
fontIdfont ID
textinput UTF-8 string, possibly multi-line (but only first line, before
, is used)
maxWidthmaximum width in bytes, if text is greater than that the parsing is escaped
len(output) consumed bytes in text fitting in maxWidth
width(output) set to maximum width in pixels in text fitting in maxWidth
wrappingif true, lines are split on separators like spaces,
...
Returns
true if maxWidth is reached, false otherwise

Definition at line 474 of file nbgl_fonts.c.

◆ nbgl_getTextMaxLenAndWidthFromEnd()

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

Note
works only with ASCII string
Parameters
fontIdfont ID
textinput ascii string, possibly multi-line (but only first line is handled)
maxWidthmaximum width in bytes, if text is greater than that the parsing is escaped
len(output) consumed bytes in text fitting in maxWidth
width(output) set to maximum width in pixels in text fitting in maxWidth
Returns
true if maxWidth is reached, false otherwise

Definition at line 673 of file nbgl_fonts.c.

◆ nbgl_getTextMaxLenInNbLines()

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, with the given maximum width

Parameters
fontIdfont ID
textinput UTF-8 string, possibly multi-line
maxWidthmaximum width in bytes, if text is greater than that the parsing is escaped
maxNbLinesmaximum number of lines, if text is greater than that the parsing is escaped
len(output) consumed bytes in text fitting in maxWidth
wrappingif true, lines are split on separators like spaces,
...
Returns
true if maxNbLines is reached, false otherwise

Definition at line 564 of file nbgl_fonts.c.

◆ nbgl_getTextNbLines()

uint16_t nbgl_getTextNbLines ( const char *  text)

return the number of lines in the given text, according to the found '
's

Parameters
texttext to get the number of lines from
Returns
the number of lines in the given text

Definition at line 414 of file nbgl_fonts.c.

◆ nbgl_getTextNbLinesInWidth()

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

Parameters
fontIdfont ID
textUTF-8 text to get the number of lines from
maxWidthmaximum width in which the text must fit
wrappingif true, lines are split on separators like spaces,
...
Returns
the number of lines in the given text

Definition at line 723 of file nbgl_fonts.c.

◆ nbgl_getTextNbPagesInWidth()

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 maxWidth

Parameters
fontIdfont ID
textUTF-8 text to get the number of pages from
nbLinesPerPagenumber of lines in a page
maxWidthmaximum width in which the text must fit
Returns
the number of pages in the given text

Definition at line 877 of file nbgl_fonts.c.

◆ nbgl_getTextWidth()

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)

Parameters
fontIdfont ID
texttext in UTF8
Returns
the width in pixels of the text

Definition at line 352 of file nbgl_fonts.c.

◆ nbgl_popUnicodeChar()

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, is_unicode is set to false.

Parameters
text(in/out) text to get character from. Updated after pop to the next UTF-8 char
textLen(in/out) remaining length in given text (before '
' or '\0')
is_unicode(out) set to true if it's a real unicode (not ASCII)
Returns
unicode (or ascii-7) value of the found character

Definition at line 142 of file nbgl_fonts.c.

◆ nbgl_textReduceOnNbLines()

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), in the given nbLines.

Note
the number of line must be odd
Parameters
fontIdfont ID
origText(input) ASCII string, must be single line
maxWidthmaximum width in pixels
nbLines(input) number of lines to reduce the text to. The middle of the text is replaced by ...
reducedText(output) reduced text
reducedTextLen(input) max size of reduced text

Definition at line 1169 of file nbgl_fonts.c.

◆ nbgl_textWrapOnNbLines()

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 possible,.

Parameters
fontIdfont ID
text(input/output) UTF-8 string, possibly multi-line
maxWidthmaximum width in pixels
nbLines(input) If the text doesn't fit in this number of lines, the last chars will be replaced by ...

Definition at line 1060 of file nbgl_fonts.c.