mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Fix OTF font loading issue #249
This commit is contained in:
parent
9cab993b2f
commit
42f05da78e
@ -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
|
||||
@ -223,7 +223,7 @@ static int read_bits_signed(bit_iterator_t* it, int n_bits, lv_fs_res_t* res)
|
||||
|
||||
static int read_label(lv_fs_file_t* fp, int start, const char* label)
|
||||
{
|
||||
LV_FS_SEEK(fp, start);
|
||||
LV_FS_SEEK(fp, start);
|
||||
|
||||
uint32_t length;
|
||||
char buf[4];
|
||||
@ -245,7 +245,7 @@ static bool load_cmaps_tables(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc,
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < font_dsc->cmap_num; ++i) {
|
||||
lv_fs_res_t res =LV_FS_SEEK(fp, cmaps_start + cmap_table[i].data_offset);
|
||||
lv_fs_res_t res = LV_FS_SEEK(fp, cmaps_start + cmap_table[i].data_offset);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return false;
|
||||
}
|
||||
@ -353,7 +353,7 @@ static int32_t load_glyph(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uin
|
||||
for(unsigned int i = 0; i < loca_count; ++i) {
|
||||
lv_font_fmt_txt_glyph_dsc_t* gdsc = &glyph_dsc[i];
|
||||
|
||||
lv_fs_res_t res =LV_FS_SEEK(fp, start + glyph_offset[i]);
|
||||
lv_fs_res_t res = LV_FS_SEEK(fp, start + glyph_offset[i]);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
@ -419,7 +419,7 @@ static int32_t load_glyph(lv_fs_file_t* fp, lv_font_fmt_txt_dsc_t* font_dsc, uin
|
||||
cur_bmp_size = 0;
|
||||
|
||||
for(unsigned int i = 1; i < loca_count; ++i) {
|
||||
lv_fs_res_t res =LV_FS_SEEK(fp, start + glyph_offset[i]);
|
||||
lv_fs_res_t res = LV_FS_SEEK(fp, start + glyph_offset[i]);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -63,40 +63,28 @@ static lv_font_t* font_add_to_list(const char* payload)
|
||||
char* name_p = NULL;
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) && (HASP_USE_FREETYPE > 0)
|
||||
if(!font) {
|
||||
// Try .ttf file
|
||||
char* ext[] = {"ttf", "otf"};
|
||||
for(size_t i = 0; i < 2; i++) {
|
||||
if(!font) {
|
||||
size_t pos = font_split_payload(payload);
|
||||
if(pos > 0 && pos < 56) {
|
||||
uint16_t size = atoi(payload + pos);
|
||||
|
||||
size_t pos = font_split_payload(payload);
|
||||
if(pos > 0 && pos < 56) {
|
||||
uint16_t size = atoi(payload + pos);
|
||||
char fontname[64];
|
||||
memset(fontname, 0, sizeof(fontname));
|
||||
strncpy(fontname, payload, pos);
|
||||
snprintf_P(filename, sizeof(filename), PSTR("L:\\%s.%s"), fontname, ext[i]);
|
||||
|
||||
char fontname[64];
|
||||
memset(fontname, 0, sizeof(fontname));
|
||||
strncpy(fontname, payload, pos);
|
||||
snprintf_P(filename, sizeof(filename), PSTR("L:\\%s.ttf"), fontname);
|
||||
|
||||
lv_ft_info_t info;
|
||||
info.name = filename;
|
||||
info.weight = size;
|
||||
info.style = FT_FONT_STYLE_NORMAL;
|
||||
if(lv_ft_font_init(&info)) {
|
||||
font = info.font;
|
||||
lv_ft_info_t info;
|
||||
info.name = filename;
|
||||
info.weight = size;
|
||||
info.style = FT_FONT_STYLE_NORMAL;
|
||||
if(lv_ft_font_init(&info)) {
|
||||
font = info.font;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if(!font) return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user