您尚未登录。

楼主 #1 2021-04-15 16:04:27

542396750@qq.com
会员
注册时间: 2021-03-26
已发帖子: 163
积分: 19.5

lvgl添加汉字显示

工程代码lv_port_linux_frame_buffer
使用工具LvglFontTool生成myFont.c添加到lvgl/scr/lv_font目录下

修改lv_conf.h中
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(myFont)

测试代码提示myFont 未定义

void lv_font_test()
{
    LV_FONT_DECLARE(myFont);//放这里也行
    lv_obj_t* label1 = lv_label_create(lv_scr_act(), NULL);
    lv_obj_set_style_local_text_font(label1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &myFont);
    lv_obj_set_pos(label1, 20, 20);
    lv_label_set_text(label1, "Hello,你好,哇酷网!");

}

myFont.c好像没有编译,

求教怎么把myFont.c加入编译进去?

离线

楼主 #3 2021-04-15 16:17:55

542396750@qq.com
会员
注册时间: 2021-03-26
已发帖子: 163
积分: 19.5

Re: lvgl添加汉字显示

哇酷小二 说:

Makefile文件找到你当前.c文件名,然后把myFont.c一起挤进去

应该不是改Makefile,
不好意思,我没问对问题。应该是lv_conf.h应该怎么修改才能使用自定义的字库?

只把myFont.c加入lv_font目录和声明LV_FONT_DECLARE(myFont);不够吧?

Makefile是这样的:

#
# Makefile
#
#CC ?= gcc
CC = /home/obm/123/buildroot-2017.08/output/host/bin/arm-linux-gcc

LVGL_DIR_NAME ?= lvgl
LVGL_DIR ?= ${shell pwd}
CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ -Wall -Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wno-discarded-qualifiers -Wall -Wextra -Wno-unused-function -Wundef -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wno-switch-enum -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body -Wtype-limits  -Wstack-usage=1024 -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wmissing-prototypes -Wunreachable-code -Wno-switch-default -Wswitch-enum -Wreturn-type -Wmultichar -Wno-discarded-qualifiers -Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare
LDFLAGS ?= -lm
LDFLAGS +=-lts
BIN = demo


#Collect the files to compile
MAINSRC = ./main.c

include $(LVGL_DIR)/lvgl/lvgl.mk
include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
include $(LVGL_DIR)/lv_examples/lv_examples.mk
#include $(LVGL_DIR)/lv_examples/lv_tests/lv_test_theme/lv_test_theme.mk

OBJEXT ?= .o

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

MAINOBJ = $(MAINSRC:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)

## MAINOBJ -> OBJFILES

all: default

%.o: %.c
    @$(CC)  $(CFLAGS) -c $< -o $@
    @echo "$(CC) $<"
   
default: $(AOBJS) $(COBJS) $(MAINOBJ)
    $(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS)

clean:
    rm -f $(BIN) $(AOBJS) $(COBJS) $(MAINOBJ)

离线

楼主 #5 2021-04-15 16:27:04

542396750@qq.com
会员
注册时间: 2021-03-26
已发帖子: 163
积分: 19.5

Re: lvgl添加汉字显示

参考这个贴子
https://whycan.com/t_5080.html

2、在CMakeLists.txt中  lvgl/src/lv_font/lv_font_montserrat_48.c 附近添加lvgl/src/lv_font/myFont.c。
这一步在CMakeLists.txt没找到对应内容lvgl/src/lv_font/lv_font_montserrat_48.c

离线

楼主 #6 2021-04-15 16:34:54

542396750@qq.com
会员
注册时间: 2021-03-26
已发帖子: 163
积分: 19.5

Re: lvgl添加汉字显示

修改lv_font目录下lv_font。mk,后面加+=myFont.c编译通过

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn