LVGL字体
LVGL字体概述
V6版本最高支持4bpp的抗锯齿,支持UTF-8和ASCLL编码.通过配置LV_TXT_ENC
修改编码.具体区别如下
- ASCLL:只支持英文显示
- UTF-8:支持全球所有字符
需要注意的是,当使用UTF-8编码时,将你使用的IDE的编码也修改为UTF-8.
如何使用字体
LVGL内置了7种字体,相关宏如下所示.
/* https://fonts.google.com/specimen/Roboto */
#define LV_FONT_ROBOTO_12 1
#define LV_FONT_ROBOTO_16 1
#define LV_FONT_ROBOTO_22 0
#define LV_FONT_ROBOTO_28 0
/* Demonstrate special features */
#define LV_FONT_ROBOTO_12_SUBPX 1
#define LV_FONT_ROBOTO_28_COMPRESSED 1 /*bpp = 3*/
/*Pixel perfect monospace font
* http://pelulamu.net/unscii/ */
#define LV_FONT_UNSCII_8 0
如果想使用哪个字体,则打开对应的宏定义即可.
具体使用示例如下.
static lv_style_t laebl_style;
lv_style_copy(&laebl_style,&lv_style_plain_color);
laebl_style.text.font = &LV_FONT_ROBOTO_12;
lv_label_set_style(label1, LV_LABEL_STYLE_MAIN,&laebl_style);
备注: 如果在使用的时候没有指定显示文本的字体时,按照LV_FONT_DEFAULT
宏的配置去显示.
创建自己的字体
使用如下两款软件
生成c文件后,将该文件导入到工程中.下面是一段简单的测试代码.
lv_obj_t *consolas_label = lv_label_create(app_window, NULL);
if(consolas_label == NULL)
{
printf("init failed\r\n");
while(1);
}
static lv_style_t consolas_style;
lv_style_copy(&consolas_style,&lv_style_plain);
consolas_style.text.font = &consolas;
lv_label_set_style(consolas_label,LV_LABEL_STYLE_MAIN,&consolas_style);
lv_label_set_text(consolas_label,"abc");
lv_label_set_body_draw(consolas_label,true);
lv_obj_align(consolas_label,NULL,LV_ALIGN_IN_BOTTOM_LEFT,0,0);