Fix OTF font loading issue #249

This commit is contained in:
fvanroie 2022-04-18 00:40:51 +02:00
parent 9cab993b2f
commit 42f05da78e
2 changed files with 22 additions and 34 deletions

View File

@ -107,7 +107,7 @@ lv_font_t* hasp_font_load(const char* font_name)
lv_fs_close(&file);
if(!success) {
LOG_WARNING(TAG_FONT, "Error loading font %s", font_name);
// LOG_WARNING(TAG_FONT, "Error loading font %s", font_name);
/*
* When `lvgl_load_font` fails it can leak some pointers.
* All non-null pointers can be assumed as allocated and

View File

@ -63,9 +63,9 @@ static lv_font_t* font_add_to_list(const char* payload)
char* name_p = NULL;
#if defined(ARDUINO_ARCH_ESP32) && (HASP_USE_FREETYPE > 0)
char* ext[] = {"ttf", "otf"};
for(size_t i = 0; i < 2; i++) {
if(!font) {
// Try .ttf file
size_t pos = font_split_payload(payload);
if(pos > 0 && pos < 56) {
uint16_t size = atoi(payload + pos);
@ -73,7 +73,7 @@ static lv_font_t* font_add_to_list(const char* payload)
char fontname[64];
memset(fontname, 0, sizeof(fontname));
strncpy(fontname, payload, pos);
snprintf_P(filename, sizeof(filename), PSTR("L:\\%s.ttf"), fontname);
snprintf_P(filename, sizeof(filename), PSTR("L:\\%s.%s"), fontname, ext[i]);
lv_ft_info_t info;
info.name = filename;
@ -84,18 +84,6 @@ static lv_font_t* font_add_to_list(const char* payload)
}
}
}
if(!font) {
// Try .otf file
snprintf_P(filename, sizeof(filename), PSTR("L:\\%s.otf"), payload);
lv_ft_info_t info;
info.name = filename;
info.weight = 56;
info.style = FT_FONT_STYLE_NORMAL;
if(lv_ft_font_init(&info)) {
font = info.font;
}
}
#endif