Edit online

第三方库支持

4 Dec 2024
Read time: 1 minute(s)
  • freetype 库支持

    1. 选择 freetype 包,在 Luban 根目录下执行 make menuconfig,进入 menuconfig
      ArtInChip Luban SDK Configuration  --->
          Third-party packages  --->
          [*] freetype  --->
    2. 目录 lvgl-ui/lvgl/examples/libs/freetype/lv_example_freetype_1.c 下示例调用

      在 h 头文件中打开宏定义
      #define LV_USE_FREETYPE 1
      #define LV_BUILD_EXAMPLES 1
    3. 修改 c 中的入口函数:
      /*Create a Demo*/
      #if LV_USE_DEMO_MUSIC == 1
          void lv_demo_music(void);
          lv_demo_music();
      #else
          //void base_ui_init();
          //base_ui_init();
          void lv_example_freetype_1(void);
          lv_example_freetype_1();
      #endif
    4. 设置 lvgl-ui/lvgl/examples/libs/freetype/Lato-Regular.ttf 字体的打包目录, 复制字体到 lvgl-ui/base_ui/asserts/font 目录下,则会把字体打包到系统目录/usr/local/share/lvgl_data/font 目录下

    5. 修改代码 c 中字体文件路径
      void lv_example_freetype_1(void)
      {
          /*Create a font*/
          static lv_ft_info_t info;
          /*FreeType uses C standard file system, so no driver letter is required.*/
          //info.name = "./lvgl/examples/libs/freetype/Lato-Regular.ttf";
          info.name = "/usr/local/share/lvgl_data/font/Lato-Regular.ttf";
          info.weight = 24;
          info.style = FT_FONT_STYLE_NORMAL;
          info.mem = NULL;
          if(!lv_ft_font_init(&info)) {
              LV_LOG_ERROR("create failed.");
          }
      
          /*Create style with the new font*/
          static lv_style_t style;
          lv_style_init(&style);
          lv_style_set_text_font(&style, info.font);
          lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);
      
          /*Create a label with the new style*/
          lv_obj_t * label = lv_label_create(lv_scr_act());
          lv_obj_add_style(label, &style, 0);
          lv_label_set_text(label, "Hello world\nI'm a font created with FreeType");
          lv_obj_center(label);
      }