纳入固件源码、屏幕组件、nand_xfer 工具和文档。忽略本机构建产物、sdkconfig,以及含本机路径的依赖锁。 Co-authored-by: Cursor <[email protected]>
159 lines
3.9 KiB
C
159 lines
3.9 KiB
C
#include "font_runtime.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
/* 如果工程未在 lv_conf 或编译参数里定义,则默认开启运行时 binfont。 */
|
|
#ifndef LV_USE_BINFONT
|
|
#define LV_USE_BINFONT 1
|
|
#endif
|
|
|
|
#if LV_USE_BINFONT
|
|
#include "font/binfont_loader/lv_binfont_loader.h"
|
|
#endif
|
|
|
|
typedef struct {
|
|
const char *tag;
|
|
const char *path;
|
|
lv_font_t *runtime_font;
|
|
} runtime_font_slot_t;
|
|
|
|
static const char *TAG = "font_runtime";
|
|
static bool s_font_inited = false;
|
|
#if !LV_USE_BINFONT
|
|
static bool s_feature_logged = false;
|
|
#endif
|
|
|
|
static runtime_font_slot_t s_misans_25 = {
|
|
.tag = "MiSans_25",
|
|
.path = "/extflash/fonts/MiSans_VF_25.bin",
|
|
.runtime_font = NULL,
|
|
};
|
|
static runtime_font_slot_t s_misans_30 = {
|
|
.tag = "MiSans_30",
|
|
.path = "/extflash/fonts/MiSans_VF_30.bin",
|
|
.runtime_font = NULL,
|
|
};
|
|
static runtime_font_slot_t s_misans_40 = {
|
|
.tag = "MiSans_40",
|
|
.path = "/extflash/fonts/MiSans_VF_40.bin",
|
|
.runtime_font = NULL,
|
|
};
|
|
static runtime_font_slot_t s_misans_60 = {
|
|
.tag = "MiSans_60",
|
|
.path = "/extflash/fonts/MiSans_VF_60.bin",
|
|
.runtime_font = NULL,
|
|
};
|
|
static runtime_font_slot_t s_misans_100 = {
|
|
.tag = "MiSans_100",
|
|
.path = "/extflash/fonts/MiSans_VF_100.bin",
|
|
.runtime_font = NULL,
|
|
};
|
|
static runtime_font_slot_t s_misans_180 = {
|
|
.tag = "MiSans_180",
|
|
.path = "/extflash/fonts/MiSans_VF_180.bin",
|
|
.runtime_font = NULL,
|
|
};
|
|
static runtime_font_slot_t s_icon_25 = {
|
|
.tag = "Icon_25",
|
|
.path = "/extflash/fonts/iconfont_25.bin",
|
|
.runtime_font = NULL,
|
|
};
|
|
|
|
static void load_one_font(runtime_font_slot_t *slot)
|
|
{
|
|
if (slot == NULL || slot->runtime_font != NULL) {
|
|
return;
|
|
}
|
|
|
|
#if LV_USE_BINFONT
|
|
slot->runtime_font = lv_binfont_create(slot->path);
|
|
if (slot->runtime_font == NULL) {
|
|
ESP_LOGW(TAG, "load failed: %s (%s), fallback to built-in", slot->tag, slot->path);
|
|
return;
|
|
}
|
|
ESP_LOGI(TAG, "load ok: %s (%s)", slot->tag, slot->path);
|
|
#else
|
|
LV_UNUSED(slot);
|
|
if (!s_feature_logged) {
|
|
ESP_LOGI(TAG, "LV_USE_BINFONT=0, keep built-in fonts");
|
|
s_feature_logged = true;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void ui_font_runtime_init(void)
|
|
{
|
|
if (s_font_inited) {
|
|
return;
|
|
}
|
|
s_font_inited = true;
|
|
|
|
load_one_font(&s_misans_25);
|
|
load_one_font(&s_misans_30);
|
|
load_one_font(&s_misans_40);
|
|
load_one_font(&s_misans_60);
|
|
load_one_font(&s_misans_100);
|
|
load_one_font(&s_misans_180);
|
|
load_one_font(&s_icon_25);
|
|
}
|
|
|
|
void ui_font_runtime_deinit(void)
|
|
{
|
|
#if LV_USE_BINFONT
|
|
runtime_font_slot_t *slots[] = {
|
|
&s_misans_25, &s_misans_30, &s_misans_40,
|
|
&s_misans_60, &s_misans_100, &s_misans_180, &s_icon_25,
|
|
};
|
|
size_t i = 0;
|
|
for (i = 0; i < sizeof(slots) / sizeof(slots[0]); ++i) {
|
|
if (slots[i]->runtime_font != NULL) {
|
|
lv_binfont_destroy(slots[i]->runtime_font);
|
|
slots[i]->runtime_font = NULL;
|
|
}
|
|
}
|
|
#endif
|
|
s_font_inited = false;
|
|
}
|
|
|
|
const lv_font_t *ui_font_misans_25(void)
|
|
{
|
|
if (s_misans_25.runtime_font != NULL) return s_misans_25.runtime_font;
|
|
return LV_FONT_DEFAULT;
|
|
}
|
|
|
|
const lv_font_t *ui_font_misans_30(void)
|
|
{
|
|
if (s_misans_30.runtime_font != NULL) return s_misans_30.runtime_font;
|
|
return LV_FONT_DEFAULT;
|
|
}
|
|
|
|
const lv_font_t *ui_font_misans_40(void)
|
|
{
|
|
if (s_misans_40.runtime_font != NULL) return s_misans_40.runtime_font;
|
|
return LV_FONT_DEFAULT;
|
|
}
|
|
|
|
const lv_font_t *ui_font_misans_60(void)
|
|
{
|
|
if (s_misans_60.runtime_font != NULL) return s_misans_60.runtime_font;
|
|
return LV_FONT_DEFAULT;
|
|
}
|
|
|
|
const lv_font_t *ui_font_misans_100(void)
|
|
{
|
|
if (s_misans_100.runtime_font != NULL) return s_misans_100.runtime_font;
|
|
return LV_FONT_DEFAULT;
|
|
}
|
|
|
|
const lv_font_t *ui_font_misans_180(void)
|
|
{
|
|
if (s_misans_180.runtime_font != NULL) return s_misans_180.runtime_font;
|
|
return LV_FONT_DEFAULT;
|
|
}
|
|
|
|
const lv_font_t *ui_font_icon_25(void)
|
|
{
|
|
if (s_icon_25.runtime_font != NULL) return s_icon_25.runtime_font;
|
|
return LV_FONT_DEFAULT;
|
|
}
|