Bläddra i källkod

update: ufont库也得让idf5库开心才行,修正一些编译警告

Wendal Chen 3 år sedan
förälder
incheckning
44701fdad8

+ 5 - 5
components/eink/luat_lib_eink.c

@@ -29,8 +29,8 @@
 #include "luat_zbuff.h"
 
 #include "luat_ufont.h"
-extern const lv_font_t luat_font_sarasa_bold_16_lvgl;
-static lv_font_t* font_current;
+
+static const lv_font_t* font_current;
 
 static size_t epd_w = 0;
 static size_t epd_h = 0;
@@ -187,7 +187,7 @@ static int l_eink_setup(lua_State *L) {
         }
 
     }
-    font_current = &luat_font_sarasa_bold_16_lvgl;
+    font_current = luat_fonts_default_font();
     lua_pushboolean(L, 1);
     return 1;
 }
@@ -320,10 +320,10 @@ static int l_eink_print(lua_State *L)
 {
     int x, y;
     size_t sz;
-    const uint8_t* str;
+    const char* str;
     x = luaL_checkinteger(L, 1);
     y = luaL_checkinteger(L, 2);
-    str = (const uint8_t*)luaL_checklstring(L, 3, &sz);
+    str = (const char*)luaL_checklstring(L, 3, &sz);
     if (sz == 0)
         return 0;
     ui_draw_str_ctx_t ctx = {

+ 7 - 20
components/fonts/luat_lib_ufont.c

@@ -15,21 +15,8 @@
 
 #include "luat_ufont.h"
 
-extern const luat_font_desc_t luat_font_sarasa_bold_16;
-extern const lv_font_t luat_font_sarasa_bold_16_lvgl;
-
-typedef struct ufont_reg
-{
-    const char* name;
-    const lv_font_t* font;
-}ufont_reg_t;
-
-const ufont_reg_t ufonts[] = {
-#ifdef LUAT_UFONT_FONTS_SARASA_BOLD_16
-    {.name="sarasa_bold_16", .font=&luat_font_sarasa_bold_16_lvgl},
-#endif
-    {.name = NULL, .font = (NULL)}
-};
+extern const ufont_reg_t ufonts[];
+//const ufont_reg_t *ufont_default = &ufonts[0]; 
 
 /*
 获取字体
@@ -41,13 +28,13 @@ const ufont_reg_t ufonts[] = {
 */
 static int l_ufont_get(lua_State *L) {
     const char* font_name = luaL_optstring(L, 1, "sarasa_bold_16");
-    ufont_reg_t* reg = ufonts;
-    for (size_t i = 0; i < sizeof(ufonts)/sizeof(ufont_reg_t); i++)
-    {
+    const ufont_reg_t* reg = ufonts;
+    while (reg->font != NULL) {
         if (strcmp(reg->name, font_name) == 0) {
             lua_pushlightuserdata(L, reg->font);
             return 1;
         }
+        reg ++;
     }
     LLOGW("font not exists [%s]", font_name);
     return 0;
@@ -62,7 +49,7 @@ static int l_ufont_get(lua_State *L) {
 log.info("fonts", "u8g2", json.encode(fonts.list()))
 */
 static int l_ufont_list(lua_State *L) {
-    ufont_reg_t* reg = ufonts;
+    const ufont_reg_t* reg = ufonts;
     lua_createtable(L, 10, 0);
     int index = 1;
     while (reg->font != NULL) {
@@ -83,7 +70,7 @@ static const rotable_Reg_t reg_ufont[] =
 	{ NULL,         ROREG_INT(0)},
 };
 
-LUAMOD_API int luaopen_ufont( lua_State *L ) {
+LUAMOD_API int luaopen_fonts( lua_State *L ) {
     luat_newlib2(L, reg_ufont);
     return 1;
 }

+ 23 - 4
components/fonts/luat_ufont.c

@@ -5,6 +5,8 @@
 #include "luat_log.h"
 
 extern const uint16_t luat_font_map_gb2312_data[];
+extern const lv_font_t luat_fonts_sarasa_bold_16_lvgl;
+extern const ufont_reg_t ufonts[];
 
 static int binsearch(const uint16_t *sortedSeq, int seqLength, uint16_t keyData) {
     int low = 0, mid, high = seqLength - 1;
@@ -34,9 +36,9 @@ int luat_font_get_bitmap(luat_font_header_t *font, luat_font_char_desc_t *dsc_ou
     }
     
     // 暂时只支持内存访问模式, 就先拦截掉其他的吧
-    //LLOGD("font search letter %04X", letter);
-    //LLOGD("font access_mode %02X", font->access_mode);
-    //LLOGD("font font_data_count %02X", font->font_data_count);
+    // LLOGD("font search letter %04X", letter);
+    // LLOGD("font access_mode %02X", font->access_mode);
+    // LLOGD("font font_data_count %02X", font->font_data_count);
     if (font->access_mode != 0x01) {
         LLOGW("only ram access mode is supported, for now");
         return -3;
@@ -167,7 +169,7 @@ int luat_ufont_drawUTF8(ui_draw_str_ctx_t* ctx) {
     uint32_t str_offset;
     int ret = 0;
     uint16_t draw_offset = 0;
-    char bitmap_buff[512] = {0}; // 不会真的有人用64以上的字号吧?
+    uint8_t bitmap_buff[512] = {0}; // 不会真的有人用64以上的字号吧?
 
     int draw_x = 0;
     int draw_y = 0;
@@ -187,6 +189,17 @@ int luat_ufont_drawUTF8(ui_draw_str_ctx_t* ctx) {
        LLOGW("draw without font?!");
        return 0;
     }
+    
+    // LLOGD("font %p", lfont);
+    // LLOGD("want %p", &luat_fonts_sarasa_bold_16_lvgl);
+    // LLOGD("ufonts[0].font %p", ufonts[0].font);
+    // LLOGD("ufonts[0] %p", &ufonts[0]);
+    // LLOGD("ufonts %p", &ufonts);
+    // LLOGD("ufonts[0].name %s", ufonts[0].name);
+    // lfont = &luat_fonts_sarasa_bold_16_lvgl;
+
+    
+
     // 是否填充背景
     bool draw_bg = ctx->draw_mode == 0 ? false : true;
 
@@ -236,6 +249,8 @@ int luat_ufont_drawUTF8(ui_draw_str_ctx_t* ctx) {
           continue;
         }
 
+        //LLOGD("box %d %d", dsc.box_w, dsc.box_h);
+
         draw_x = x + draw_offset;
         draw_offset += dsc.box_w;
         offset = 0;
@@ -250,3 +265,7 @@ int luat_ufont_drawUTF8(ui_draw_str_ctx_t* ctx) {
     //ctx->opts.draw_flush(ctx->userdata);
     return 0;
 }
+
+lv_font_t* luat_fonts_default_font(void) {
+  return ufonts[0].font;
+}

+ 15 - 7
components/fonts/luat_ufont.h

@@ -26,13 +26,13 @@ typedef struct ui_draw_str_ctx
     const ui_draw_opts_t opts;
     void* userdata;
     const char* utf8_letters;
-    int x;
-    int y;
-    uint32_t front_color;
-    uint32_t bg_color;
-    lv_font_t *font;
-    uint16_t ui_w;
-    uint16_t ui_h;
+    const int x;
+    const int y;
+    const uint32_t front_color;
+    const uint32_t bg_color;
+    const lv_font_t *font;
+    const uint16_t ui_w;
+    const uint16_t ui_h;
     uint8_t draw_mode;
 }ui_draw_str_ctx_t;
 
@@ -91,4 +91,12 @@ bool luat_fonts_lvgl_get_glyph_dsc(const struct _lv_font_struct *, lv_font_glyph
 /** Get a glyph's bitmap from a font*/
 const uint8_t * luat_fonts_lvgl_get_glyph_bitmap(const struct _lv_font_struct *, uint32_t);
 
+lv_font_t* luat_fonts_default_font(void);
+
+typedef struct ufont_reg
+{
+    const char* name;
+    const lv_font_t* font;
+}ufont_reg_t;
+
 #endif

+ 5 - 5
components/lcd/luat_lib_lcd.c

@@ -23,8 +23,8 @@
 extern luat_color_t BACK_COLOR , FORE_COLOR ;
 
 #include "luat_ufont.h"
-extern const lv_font_t luat_font_sarasa_bold_16_lvgl;
-static lv_font_t* font_current;
+
+static const lv_font_t* font_current;
 
 extern const luat_lcd_opts_t lcd_opts_st7735;
 extern const luat_lcd_opts_t lcd_opts_st7735v;
@@ -260,7 +260,7 @@ static int l_lcd_init(lua_State* L) {
         }
         // 初始化OK, 配置额外的参数
         default_conf = conf;
-        font_current = &luat_font_sarasa_bold_16_lvgl;
+        font_current = luat_fonts_default_font();
         lua_pushboolean(L, 1);
         return 1;
     }
@@ -720,10 +720,10 @@ lcd.drawStr(40,40,"drawStr测试")
 static int l_lcd_draw_str(lua_State* L) {
     int x, y;
     size_t sz;
-    const uint8_t* str;
+    const char* str;
     x = luaL_checkinteger(L, 1);
     y = luaL_checkinteger(L, 2);
-    str = (const uint8_t*)luaL_checklstring(L, 3, &sz);
+    str = (const char*)luaL_checklstring(L, 3, &sz);
     lcd_str_fg_color = (luat_color_t)luaL_optinteger(L, 4,FORE_COLOR);
     // lcd_str_bg_color = (uint32_t)luaL_optinteger(L, 5,BACK_COLOR);
     if (sz == 0)

+ 2 - 5
components/u8g2/luat_lib_u8g2.c

@@ -22,11 +22,8 @@
 #include "luat_log.h"
 
 #include "luat_ufont.h"
+static const lv_font_t* font_current;
 
-
-extern const lv_font_t luat_font_sarasa_bold_16_lvgl;
-
-static lv_font_t* font_current;
 static uint8_t font_mode;
 
 static u8g2_t* u8g2 = NULL;
@@ -213,7 +210,7 @@ static int l_u8g2_begin(lua_State *L) {
     LLOGD("setup done");
     u8g2_lua_ref = luaL_ref(L, LUA_REGISTRYINDEX);
     //u8g2_SetFont(u8g2, u8g2_font_ncenB08_tr); // 设置默认字体
-    font_current = &luat_font_sarasa_bold_16_lvgl;
+    font_current = luat_fonts_default_font();
     lua_pushinteger(L, 1);
     return 1;
 }