lv_font.h
API reference for lv_font.h
Functions
lv_font_set_kerning
Configure the use of kerning information stored in a font
void lv_font_set_kerning(lv_font_t *font, lv_font_kerning_t kerning)| Name | Type | Description |
|---|---|---|
font | lv_font_t * | pointer to a font |
kerning | lv_font_kerning_t | LV_FONT_KERNING_NORMAL (default) or LV_FONT_KERNING_NONE |
lv_font_get_glyph_bitmap
Return with the bitmap of a font. It always converts the normal fonts to A8 format in a draw_buf with LV_DRAW_BUF_ALIGN and LV_DRAW_BUF_STRIDE_ALIGN
const void * lv_font_get_glyph_bitmap(lv_font_glyph_dsc_t *g_dsc, lv_draw_buf_t *draw_buf)| Name | Type | Description |
|---|---|---|
g_dsc | lv_font_glyph_dsc_t * | the glyph descriptor including which font to use, which supply the glyph_index and the format. |
draw_buf | lv_draw_buf_t * | a draw buffer that can be used to store the bitmap of the glyph. May be NULL. Fonts returning an image source do not use it. |
Returns: const void * — pointer to the glyph's data. It can be a draw buffer for bitmap fonts or an image source for imgfonts.
You must call lv_font_get_glyph_dsc() to get g_dsc (lv_font_glyph_dsc_t) before you can call this function.
lv_font_get_glyph_static_bitmap
Return the bitmap as it is. It works only if the font stores the bitmap in a non-volatile memory.
const void * lv_font_get_glyph_static_bitmap(lv_font_glyph_dsc_t *g_dsc)| Name | Type | Description |
|---|---|---|
g_dsc | lv_font_glyph_dsc_t * | the glyph descriptor including which font to use, which supply the glyph_index and the format. |
Returns: const void * — the bitmap as it is
lv_font_get_glyph_dsc
Get the descriptor of a glyph
bool lv_font_get_glyph_dsc(const lv_font_t *font, lv_font_glyph_dsc_t *dsc_out, uint32_t letter, uint32_t letter_next)| Name | Type | Description |
|---|---|---|
font | const lv_font_t * | pointer to font |
dsc_out | lv_font_glyph_dsc_t * | store the result descriptor here |
letter | uint32_t | a UNICODE letter code |
letter_next | uint32_t | the next letter after letter. Used for kerning |
Returns: bool — true: descriptor is successfully loaded into dsc_out. false: the letter was not found, no data is loaded to dsc_out
lv_font_get_glyph_width
Get the width of a glyph with kerning
uint16_t lv_font_get_glyph_width(const lv_font_t *font, uint32_t letter, uint32_t letter_next)| Name | Type | Description |
|---|---|---|
font | const lv_font_t * | pointer to a font |
letter | uint32_t | a UNICODE letter |
letter_next | uint32_t | the next letter after letter. Used for kerning |
Returns: uint16_t — the width of the glyph
lv_font_get_line_height
Get the line height of a font. All characters fit into this height
int32_t lv_font_get_line_height(const lv_font_t *font)| Name | Type | Description |
|---|---|---|
font | const lv_font_t * | pointer to a font |
Returns: int32_t — the height of a font
lv_font_get_default
Get the default font, defined by LV_FONT_DEFAULT
const lv_font_t * lv_font_get_default(void)Returns: const lv_font_t * — return pointer to the default font
lv_font_glyph_release_draw_data
Release the bitmap of a font.
void lv_font_glyph_release_draw_data(lv_font_glyph_dsc_t *g_dsc)| Name | Type | Description |
|---|---|---|
g_dsc | lv_font_glyph_dsc_t * | the glyph descriptor including which font to use, which supply the glyph_index and the format. |
You must call lv_font_get_glyph_dsc() to get g_dsc (lv_font_glyph_dsc_t) before you can call this function.
lv_font_info_is_equal
Compare font information.
bool lv_font_info_is_equal(const lv_font_info_t *ft_info_1, const lv_font_info_t *ft_info_2)| Name | Type | Description |
|---|---|---|
ft_info_1 | const lv_font_info_t * | font information 1. |
ft_info_2 | const lv_font_info_t * | font information 2. |
Returns: bool — return true if the fonts are equal.
lv_font_has_static_bitmap
Checks if a font has a static rendering bitmap.
bool lv_font_has_static_bitmap(const lv_font_t *font)| Name | Type | Description |
|---|---|---|
font | const lv_font_t * | pointer to a font |
Returns: bool — return true if the font has a bitmap generated for static rendering.
Enums
lv_font_glyph_format_t
The font format.
| Name | Value | Description |
|---|---|---|
LV_FONT_GLYPH_FORMAT_NONE | 0 | Maybe not visible Legacy simple formats |
LV_FONT_GLYPH_FORMAT_A1 | 0x01 | 1 bit per pixel |
LV_FONT_GLYPH_FORMAT_A2 | 0x02 | 2 bit per pixel |
LV_FONT_GLYPH_FORMAT_A3 | 0x03 | 3 bit per pixel |
LV_FONT_GLYPH_FORMAT_A4 | 0x04 | 4 bit per pixel |
LV_FONT_GLYPH_FORMAT_A8 | 0x08 | 8 bit per pixel |
LV_FONT_GLYPH_FORMAT_IMAGE | 0x19 | Image format Advanced formats |
LV_FONT_GLYPH_FORMAT_VECTOR | 0x1A | Vectorial format |
LV_FONT_GLYPH_FORMAT_SVG | 0x1B | SVG format |
LV_FONT_GLYPH_FORMAT_CUSTOM | 0xFF | Custom format |
lv_font_subpx_t
The bitmaps might be upscaled by 3 to achieve subpixel rendering.
| Name |
|---|
LV_FONT_SUBPX_NONE |
LV_FONT_SUBPX_HOR |
LV_FONT_SUBPX_VER |
LV_FONT_SUBPX_BOTH |
lv_font_kerning_t
Adjust letter spacing for specific character pairs.
| Name |
|---|
LV_FONT_KERNING_NORMAL |
LV_FONT_KERNING_NONE |
Used by 3 functions
lv_font_set_kerning— paramkerninglv_font_manager_create_font— paramkerninglv_tiny_ttf_create_data_ex— paramkerning
Structs
lv_font_glyph_dsc_t
Describes the properties of a glyph.
| Member | Type | Description |
|---|---|---|
resolved_font | const lv_font_t * | Pointer to a font where the glyph was actually found after handling fallbacks |
entry | void * | The cache entry of the glyph draw data. Used by the font cache |
index | uint32_t | Glyph descriptor index |
src | const void * | Pointer to the source data used by image fonts |
gid | union lv_font_glyph_dsc_t | The index of the glyph in the font file. Used by the font cache |
format | lv_font_glyph_format_t | Font format of the glyph see lv_font_glyph_format_t |
outline_stroke_width | int32_t | used with freetype vector fonts - width of the letter border |
adv_w | uint16_t | The glyph needs this space. Draw the next glyph after this width. |
box_w | uint16_t | Width of the glyph's bounding box |
box_h | uint16_t | Height of the glyph's bounding box |
ofs_x | int16_t | x offset of the bounding box |
ofs_y | int16_t | y offset of the bounding box |
stride | uint16_t | Bytes in each line. If 0 than there is no padding at the end of the line. |
is_placeholder | uint8_t | Glyph is missing. But placeholder will still be displayed |
req_raw_bitmap | uint8_t | 0: Get bitmap should return an A8 or ARGB8888 image. 1: return the bitmap as it is (Maybe A1/2/4 or any proprietary formats). |
Used by 13 functions
lv_font_get_glyph_bitmap— paramg_dsclv_font_get_glyph_static_bitmap— paramg_dsclv_font_get_glyph_dsc— paramdsc_outlv_font_glyph_release_draw_data— paramg_dsclv_font_get_bitmap_fmt_txt— paramg_dsclv_font_get_glyph_dsc_fmt_txt— paramdsc_outlv_vg_lite_bitmap_font_cache_get— paramg_dsclv_font_glyph_dsc_compare— paramlhslv_font_glyph_dsc_compare— paramrhslv_font_get_glyph_bitmap_internal— paramg_dsclv_font_get_glyph_static_bitmap_internal— paramg_dsclv_font_glyph_release_draw_data_internal— paramg_dsclv_font_get_glyph_dsc_internal— paramdsc_out
_lv_font_t
Describe the properties of a font
| Member | Type | Description |
|---|---|---|
dsc | const void * | Store implementation specific or run_time data or caching here |
fallback | const lv_font_t * | Fallback font for missing glyph. Resolved recursively |
user_data | void * | Custom user data for font. |
get_glyph_dsc | bool(*)(const lv_font_t *font, lv_font_glyph_dsc_t *dsc_out, uint32_t letter, uint32_t letter_next) | Get a glyph's descriptor from a font. Fills dsc_out with metrics for the glyph corresponding to letter in font. letter_next is provided for kerning. The implementation may adjust dsc_out->adv_w based on the following character. Pass 0 if there is no next character. |
get_glyph_bitmap | const void *(*)(lv_font_glyph_dsc_t *g_dsc, lv_draw_buf_t *draw_buf) | Get glyph draw data from a font. Returns an opaque pointer to draw data for the glyph described by g_dsc. The concrete type and interpretation of the returned pointer depend on g_dsc->format (and related flags, e.g. whether a raw bitmap was requested).For legacy bitmap formats (e.g. A1/A2/A3/A4/A8), the implementation may either: - decode/decompress into the caller-provided draw_buf and return a pointer to that draw buffer (typically an lv_draw_buf_t *), or- return a pointer to font-internal bitmap storage. For non-bitmap formats (e.g. LV_FONT_GLYPH_FORMAT_IMAGE, vector/outline/SVG, or custom formats), the implementation typically ignores draw_buf and returns a format-specific object (such as an image source or lv_vector_path_t *).The caller must always treat the return value as the authoritative glyph draw data and interpret it according to g_dsc->format. Do not assume the data was written into draw_buf or that it is always an alpha bitmap. The returned pointer is only valid until release_glyph is called. |
release_glyph | void(*)(const lv_font_t *font, lv_font_glyph_dsc_t *g_dsc) | Release a glyph and any resources acquired during get_glyph_dsc or get_glyph_bitmap.Must be called after the glyph bitmap is no longer needed. Releases any internal cache entry stored in g_dsc->entry by the font implementation. Calling this with a g_dsc whose entry is NULL must be treated as a no-op. |
line_height | int32_t | The real line height where any text fits |
base_line | int32_t | Base line measured from the bottom of the line_height |
cap_height | int32_t | Cap height of the font |
x_height | int32_t | x-height of the font |
subpx | uint8_t | An element of lv_font_subpx_t |
kerning | uint8_t | An element of lv_font_kerning_t |
static_bitmap | uint8_t | The font will be used as static bitmap |
underline_position | int8_t | Distance between the top of the underline and base line (< 0 means below the base line) |
underline_thickness | int8_t | Thickness of the underline |
_lv_font_class_t
| Member | Type | Description |
|---|---|---|
create_cb | lv_font_t *(*)(const lv_font_info_t *info, const void *src) | Font creation callback function |
delete_cb | void(*)(lv_font_t *font) | Font deletion callback function |
dup_src_cb | void *(*)(const void *src) | Font source duplication callback function |
free_src_cb | void(*)(void *src) | Font source free callback function |
_lv_font_info_t
| Member | Type | Description |
|---|---|---|
name | const char * | Font name, used to distinguish different font resources |
class_p | const lv_font_class_t * | Font backend implementation |
size | uint32_t | Font size in pixel |
render_mode | uint32_t | Font rendering mode, see lv_freetype_font_render_mode_t |
style | uint32_t | Font style, see lv_freetype_font_style_t |
weight | int32_t | Font weight for variable fonts (range 1-2000, CSS-like values 100-900; 0 = default: 400 normal, 700 if bold style) |
kerning | lv_font_kerning_t | Font kerning, see lv_font_kerning_t |
Macros
LV_FONT_DECLARE
#define LV_FONT_DECLARE(font_name) \
LV_ATTRIBUTE_EXTERN_DATA extern const lv_font_t font_name;Variables
lv_font_montserrat_14
const lv_font_t lv_font_montserrat_14Dependencies
Last updated on