搞过 EMWIN 对 XBF 外置字体并不陌生,LVGL 没有详细资料,我们先从内置源码看起
lv_font_t 字体结构可以先看一下
//微软雅黑,Regular,24
//字模高度:41
//内部字体
//使用排序和二分查表
lv_font_t HeaFont = {
.dsc = &font_dsc,//字体描述
[size=13.9333px] [size=13.9333px] .get_glyph_bitmap = __user_font_get_bitmap,//获取字体数据
[size=13.9333px] [size=13.9333px] .get_glyph_dsc = __user_font_get_glyph_dsc,//获取字体描述
[size=13.9333px] [size=13.9333px] .line_height = 41,
[size=13.9333px] [size=13.9333px] .base_line = 0,
};
然后肯定先要查字体描述来或者字体信息(
__user_font_get_glyph_dsc)再看字体表述代码
static bool __user_font_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out,
uint32_t unicode_letter, uint32_t unicode_letter_next) {
lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc;
if(unicode_letter < fdsc->cmaps[0].range_start)
return false;
//编码小于开始地址报错
int i = binsearch(fdsc->cmaps[0].unicode_list, fdsc->cmaps[0].list_length, unicode_letter);
//查询 UNICODE 字符列表,返回所在顺序位置
if( i != -1 ) {
const lv_font_fmt_txt_glyph_dsc_t * gdsc = &fdsc->glyph_dsc
;//
dsc_out->adv_w = gdsc->adv_w;//取出每个字体参数描述
dsc_out->box_h = gdsc->box_h;
dsc_out->box_w = gdsc->box_w;
dsc_out->ofs_x = gdsc->ofs_x;
dsc_out->ofs_y = gdsc->ofs_y;
dsc_out->bpp
= fdsc->bpp;
return true;
}
return false;
}
通过查
我们知道
.bitmap_index = 150 就是字体存放位置的偏移地址
然后再去获取字体数据