refact(binfont): unified font creation API (#5333)

Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
_VIFEXTech
2024-01-15 22:50:22 +08:00
committed by GitHub
parent c7bece7d98
commit 106519bd2d
5 changed files with 75 additions and 81 deletions

View File

@@ -290,7 +290,7 @@ The built-in symbols are created from the `FontAwesome <https://fontawesome.com/
Load a font at run-time
***********************
:cpp:func:`lv_binfont_load` can be used to load a font from a file. The font needs
:cpp:func:`lv_binfont_create` can be used to load a font from a file. The font needs
to have a special binary format. (Not TTF or WOFF). Use
`lv_font_conv <https://github.com/lvgl/lv_font_conv/>`__ with the
``--format bin`` option to generate an LVGL compatible font file.
@@ -302,19 +302,18 @@ Example
.. code:: c
static lv_font_t my_font;
lv_result_t res = lv_binfont_load(&my_font, "X:/path/to/my_font.bin");
if(res != LV_RESULT_OK) return;
lv_font_t *my_font = lv_binfont_create("X:/path/to/my_font.bin");
if(my_font == NULL) return;
/*Use the font*/
/*Free the font if not required anymore*/
lv_font_free(&my_font);
lv_binfont_destroy(my_font);
Load a font from a memory buffer at run-time
******************************************
:cpp:func:`lv_binfont_load_from_buffer` can be used to load a font from a memory buffer.
:cpp:func:`lv_binfont_create_from_buffer` can be used to load a font from a memory buffer.
This function may be useful to load a font from an external file system, which is not
supported by LVGL. The font needs to be in the same format as if it were loaded from a file.
@@ -325,7 +324,7 @@ Example
.. code:: c
static lv_font_t my_font;
lv_font_t *my_font;
uint8_t *buf;
uint32_t bufsize;
@@ -333,12 +332,12 @@ Example
...
/*Load font from the buffer*/
lv_result_t res = lv_binfont_load_from_buffer(&my_font, (void *)buf, buf));
if(res != LV_RESULT_OK) return;
my_font = lv_binfont_create_from_buffer((void *)buf, buf));
if(my_font == NULL) return;
/*Use the font*/
/*Free the font if not required anymore*/
lv_font_free(&my_font);
lv_binfont_destroy(my_font);
Add a new font engine
*********************