Ver Fonte

fix: easylvgl, 增加LUAT_USE_HZFONT编译条件判断

zengeshuai há 3 meses atrás
pai
commit
c831b260e4

+ 8 - 0
components/easylvgl/binding/luat_lib_easylvgl.c

@@ -323,10 +323,18 @@ static int l_easylvgl_font_load(lua_State *L) {
         int antialias = luaL_optinteger(L, 5, -1);
         is_default = lua_toboolean(L, 6);
         font = easylvgl_font_hzfont_create(path, size, cache_size, antialias);
+        if (font == NULL) {
+            LLOGE("font_load: failed to create hzfont");
+            return 0;
+        }
     } else if (strcmp(type, "bin") == 0) {
         const char *path = luaL_checkstring(L, 2);
         is_default = lua_toboolean(L, 3);
         font = lv_binfont_create(path);
+        if (font == NULL) {
+            LLOGE("font_load: failed to create bin font");
+            return 0;
+        }
     } else {
         LLOGE("font_load: unsupported type %s", type);
         return 0;

+ 25 - 3
components/easylvgl/src/font/lv_font_hzfont.c

@@ -2,12 +2,16 @@
 
 #include "lvgl9/lvgl.h"
 #include "luat_base.h"
-#include "luat_hzfont.h"
-#include "ttf_parser.h"
 
 #define LUAT_LOG_TAG "easylvgl.hzfont"
 #include "luat_log.h"
 
+#ifdef LUAT_USE_HZFONT
+
+#include "luat_hzfont.h"
+#include "ttf_parser.h"
+
+
 /** 
  * HZFont 字体描述私有数据结构 
  */
@@ -160,7 +164,8 @@ static const void * hzfont_get_glyph_bitmap(lv_font_glyph_dsc_t * dsc_out, lv_dr
 lv_font_t * easylvgl_font_hzfont_create(const char * path, uint16_t size, uint32_t cache_size, int antialias) {
     // 1. 初始化底层引擎(单例模式)
     if (luat_hzfont_get_state() == LUAT_HZFONT_STATE_UNINIT) {
-        if (!luat_hzfont_init(path, cache_size)) {
+        if (!luat_hzfont_init(path, cache_size, 1)) // 当前默认不将hzfont加载到psram中
+        {
             LLOGE("hzfont init failed: %s", path ? path : "builtin");
             return NULL;
         }
@@ -201,3 +206,20 @@ lv_font_t * easylvgl_font_hzfont_create(const char * path, uint16_t size, uint32
     font->base_line = (int32_t)font->line_height > ascent ? (int32_t)font->line_height - ascent : 0;
     return font;
 }
+
+#else
+
+static bool hzfont_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, uint32_t letter_next) {
+    return false;
+}
+
+static const void * hzfont_get_glyph_bitmap(lv_font_glyph_dsc_t * dsc_out, lv_draw_buf_t * draw_buf) {
+    return NULL;
+}
+
+lv_font_t * easylvgl_font_hzfont_create(const char * path, uint16_t size, uint32_t cache_size, int antialias) {
+    LLOGW("该固件不支持HZFont字体");
+    return NULL;
+}
+
+#endif

+ 2 - 0
components/hzfont/src/luat_hzfont.c

@@ -627,6 +627,7 @@ int luat_hzfont_init(const char *ttf_path, uint32_t cache_size, int load_to_psra
         if (load_to_psram) {
             ram_buf = (uint8_t *)luat_heap_malloc((size_t)hzfont_builtin_ttf_len);
             if (!ram_buf) {
+                LLOGE("load builtin ttf to ram failed");
                 rc = TTF_ERR_OOM;
             } else {
                 memcpy(ram_buf, hzfont_builtin_ttf, (size_t)hzfont_builtin_ttf_len);
@@ -636,6 +637,7 @@ int luat_hzfont_init(const char *ttf_path, uint32_t cache_size, int load_to_psra
                     g_ft_ctx.font.ownsData = 1;
                     g_ft_ctx.font_path[0] = '\0';
                 } else {
+                    LLOGE("load builtin ttf to ram failed rc=%d", rc);
                     luat_heap_free(ram_buf);
                     ram_buf = NULL;
                 }