static const lv_font_fmt_txt_dsc_t font_dsc = {
#else
static lv_font_fmt_txt_dsc_t font_dsc = {
#endif
.glyph_bitmap = glyph_bitmap,
.glyph_dsc = glyph_dsc,
.cmaps = cmaps,//用来描述包含了多少个unicode字符段,比如0x20-0x30是连续的一段,0x40-0x50是第二段
.kern_dsc = NULL,
.kern_scale = 16,
.cmap_num = 1, //这个值代表有多少个字符描述段
.bpp = 4,//必须跟生成的字库选择时一样否则显示会错误
.kern_classes = 0,//没有用
.bitmap_format = 0,
#if LVGL_VERSION_MAJOR >= 8
.cache = &cache
#endif
};
static const lv_font_fmt_txt_cmap_t cmaps[] = {
//一个括号就是一个连续的字符段,如果字符码不连续,就需要多个括号来描述
{
//字符的开始unicode码 一共多少个字符 表示描述数组的索引
.range_start = 0x30, .range_length = 11, .glyph_id_start = 1,
.unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
},
};
//range_start 是unicode码代表一个字符
//range_length 是这个连续的段里一共有多少个字符
//glyph_id_start 是在字符描述数组里的索引位置
static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
{.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
{.bitmap_index = 0, .adv_w = 171, .box_w = 10, .box_h = 12, .ofs_x = 0, .ofs_y = 0},// 0
{.bitmap_index = 60, .adv_w = 95, .box_w = 5, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 90, .adv_w = 147, .box_w = 9, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 144, .adv_w = 146, .box_w = 9, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 198, .adv_w = 171, .box_w = 11, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 264, .adv_w = 147, .box_w = 9, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 318, .adv_w = 158, .box_w = 10, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 378, .adv_w = 153, .box_w = 9, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 432, .adv_w = 165, .box_w = 10, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 492, .adv_w = 158, .box_w = 10, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 552, .adv_w = 58, .box_w = 3, .box_h = 9, .ofs_x = 0, .ofs_y = 0},
};
//字符位图描述数组,这个数组和位图的对应关系是以bitmap_index来决定的,bitmap_index 是字符在位图里的偏移量,而位图数组和camp描述结构体的关系是:字符unicode码-->range_start<-->range_id-->字符描述数组-->字符位图bitmap_index
字库修改步骤:
1.在字符映射数组里创建一个描述,指定uncode码起始码,字符数量,以及对应到的位图描述数组里的索引。【从0开始
.range_start = 0x30, .range_length = 11, .glyph_id_start = 1,
2.指定一共具有的映射数量,映射数组里有多少个映射描述就是几
.cmaps = cmaps,
.cmap_num = 1,
3.设置bpp,这个值必须和生成的字库所使用的bpp一致
.bpp = 4,
4.设置位图描述数组,位图索引对应位图数组的偏移,以及需要正确的字符宽度否则文字显示会错误,这里每个描述在数组里的位置,对应了字符映射里的ID [0-N],bitmap_index对应于字符在位图数组里的偏移量
static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
{.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
{.bitmap_index = 0, .adv_w = 171, .box_w = 10, .box_h = 12, .ofs_x = 0, .ofs_y = 0},// 0
{.bitmap_index = 60, .adv_w = 95, .box_w = 5, .box_h = 12, .ofs_x = 0, .ofs_y = 0},
};
5.设置字符位图,这里每个字符有一个unicode码,这个码对应字符映射中的range_start,lvgl可以根据这个unicode码得到位图描述id glyph_id_start,然后glyph_id_start对应位图描述数组下标,再通过下标得到位图描述glyph_dsc,获得bitmap_index,然后通过bitmap_index得到字符偏移量,最后得到字符位图。
static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {
/* U+0020 " " */
/* U+0030 "0" */
0x0, 0x8, 0xef, 0xc5, 0x0, 0x0, 0xcf, 0xa8,
0xcf, 0x70, 0x7, 0xf5, 0x0, 0xa, 0xf2, 0xd,
0xc0, 0x0, 0x1, 0xf8, 0x1f, 0x80, 0x0, 0x0,
0xdc, 0x3f, 0x60, 0x0, 0x0, 0xbd, 0x3f, 0x60,
0x0, 0x0, 0xbd, 0x1f, 0x80, 0x0, 0x0, 0xdc,
0xd, 0xc0, 0x0, 0x1, 0xf8, 0x7, 0xf5, 0x0,
0xa, 0xf2, 0x0, 0xcf, 0xa8, 0xcf, 0x70, 0x0,
0x8, 0xef, 0xc5, 0x0,
}