App:Library:LVGL:docs:3rd party libraries:FreeType support

提供: robot-jp wiki
2022年6月28日 (火) 12:55時点におけるTakashi (トーク | 投稿記録)による版 (→‎Example)
ナビゲーションに移動検索に移動

https://docs.lvgl.io/8.2/libs/freetype.html

英文 自動翻訳


FreeType support

Interface to FreeType to generate font bitmaps run time.

Install FreeType

  • Download Freetype from here
  • make
  • sudo make install

Add FreeType to your project

  • Add include path: /usr/include/freetype2 (for GCC: -I/usr/include/freetype2 -L/usr/local/lib)
  • Add library: freetype (for GCC: -L/usr/local/lib -lfreetype)

Usage

Enable LV_USE_FREETYPE in lv_conf.h.

To cache the glyphs from the opened fonts, set LV_FREETYPE_CACHE_SIZE >= 0 and then use the following macros for detailed configuration:

  1. LV_FREETYPE_CACHE_SIZE:maximum memory(bytes) used to cache font bitmap, outline, character maps, etc. 0 means use the system default value, less than 0 means disable cache. Note: that this value does not account for managed FT_Face and FT_Size objects.
  2. LV_FREETYPE_CACHE_FT_FACES:maximum number of opened FT_Face objects managed by this cache instance.0 means use the system default value. Only useful when LV_FREETYPE_CACHE_SIZE >= 0.
  3. LV_FREETYPE_CACHE_FT_SIZES:maximum number of opened FT_Size objects managed by this cache instance. 0 means use the system default value. Only useful when LV_FREETYPE_CACHE_SIZE >= 0.

When you are sure that all the used font sizes will not be greater than 256, you can enable LV_FREETYPE_SBIT_CACHE, which is much more memory efficient for small bitmaps.

You can use lv_ft_font_init() to create FreeType fonts. It returns true to indicate success, at the same time, the font member of lv_ft_info_t will be filled with a pointer to an LVGL font, and you can use it like any LVGL font.

Font style supports bold and italic, you can use the following macros to set:

  1. FT_FONT_STYLE_NORMAL:default style.
  2. FT_FONT_STYLE_ITALIC:Italic style
  3. FT_FONT_STYLE_BOLD:bold style

They can be combined.eg:FT_FONT_STYLE_BOLD | FT_FONT_STYLE_ITALIC.

Note that, the FreeType extension doesn't use LVGL's file system. You can simply pass the path to the font as usual on your operating system or platform.

Example

Open a front with FreeType

LVGL docs 3rdPartyLibs FreeType 01.png


Learn more

  • FreeType tutorial
  • LVGL's font interface

API

Enums

enum LV_FT_FONT_STYLE[1]
Values:
enumer[2]ator FT_FONT_STYLE_NORMAL[3]
enumerator FT_FONT_ST[4]YLE_ITALIC[5]
enumerator FT_FONT_ST[6]YLE_BOLD[7]

Functions

bool l[8]v_freetype_init(uint16_t max_faces, uint16_t max_sizes, uint32_t max_bytes)[9]
init freetype library
Parameters
  • max_faces -- Maximum number of opene[10]d FT_Face objects managed by this cache instance. Use 0 for defaults.
  • max_sizes -- Maximum number of opened FT_Size objects managed by this cache instance. Use 0 for defaults.
  • max_bytes -- Maximum number of bytes to use for cached data nodes. Use 0 for defaults. Note that this value does not account for managed FT_Face and FT_Size objects.
Returns
true on success, otherwise false.
void lv_freetype_destroy(void)[11]
Destroy freetype library

[12]

bool lv_ft_font_init(lv_ft_info_t *info)[13]
Creates a font with info parameter s[14]pecified.
Parameters
info -- See lv_ft_info_t for details. when success, lv_ft_info_t->font point to the font you created.
Returns
true on success, otherwise false.
void lv_ft_font_destroy(lv_font_t *font)[15]
Destroy a font that has been created[16].
Parameters
font -- pointer to font.
struct lv_ft_info_t[17]
Public Members [18]
const char *name[19]
const [20]void *mem[21]
size_[22]t mem_size[23]
lv_fo[24]nt_t *font[25]
uint1[26]6_t weight[27]
uint1[28]6_t style





戻る : Previous