一级目录

  • freetype 源码 freetype-2.13.2
  • gui guider 版本 Version: 1.7.0-GA
  • lvgl 版本 8.3
  • 交叉编译工具 :aarch64-linux-gnu-gcc

概述:

  • 之前使用字体的使用字体字不同的字号要转成对应的 lv_font_montserratMedium_12,lv_font_montserratMedium_xx 等c文件然后在添加工程了,这样没添加一种字号或者字体都要增加一个 c文件,这样占用空间大,编译时间慢,固件包也大,下载更新也慢,使用也不用灵活和方便,使用freetype 之后就大大增加了字体的使用灵活性和减少编译个下载时间。

二级目录l

下载源码后,解压入下
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/2d0a7ae9b0764394a77ce9513a0555e2.png

  • 配置
./configure -prefix=$PWD/tmp --host=aarch64-linux-gnu --enable-shared CC=aarch64-linux-gnu-gcc --with-zlib=no --with-bzip2=no --with-png=no --with-harfbuzz=no

-prefix:指定安装路径
CC=:指定编译器,这里用的是 aarch64-linux-gnu-gcc,根据自己平台选择
zlib、libpng 都不用 所以选 =no

  • 结果如下
    在这里插入图片描述
    在这里插入图片描述

  • 安装

//编译 安装
make                         
make install
  • make 结果
/home/xxx/doc/freetype-2.13.2/objs/ftgzip.o /home/xxx/doc/freetype-2.13.2/objs/ftlzw.o /home/xxx/doc/freetype-2.13.2/objs/ftbzip2.o /home/xxx/doc/freetype-2.13.2/objs/psaux.o /home/xxx/doc/freetype-2.13.2/objs/psnames.o /home/xxx/doc/freetype-2.13.2/objs/dlg.o
libtool: link: aarch64-linux-gnu-ranlib /home/xxx/doc/freetype-2.13.2/objs/.libs/libfreetype.a
libtool: link: ( cd "/home/xxx/doc/freetype-2.13.2/objs/.libs" && rm -f "libfreetype.la" && ln -s "../libfreetype.la" "libfreetype.la" )

  • make install 结果
 /usr/bin/install -c -m 644                                           \
            $P /home/xxx/doc/freetype-2.13.2/tmp/include/freetype2/freetype/config ; \
        done
/usr/bin/install -c -m 644 /home/xxx/doc/freetype-2.13.2/include/ft2build.h                  \
          /home/xxx/doc/freetype-2.13.2/tmp/include/freetype2/ft2build.h
/usr/bin/install -c -m 644 ./builds/unix/ftconfig.h                        \
          /home/xxx/doc/freetype-2.13.2/tmp/include/freetype2/freetype/config/ftconfig.h
/usr/bin/install -c -m 644 /home/xxx/doc/freetype-2.13.2/objs/ftmodule.h                          \
          /home/xxx/doc/freetype-2.13.2/tmp/include/freetype2/freetype/config/ftmodule.h
/usr/bin/install -c -m 644 ./builds/unix/ftoption.h                        \
          /home/xxx/doc/freetype-2.13.2/tmp/include/freetype2/freetype/config/ftoption.h
/usr/bin/install -c -m 644 ./builds/unix/freetype2.m4          \
          /home/xxx/doc/freetype-2.13.2/tmp/share/aclocal/freetype2.m4
/usr/bin/install -c -m 644 ./builds/unix/freetype2.pc             \
          /home/xxx/doc/freetype-2.13.2/tmp/lib/pkgconfig/freetype2.pc
  • 库文件夹 temp 机构如下:包含头文件和库文件
  • 在这里插入图片描述

在这里插入图片描述

将生成的头文件和库文件移植到gui guider 工程目录

  • 头文件和库文件放到 lib 下
    在这里插入图片描述
  • 修改 custom.cmake 文件,添加包含 头文件和库文件 路径
# 头文件路径
target_include_directories(lvgl SYSTEM PUBLIC 
${LVGL_ROOT_DIR}/../usr_lib/include/freetype2 
${LVGL_ROOT_DIR}/../usr_lib/include/freetype2/freetype 
${LVGL_ROOT_DIR}/../usr_lib/include/freetype2/freetype/config)

# 链接库
target_link_directories(lvgl PUBLIC "${LVGL_ROOT_DIR}/../usr_lib/libs")
target_link_libraries(lvgl PUBLIC freetype)

修改程序代码,添加演示demo

  • 配置 lv_conf.h 文件 使能 LV_USE_FREETYPE
/*FreeType library*/
#define LV_USE_FREETYPE 1
#if LV_USE_FREETYPE
/*Memory used by FreeType to cache characters [bytes] (-1: no caching)*/
#define LV_FREETYPE_CACHE_SIZE (16U * 1024U)
#if LV_FREETYPE_CACHE_SIZE >= 0
/* 1: bitmap cache use the sbit cache, 0:bitmap cache use the image cache. */
/* sbit cache:it is much more memory efficient for small bitmaps(font size < 256) */
/* if font size >= 256, must be configured as image cache */
#define LV_FREETYPE_SBIT_CACHE 255
/* Maximum number of opened FT_Face/FT_Size objects managed by this cache instance. */
/* (0:use system defaults) */
#define LV_FREETYPE_CACHE_FT_FACES 0
#define LV_FREETYPE_CACHE_FT_SIZES 0
#endif /* LV_FREETYPE_CACHE_SIZE */
#endif /* LV_USE_FREETYPE */
  • 添加演示demo 直接把官网的演示demo 复制到 程序
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.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);
}
  • 把字体文件路经修改程自己的文件路径 ,修改为斜体
  • info.name = "./import/font/Alatsi-Regular.ttf
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 = "./import/font/Alatsi-Regular.ttf";
    info.weight = 24;
    info.style = FT_FONT_STYLE_ITALIC;
    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);
}
/**
 * Create a demo application
 */

void custom_init(lv_ui *ui)
{
    /* Add your codes here */
    lv_example_freetype_1();
}

  • 编译通过,把 Alatsi-Regular.ttf 字体文件 放到板子上对应目录下
gui_guider  img  import

我的 字体文件放在 可执行文件 gui_guider 同路径下 的import 里
显示结果如下

在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐