Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
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 "os_task.h"
#include "ux_loc.h"
#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
 
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.
 
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
 
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.
 
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)
 
uint8_t nbgl_getCharWidth (nbgl_font_id_e fontId, const char *text)
 return the width in pixels of the given UTF-8 character
 
uint8_t nbgl_getFontHeight (nbgl_font_id_e fontId)
 return the height in pixels of the font with the given font ID
 
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_getTextNbLines (const char *text)
 return the number of lines in the given text, according to the found '
's
 
uint16_t nbgl_getTextHeight (nbgl_font_id_e fontId, const char *text)
 return the height of the given multiline text, with the given font.
 
uint16_t nbgl_getTextLength (const char *text)
 return the number of bytes of the given text, excluding final '
' or '\0'
 
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
 
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
 
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
 
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
 
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
 
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.
 
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,.
 
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.
 
nbgl_unicode_ctx_tnbgl_getUnicodeFont (nbgl_font_id_e fontId)
 Get the font entry for the given font id (sparse font array support)
 
const nbgl_font_unicode_character_tnbgl_getUnicodeFontCharacter (uint32_t unicode)
 Get the unicode character object matching the given unicode (a unicode character is encoded on max of 4 bytes) in the current language.
 
uint32_t nbgl_getUnicodeFontCharacterByteCount (void)
 Get the bitmap byte count of the latest used unicode character. (the one returned by nbgl_getUnicodeFontCharacter)
 
void nbgl_refreshUnicodeFont (const LANGUAGE_PACK *lp)
 Function to be called when a change on the current language pack is notified by the OS, to be sure that the current unicodeCtx variable will be set again at next nbgl_getUnicodeFont() call.
 

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 23 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 25 of file nbgl_fonts.c.

◆ PIC_FONT

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

Definition at line 22 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 66 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 350 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 372 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 391 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 312 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 326 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 429 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 1005 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 442 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 470 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 654 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 552 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 410 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 704 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 850 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 338 of file nbgl_fonts.c.

◆ nbgl_getUnicodeFont()

nbgl_unicode_ctx_t * nbgl_getUnicodeFont ( nbgl_font_id_e  fontId)

Get the font entry for the given font id (sparse font array support)

Parameters
font_idfont ID (from nbgl_font_id_e)
Returns
the found unicode context structure or NULL if not found

Definition at line 1203 of file nbgl_fonts.c.

◆ nbgl_getUnicodeFontCharacter()

const nbgl_font_unicode_character_t * nbgl_getUnicodeFontCharacter ( uint32_t  unicode)

Get the unicode character object matching the given unicode (a unicode character is encoded on max of 4 bytes) in the current language.

Parameters
unicodethe unicode value of the character
Returns
the found character or NULL if not found

Definition at line 1245 of file nbgl_fonts.c.

◆ nbgl_getUnicodeFontCharacterByteCount()

uint32_t nbgl_getUnicodeFontCharacterByteCount ( void  )

Get the bitmap byte count of the latest used unicode character. (the one returned by nbgl_getUnicodeFontCharacter)

Returns
bitmap byte count of that character (0 for empty ones, ie space)

Definition at line 1282 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 126 of file nbgl_fonts.c.

◆ nbgl_refreshUnicodeFont()

void nbgl_refreshUnicodeFont ( const LANGUAGE_PACK *  lp)

Function to be called when a change on the current language pack is notified by the OS, to be sure that the current unicodeCtx variable will be set again at next nbgl_getUnicodeFont() call.

Parameters
lpnew language pack to apply

Definition at line 1298 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 1129 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 1025 of file nbgl_fonts.c.