一、使用LvglFontTool4.0转换字体
这个工具是阿里兄大佬提供的,他的论坛下载地址
不过由于lvgl8的字体结构体变了一下,最新4.0转换出内部字体的话,需要对生成的c文修改一下才能用

输入要用到的字,或者直接选加入常用汉字,就看flash够不够大了。
然后选择字体。由于我win10权限的关系,我windows目录里面看不到Font文件夹,需要到控制面板——字体打开Font文件夹,然后将需要的字体文件拷贝到其他地方,才能选择字体

最后点开始转换,就能生成c文件,存到电脑本地目录
二、修改生成的C文件
因为lvgl8的lv_font_fmt_txt_dsc_t结构体将原来的last_letter和last_glyph_id放到了新的成员cache里面了,所以需要对应改过来
/*Describe store additional data for fonts*/
typedef struct {
/*The bitmaps of all glyphs*/
const uint8_t * glyph_bitmap;
/*Describe the glyphs*/
const lv_font_fmt_txt_glyph_dsc_t * glyph_dsc;
/*Map the glyphs to Unicode characters.
*Array of `lv_font_cmap_fmt_txt_t` variables*/
const lv_font_fmt_txt_cmap_t * cmaps;
/**
* Store kerning values.
* Can be `lv_font_fmt_txt_kern_pair_t * or `lv_font_kern_classes_fmt_txt_t *`
* depending on `kern_classes`
*/
const void * kern_dsc;
/*Scale kern values in 12.4 format*/
uint16_t kern_scale;
/*Number of cmap tables*/
uint16_t cmap_num : 9;
/*Bit per pixel: 1, 2, 3, 4, 8*/
uint16_t bpp : 4;
/*Type of `kern_dsc`*/
uint16_t kern_classes

本文档详细介绍了如何使用LvglFontTool4.0工具转换字体,并在LVGL图形库中进行修改和应用。首先,介绍了转换字体的步骤,包括选择字体和生成C文件。接着,由于LVGL8的结构体变化,需要修改生成的C文件以适配新版本。具体修改包括创建lv_font_fmt_txt_glyph_cache_t结构体并更新font_dsc。最后,展示了两种使用自定义字体的方法:在canvas上绘制和在label上显示。
最低0.47元/天 解锁文章
3782

被折叠的 条评论
为什么被折叠?



