里飞网

标题: 0.4生成的字库在8.1版本上编译错误 [打印本页]

作者: feihongkld    时间: 2022-1-4 14:40
标题: 0.4生成的字库在8.1版本上编译错误
8.1版本的字库文件和生成的字库结构体有些不一样,/*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   : 1;

    /*
     * storage format of the bitmap
     * from `lv_font_fmt_txt_bitmap_format_t`
     */
    uint16_t bitmap_format  : 2;

    /*Cache the last letter and is glyph id*/
    lv_font_fmt_txt_glyph_cache_t * cache;
} lv_font_fmt_txt_dsc_t;

是不是这个0.4不支持8.1版本

..\..\lvgl8\lvgl\src\font\myFont1.c(119465): error:  #136: struct "<unnamed>"  has no field "last_letter"
      .last_letter = 0x9fa0,
..\..\lvgl8\lvgl\src\font\myFont1.c(119494): error:  #136: struct "<unnamed>"  has no field "last_letter"
      if( unicode_letter==fdsc->last_letter ){
..\..\lvgl8\lvgl\src\font\myFont1.c(119495): error:  #136: struct "<unnamed>"  has no field "last_glyph_id"
          i = fdsc->last_glyph_id;
..\..\lvgl8\lvgl\src\font\myFont1.c(119502): error:  #136: struct "<unnamed>"  has no field "last_glyph_id"
          fdsc->last_glyph_id = i;
..\..\lvgl8\lvgl\src\font\myFont1.c(119503): error:  #136: struct "<unnamed>"  has no field "last_letter"
          fdsc->last_letter = unicode_letter;
..\..\lvgl8\lvgl\src\font\myFont1.c(119516): error:  #136: struct "<unnamed>"  has no field "last_letter"
      if( unicode_letter==fdsc->last_letter ){
..\..\lvgl8\lvgl\src\font\myFont1.c(119517): error:  #136: struct "<unnamed>"  has no field "last_glyph_id"
          i = fdsc->last_glyph_id;
..\..\lvgl8\lvgl\src\font\myFont1.c(119524): error:  #136: struct "<unnamed>"  has no field "last_glyph_id"
          fdsc->last_glyph_id = i;
..\..\lvgl8\lvgl\src\font\myFont1.c(119525): error:  #136: struct "<unnamed>"  has no field "last_letter"
          fdsc->last_letter = unicode_letter;
..\..\lvgl8\lvgl\src\font\myFont1.c(119542): error:  #147: declaration is incompatible with "const lv_font_t myFont1"  (declared at line 239 of "..\..\lvgl8\lvgl\src/core/../misc/../font/lv_font.h")
  lv_font_t myFont1 = {
..\..\lvgl8\lvgl\src\font\myFont1.c: 0 warnings, 10 errors
".\Output_Data\NUC972_FreeRTOS_LvglV8_Cap.axf" - 10 Error(s), 0 Warning(s).



作者: 阿里兄    时间: 2022-1-4 14:44
本帖最后由 阿里兄 于 2023-3-22 16:54 编辑

http://dz.lfly.xyz/forum.php?mod=viewthread&tid=24&extra=page%3D1

22楼有回复,自己改改。
作者: feihongkld    时间: 2022-1-4 16:44
本帖最后由 feihongkld 于 2022-1-4 16:45 编辑

为了方便大家修改成8.0一上版本可以使用,贴出修改代码: 测试显示OK  我的版本是8.11

static lv_font_fmt_txt_glyph_cache_t glyph_cache = {
        .last_letter = 0x9fa0,
        .last_glyph_id = 6858,
};

static lv_font_fmt_txt_dsc_t font_dsc = {
    .glyph_bitmap = glyph_bitmap,
    .glyph_dsc = glyph_dsc,
    .cmaps = cmaps,
    .cmap_num = 1,
    .bpp = 4,

    .kern_scale = 0,
    .kern_dsc = NULL,
    .kern_classes = 0,
          .cache = &glyph_cache,
};


int binsearch(const uint16_t *sortedSeq, int seqLength, uint16_t keyData) {
    int low = 0, mid, high = seqLength - 1;
    while (low <= high) {
        mid = (low + high)>>1;//右移1位等于是/2,奇数,无论奇偶,有个值就行
        if (keyData < sortedSeq[mid]) {
            high = mid - 1;//是mid-1,因为mid已经比较过了
        }
        else if (keyData > sortedSeq[mid]) {
            low = mid + 1;
        }
        else {
            return mid;
        }
    }
    return -1;
}

const uint8_t * __user_font_get_bitmap(const lv_font_t * font, uint32_t unicode_letter) {
    lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc;
    if( unicode_letter<fdsc->cmaps[0].range_start || unicode_letter>fdsc->cmaps[0].range_length ) return false;

    int i;
    if( unicode_letter==fdsc->cache->last_letter ){
        i = fdsc->cache->last_glyph_id;
    }
    else{
        i = binsearch(fdsc->cmaps[0].unicode_list, fdsc->cmaps[0].list_length, unicode_letter);
    }
    if( i != -1 ) {
        const lv_font_fmt_txt_glyph_dsc_t * gdsc = &fdsc->glyph_dsc;
        fdsc->cache->last_glyph_id = i;
        fdsc->cache->last_letter = unicode_letter;
        return &fdsc->glyph_bitmap[gdsc->bitmap_index];
    }
    return NULL;
}


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 || unicode_letter>fdsc->cmaps[0].range_length ) return false;

    int i;
    if( unicode_letter==fdsc->cache->last_letter ){
        i = fdsc->cache->last_glyph_id;
    }
    else{
        i = binsearch(fdsc->cmaps[0].unicode_list, fdsc->cmaps[0].list_length, unicode_letter);
    }
    if( i != -1 ) {
        const lv_font_fmt_txt_glyph_dsc_t * gdsc = &fdsc->glyph_dsc;
        fdsc->cache->last_glyph_id = i;
        fdsc->cache->last_letter = unicode_letter;
        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;
}


//Microsoft JhengHei,,-1
//字模高度:19
//内部字体
//使用排序和二分查表
const lv_font_t myFont1 = {
    .dsc = &font_dsc,
    .get_glyph_bitmap = __user_font_get_bitmap,
    .get_glyph_dsc = __user_font_get_glyph_dsc,
    .line_height = 19,
    .base_line = 0,
};

测试代码:
void lvgl_test(void)
{
//                lv_style_init(&style_label);
//    lv_style_set_bg_opa(&style_label, LV_OPA_0);
//    lv_style_set_text_font(&style_label, &myFont1);
    lv_obj_t *scr = lv_disp_get_scr_act(NULL);/* 获取当前屏幕 */
    lv_scr_load(scr);

    lv_obj_t *label1 = lv_label_create(scr); /* 创建 label 控件 */
    lv_obj_set_pos(label1,0,0); /* 设置控件的坐标 */
    lv_label_set_text(label1,"Hello欢迎到来"); /* 设置文字 */
    lv_obj_align(label1,LV_ALIGN_CENTER,0,0); /* 设置控件的对*/
}

注意需要修改lv_conf.h
/*Optionally declare custom fonts here.
*You can use these fonts as default font too and they will be available globally.
*E.g. #define LV_FONT_CUSTOM_DECLARE   LV_FONT_DECLARE(my_font_1) LV_FONT_DECLARE(my_font_2)*/
#define LV_FONT_CUSTOM_DECLARE  LV_FONT_DECLARE(myFont1)

/*Always set a default font*/
#define LV_FONT_DEFAULT &myFont1






欢迎光临 里飞网 (http://dz.lfly.xyz/) Powered by Discuz! X3.3