Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
nbgl_fonts.h
Go to the documentation of this file.
1
7#ifndef NBGL_FONTS_H
8#define NBGL_FONTS_H
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14/*********************
15 * INCLUDES
16 *********************/
17#include "nbgl_types.h"
18#ifdef HAVE_LANGUAGE_PACK
19#include "ux_loc_nbgl.h"
20#endif // HAVE_LANGUAGE_PACK
21
22/*********************
23 * DEFINES
24 *********************/
25#define PIC_CHAR(x) ((const nbgl_font_character_t *) PIC(x))
26#define PIC_BMP(x) ((uint8_t const *) PIC(x))
27
28#ifndef HAVE_LANGUAGE_PACK
29#define LANGUAGE_PACK void
30#endif // HAVE_LANGUAGE_PACK
31
36#if SMALL_FONT_HEIGHT == 24
37#define SMALL_REGULAR_FONT BAGL_FONT_INTER_REGULAR_24px
38#define SMALL_BOLD_FONT BAGL_FONT_INTER_SEMIBOLD_24px
39#define LARGE_MEDIUM_FONT BAGL_FONT_INTER_MEDIUM_32px
40#define SMALL_REGULAR_1BPP_FONT BAGL_FONT_INTER_REGULAR_24px_1bpp
41#define SMALL_BOLD_1BPP_FONT BAGL_FONT_INTER_SEMIBOLD_24px_1bpp
42#define LARGE_MEDIUM_1BPP_FONT BAGL_FONT_INTER_MEDIUM_32px_1bpp
43#elif SMALL_FONT_HEIGHT == 28
44#define SMALL_REGULAR_FONT BAGL_FONT_INTER_REGULAR_28px
45#define SMALL_BOLD_FONT BAGL_FONT_INTER_SEMIBOLD_28px
46#define LARGE_MEDIUM_FONT BAGL_FONT_INTER_MEDIUM_36px
47#define SMALL_REGULAR_1BPP_FONT BAGL_FONT_INTER_REGULAR_28px_1bpp
48#define SMALL_BOLD_1BPP_FONT BAGL_FONT_INTER_SEMIBOLD_28px_1bpp
49#define LARGE_MEDIUM_1BPP_FONT BAGL_FONT_INTER_MEDIUM_36px_1bpp
50#elif SMALL_FONT_HEIGHT == 18
51#define SMALL_REGULAR_FONT BAGL_FONT_NANOTEXT_MEDIUM_18px_1bpp
52#define SMALL_BOLD_FONT BAGL_FONT_NANOTEXT_BOLD_18px_1bpp
53#define LARGE_MEDIUM_FONT BAGL_FONT_NANODISPLAY_SEMIBOLD_24px_1bpp
54#define SMALL_REGULAR_1BPP_FONT BAGL_FONT_NANOTEXT_MEDIUM_18px_1bpp
55#define SMALL_BOLD_1BPP_FONT BAGL_FONT_NANOTEXT_BOLD_18px_1bpp
56#define LARGE_MEDIUM_1BPP_FONT BAGL_FONT_NANODISPLAY_SEMIBOLD_24px_1bpp
57#endif // SMALL_FONT_HEIGHT
58
59/**********************
60 * TYPEDEFS
61 **********************/
62
67// WARNING: please DON'T CHANGE the order/values of the fields below!
68// (otherwise python tools that generate data will need to be modified too)
69typedef struct {
70 uint32_t bitmap_offset;
71 uint32_t encoding : 1;
72 uint32_t width : 6;
73 uint32_t x_min_offset : 4;
74 uint32_t y_min_offset : 6;
75 uint32_t x_max_offset : 4;
76 uint32_t y_max_offset : 6;
78
83typedef struct {
84 uint32_t bitmap_len;
85 uint8_t font_id;
86 uint8_t bpp;
87 uint8_t height;
88 uint8_t line_height;
89 uint8_t char_kerning;
90 uint8_t crop;
91 uint8_t y_min;
92 uint8_t
94 uint8_t
97 *const characters;
98 uint8_t const *bitmap;
100
101#define BAGL_ENCODING_LATIN1 0
102#define BAGL_ENCODING_UTF8 1
103#define BAGL_ENCODING_DEFAULT BAGL_ENCODING_UTF8
104
109// WARNING: please DON'T CHANGE the order of the fields below!
110// (otherwise python tools that generate data will need to be modified too)
111typedef struct {
112 uint32_t char_unicode : 21;
113 uint32_t encoding : 1;
114 uint32_t width : 6;
115 uint32_t x_min_offset : 4;
116 uint32_t y_min_offset : 6;
117 uint32_t x_max_offset : 4;
118 uint32_t y_max_offset : 6;
119 uint32_t bitmap_offset : 16;
125typedef struct {
126 uint16_t bitmap_len;
127 uint8_t font_id;
128 uint8_t bpp;
129 uint8_t height;
130 uint8_t line_height;
131 uint8_t char_kerning;
132 uint8_t crop;
133 uint8_t y_min;
134 uint8_t unused[3];
135#if !defined(HAVE_LANGUAGE_PACK)
136 // When using language packs, those 2 pointers does not exists
138 *const characters;
139 uint8_t const *bitmap;
140#endif
142
164
171
172/**********************
173 * GLOBAL PROTOTYPES
174 **********************/
176uint16_t nbgl_getSingleLineTextWidth(nbgl_font_id_e fontId, const char *text);
177uint16_t nbgl_getSingleLineTextWidthInLen(nbgl_font_id_e fontId, const char *text, uint16_t maxLen);
178uint16_t nbgl_getTextWidth(nbgl_font_id_e fontId, const char *text);
179uint8_t nbgl_getCharWidth(nbgl_font_id_e fontId, const char *text);
180uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId);
182uint16_t nbgl_getTextNbLines(const char *text);
183uint16_t nbgl_getTextHeight(nbgl_font_id_e fontId, const char *text);
184uint16_t nbgl_getTextLength(const char *text);
186 const char *text,
187 uint16_t maxWidth,
188 uint16_t *len,
189 uint16_t *width,
190 bool wrapping);
192 const char *text,
193 uint16_t maxWidth,
194 bool wrapping);
196 const char *text,
197 uint16_t maxWidth,
198 bool wrapping);
200 const char *text,
201 uint16_t maxWidth,
202 uint16_t *len,
203 uint16_t *width);
205 const char *text,
206 uint16_t maxWidth,
207 uint16_t maxNbLines,
208 uint16_t *len,
209 bool wrapping);
210void nbgl_textWrapOnNbLines(nbgl_font_id_e fontId, char *text, uint16_t maxWidth, uint8_t nbLines);
212 const char *origText,
213 uint16_t maxWidth,
214 uint8_t nbLines,
215 char *reducedText,
216 uint16_t reducedTextLen);
218 const char *text,
219 uint8_t nbLinesPerPage,
220 uint16_t maxWidth);
221
222uint32_t nbgl_popUnicodeChar(const uint8_t **text, uint16_t *text_length, bool *is_unicode);
223#ifdef HAVE_UNICODE_SUPPORT
224nbgl_unicode_ctx_t *nbgl_getUnicodeFont(nbgl_font_id_e font_id);
225const nbgl_font_unicode_character_t *nbgl_getUnicodeFontCharacter(uint32_t unicode);
226uint32_t nbgl_getUnicodeFontCharacterByteCount(void);
227void nbgl_refreshUnicodeFont(const LANGUAGE_PACK *lp);
228#endif // HAVE_UNICODE_SUPPORT
229
230/**********************
231 * MACROS
232 **********************/
233#define IS_UNICODE(__value) ((__value) > 0xF0)
234
235#ifdef __cplusplus
236} /* extern "C" */
237#endif
238
239#endif /* NBGL_FONTS_H */
struct nbgl_unicode_ctx_s nbgl_unicode_ctx_t
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
Definition nbgl_fonts.c:476
uint16_t nbgl_getTextNbLines(const char *text)
return the number of lines in the given text, according to the found ' 's
Definition nbgl_fonts.c:416
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...
Definition nbgl_fonts.c:879
uint32_t nbgl_popUnicodeChar(const uint8_t **text, uint16_t *text_length, bool *is_unicode)
Get the coming unicode value on the given UTF-8 string. If the value is a simple ASCII character,...
Definition nbgl_fonts.c:144
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
Definition nbgl_fonts.c:328
uint8_t nbgl_getCharWidth(nbgl_font_id_e fontId, const char *text)
return the width in pixels of the given UTF-8 character
Definition nbgl_fonts.c:366
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,...
Definition nbgl_fonts.c:566
nbgl_font_id_e
Definition nbgl_fonts.h:143
@ BAGL_FONT_OPEN_SANS_REGULAR_11px_1bpp
Definition nbgl_fonts.h:152
@ BAGL_FONT_INTER_REGULAR_28px_1bpp
Definition nbgl_fonts.h:156
@ BAGL_FONT_NANOTEXT_MEDIUM_18px_1bpp
Definition nbgl_fonts.h:159
@ BAGL_FONT_INTER_SEMIBOLD_28px
Definition nbgl_fonts.h:154
@ BAGL_FONT_INTER_REGULAR_24px_1bpp
Definition nbgl_fonts.h:147
@ BAGL_FONT_OPEN_SANS_EXTRABOLD_11px_1bpp
Definition nbgl_fonts.h:150
@ BAGL_FONT_INTER_REGULAR_24px
Definition nbgl_fonts.h:144
@ BAGL_FONT_INTER_REGULAR_28px
Definition nbgl_fonts.h:153
@ BAGL_FONT_INTER_MEDIUM_32px
Definition nbgl_fonts.h:146
@ BAGL_FONT_INTER_MEDIUM_36px
Definition nbgl_fonts.h:155
@ BAGL_FONT_INTER_MEDIUM_36px_1bpp
Definition nbgl_fonts.h:158
@ BAGL_FONT_NANODISPLAY_SEMIBOLD_24px_1bpp
Definition nbgl_fonts.h:161
@ BAGL_FONT_INTER_SEMIBOLD_24px
Definition nbgl_fonts.h:145
@ BAGL_FONT_INTER_MEDIUM_32px_1bpp
Definition nbgl_fonts.h:149
@ BAGL_FONT_OPEN_SANS_LIGHT_16px_1bpp
Definition nbgl_fonts.h:151
@ BAGL_FONT_LAST
Definition nbgl_fonts.h:162
@ BAGL_FONT_INTER_SEMIBOLD_24px_1bpp
Definition nbgl_fonts.h:148
@ BAGL_FONT_NANOTEXT_BOLD_18px_1bpp
Definition nbgl_fonts.h:160
@ BAGL_FONT_INTER_SEMIBOLD_28px_1bpp
Definition nbgl_fonts.h:157
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
Definition nbgl_fonts.c:675
uint8_t nbgl_getFontHeight(nbgl_font_id_e fontId)
return the height in pixels of the font with the given font ID
Definition nbgl_fonts.c:392
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),...
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)
Definition nbgl_fonts.c:354
#define LANGUAGE_PACK
Definition nbgl_fonts.h:29
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.
uint16_t nbgl_getTextLength(const char *text)
return the number of bytes of the given text, excluding final ' ' or '\0'
Definition nbgl_fonts.c:448
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
Definition nbgl_fonts.c:725
const nbgl_font_t * nbgl_getFont(nbgl_font_id_e fontId)
uint16_t nbgl_getTextHeight(nbgl_font_id_e fontId, const char *text)
return the height of the given multiline text, with the given font.
Definition nbgl_fonts.c:435
uint8_t nbgl_getFontLineHeight(nbgl_font_id_e fontId)
return the height in pixels of the line of font with the given font ID
Definition nbgl_fonts.c:404
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,...
Definition nbgl_fonts.c:342
common types for Graphical Library
fonts nicknames to be used for various wallet size targets (non-Nano)
Definition nbgl_fonts.h:69
uint32_t width
width of character in pixels
Definition nbgl_fonts.h:72
uint32_t encoding
method used to encode bitmap data
Definition nbgl_fonts.h:71
uint32_t x_min_offset
x_min = x_min_offset
Definition nbgl_fonts.h:73
uint32_t bitmap_offset
offset of this character in chars buffer
Definition nbgl_fonts.h:70
uint32_t y_min_offset
y_min = (y_min + y_min_offset)
Definition nbgl_fonts.h:74
uint32_t x_max_offset
x_max = width - x_max_offset
Definition nbgl_fonts.h:75
uint32_t y_max_offset
y_max = (height - y_max_offset)
Definition nbgl_fonts.h:76
structure defining an ASCII font
Definition nbgl_fonts.h:83
uint8_t char_kerning
kerning for the font
Definition nbgl_fonts.h:89
uint8_t crop
If false, x_min_offset+y_min_offset=bytes to skip.
Definition nbgl_fonts.h:90
uint8_t first_char
ASCII code of the first character in bitmap and in characters fields.
Definition nbgl_fonts.h:93
uint8_t font_id
ID of the font, from nbgl_font_id_e.
Definition nbgl_fonts.h:85
uint32_t bitmap_len
Size in bytes of the associated bitmap.
Definition nbgl_fonts.h:84
uint8_t const * bitmap
array containing bitmaps of all characters
Definition nbgl_fonts.h:98
const nbgl_font_character_t *const characters
array containing definitions of all characters
Definition nbgl_fonts.h:97
uint8_t height
height of all characters in pixels
Definition nbgl_fonts.h:87
uint8_t line_height
height of a line for all characters in pixels
Definition nbgl_fonts.h:88
uint8_t last_char
ASCII code of the last character in bitmap and in characters fields.
Definition nbgl_fonts.h:95
uint8_t y_min
Most top Y coordinate of any char in the font.
Definition nbgl_fonts.h:91
uint8_t bpp
number of bits per pixels
Definition nbgl_fonts.h:86
structure defining a unicode character (except the bitmap)
Definition nbgl_fonts.h:111
uint32_t encoding
method used to encode bitmap data
Definition nbgl_fonts.h:113
uint32_t char_unicode
plane value from 0 to 16 then 16-bit code.
Definition nbgl_fonts.h:112
uint32_t width
width of character in pixels
Definition nbgl_fonts.h:114
uint32_t x_min_offset
x_min = x_min_offset
Definition nbgl_fonts.h:115
uint32_t y_min_offset
y_min = (y_min + y_min_offset)
Definition nbgl_fonts.h:116
uint32_t y_max_offset
y_max = (height - y_max_offset)
Definition nbgl_fonts.h:118
uint32_t x_max_offset
x_max = width - x_max_offset
Definition nbgl_fonts.h:117
uint32_t bitmap_offset
offset of this character in chars buffer
Definition nbgl_fonts.h:119
structure defining a unicode font
Definition nbgl_fonts.h:125
uint8_t crop
If false, x_min_offset+y_min_offset=bytes to skip.
Definition nbgl_fonts.h:132
uint8_t y_min
Most top Y coordinate of any char in the font.
Definition nbgl_fonts.h:133
uint8_t const * bitmap
Definition nbgl_fonts.h:139
uint16_t bitmap_len
Size in bytes of all characters bitmaps.
Definition nbgl_fonts.h:126
uint8_t height
height of all characters in pixels
Definition nbgl_fonts.h:129
uint8_t font_id
ID of the font, from nbgl_font_id_e.
Definition nbgl_fonts.h:127
uint8_t char_kerning
kerning for the font
Definition nbgl_fonts.h:131
const nbgl_font_unicode_character_t *const characters
array containing definitions of all characters
Definition nbgl_fonts.h:138
uint8_t line_height
height of a line for all characters in pixels
Definition nbgl_fonts.h:130
uint8_t bpp
Number of bits per pixels, (interpreted as nbgl_bpp_t)
Definition nbgl_fonts.h:128
const nbgl_font_unicode_character_t * characters
Definition nbgl_fonts.h:167
const nbgl_font_unicode_t * font
Definition nbgl_fonts.h:166
uint32_t unicode_character_byte_count
Definition nbgl_fonts.h:169
const uint8_t * bitmap
Definition nbgl_fonts.h:168