فهرست منبع

add:eink添加gtfont

Dozingfiretruck 4 سال پیش
والد
کامیت
d7feb0f5a9
2فایلهای تغییر یافته به همراه131 افزوده شده و 1 حذف شده
  1. 9 0
      components/gtfont/luat_lib_gtfont.c
  2. 122 1
      luat/packages/eink/luat_lib_eink.c

+ 9 - 0
components/gtfont/luat_lib_gtfont.c

@@ -10,6 +10,8 @@
 #include "luat_lcd.h"
 #include "luat_malloc.h"
 
+#include "epdpaint.h"
+
 #include "GT5SLCD2E_1A.h"
 #define LUAT_LOG_TAG "gt"
 #include "luat_log.h"
@@ -29,9 +31,11 @@ void gtfont_draw_w(unsigned char *pBits,unsigned int x,unsigned int y,unsigned i
 				if(((temp << k)& 0x80) == 0 ){
 					/* 显示一个像素点 */
 					if (mode == 0)point((luat_lcd_conf_t *)userdata, x+k+(j*8), y+i, 0xFFFF);
+					if (mode == 1)point((Paint *)userdata, x+k+(j*8), y+i, 0xFFFF);
 				}else{
 					/* 显示一个像素点 */
 					if (mode == 0)point((luat_lcd_conf_t *)userdata, x+k+(j*8), y+i, 0x0000);
+					if (mode == 1)point((Paint *)userdata, x+k+(j*8), y+i, 0x0000);
 				}
 			}
 		}
@@ -67,6 +71,7 @@ void gtfont_draw_gray_hz (unsigned char *data,unsigned short x,unsigned short y,
 				c<<=2;
 				if(x<(x_temp+w)){
 					if (mode == 0)point((luat_lcd_conf_t *)userdata,x,y,temp);
+					if (mode == 1)point((Paint *)userdata, x,y,temp);
 				}
 				x++;
 				if(x>=x_temp+(w+7)/8*8) {x=x_temp; y++;}
@@ -99,6 +104,7 @@ void gtfont_draw_gray_hz (unsigned char *data,unsigned short x,unsigned short y,
 				temp =color;
 				if(x<(x_temp+w)){
 					if (mode == 0)point((luat_lcd_conf_t *)userdata,x,y,temp);
+					if (mode == 1)point((Paint *)userdata, x,y,temp);
 				}
 				x++;
 				if(x>=x_temp+(w+7)/8*8) {x=x_temp; y++;}
@@ -120,6 +126,7 @@ void gtfont_draw_gray_hz (unsigned char *data,unsigned short x,unsigned short y,
 				c<<=4;
 				if(x<(x_temp+w)){
 					if (mode == 0)point((luat_lcd_conf_t *)userdata,x,y,temp);
+					if (mode == 1)point((Paint *)userdata, x,y,temp);
 				}
 				x++;
 				if(x>=x_temp+(w+7)/8*8) {x=x_temp; y++;}
@@ -136,8 +143,10 @@ void gtfont_draw_gray_hz (unsigned char *data,unsigned short x,unsigned short y,
 				if(x<(x_temp+w)){
 					if(color == 0x0000 && HB_par == 1){
 						if (mode == 0)point((luat_lcd_conf_t *)userdata,x,y,color);
+						if (mode == 1)point((Paint *)userdata, x,y,color);
 					}else if(HB_par == 0 && color == 0x0000){
 						if (mode == 0)point((luat_lcd_conf_t *)userdata,x,y,~color);
+						if (mode == 1)point((Paint *)userdata, x,y,~color);
 					}
 				}
 				x++;

+ 122 - 1
luat/packages/eink/luat_lib_eink.c

@@ -844,6 +844,120 @@ static int l_eink_model(lua_State *L) {
     return 0;
 }
 
+#ifdef LUAT_USE_GTFONT
+
+#include "GT5SLCD2E_1A.h"
+extern void gtfont_draw_w(unsigned char *pBits,unsigned int x,unsigned int y,unsigned int widt,unsigned int high,int(*point)(void*),void* userdata,int mode);
+extern void gtfont_draw_gray_hz(unsigned char *data,unsigned short x,unsigned short y,unsigned short w ,unsigned short h,unsigned char grade, unsigned char HB_par,int(*point)(void*,uint16_t, uint16_t, uint32_t),void* userdata,int mode);
+
+static int l_eink_draw_gtfont_gb2312(lua_State *L) {
+    unsigned char buf[128];
+	int len;
+	int i = 0;
+	uint8_t strhigh,strlow ;
+	uint16_t str;
+  const char *fontCode = luaL_checklstring(L, 1,&len);
+  unsigned char size = luaL_checkinteger(L, 2);
+	int x = luaL_checkinteger(L, 3);
+	int y = luaL_checkinteger(L, 4);
+	while ( i < len){
+		strhigh = *fontCode;
+		fontCode++;
+		strlow = *fontCode;
+		str = (strhigh<<8)|strlow;
+		fontCode++;
+		get_font(buf, 1, str, size, size, size);
+		gtfont_draw_w(buf , x ,y , size , size,Paint_DrawPixel,&paint,1);
+		x+=size;
+		i+=2;
+	}
+    return 0;
+}
+
+static int l_eink_draw_gtfont_gb2312_gray(lua_State* L) {
+	unsigned char buf[2048];
+	int len;
+	int i = 0;
+	uint8_t strhigh,strlow ;
+	uint16_t str;
+    const char *fontCode = luaL_checklstring(L, 1,&len);
+    unsigned char size = luaL_checkinteger(L, 2);
+	unsigned char font_g = luaL_checkinteger(L, 3);
+	int x = luaL_checkinteger(L, 4);
+	int y = luaL_checkinteger(L, 5);
+	while ( i < len){
+		strhigh = *fontCode;
+		fontCode++;
+		strlow = *fontCode;
+		str = (strhigh<<8)|strlow;
+		fontCode++;
+		get_font(buf, 1, str, size*font_g, size*font_g, size*font_g);
+		Gray_Process(buf,size,size,font_g);
+		gtfont_draw_gray_hz(buf, x, y, size , size, font_g, 1,Paint_DrawPixel,&paint,1);
+		x+=size;
+		i+=2;
+	}
+    return 0;
+}
+
+#ifdef LUAT_USE_GTFONT_UTF8
+extern unsigned short unicodetogb2312 ( unsigned short	chr);
+static int l_eink_draw_gtfont_utf8(lua_State *L) {
+    unsigned char buf[128];
+    int len;
+    int i = 0;
+    uint8_t strhigh,strlow ;
+    uint16_t e,str;
+    const char *fontCode = luaL_checklstring(L, 1,&len);
+    unsigned char size = luaL_checkinteger(L, 2);
+    int x = luaL_checkinteger(L, 3);
+    int y = luaL_checkinteger(L, 4);
+    for(;;){
+      e = utf8_next((uint8_t)*fontCode);
+      if ( e == 0x0ffff )
+      break;
+      fontCode++;
+      if ( e != 0x0fffe ){
+        uint16_t str = unicodetogb2312(e);
+        get_font(buf, 1, str, size, size, size);
+        gtfont_draw_w(buf , x ,y , size , size,Paint_DrawPixel,&paint,1);
+        x+=size;    
+      }
+    }
+    return 0;
+}
+
+static int l_eink_draw_gtfont_utf8_gray(lua_State* L) {
+	unsigned char buf[2048];
+	int len;
+	int i = 0;
+	uint8_t strhigh,strlow ;
+	uint16_t e,str;
+  const char *fontCode = luaL_checklstring(L, 1,&len);
+  unsigned char size = luaL_checkinteger(L, 2);
+	unsigned char font_g = luaL_checkinteger(L, 3);
+	int x = luaL_checkinteger(L, 4);
+	int y = luaL_checkinteger(L, 5);
+	for(;;){
+        e = utf8_next((uint8_t)*fontCode);
+        if ( e == 0x0ffff )
+        break;
+        fontCode++;
+        if ( e != 0x0fffe ){
+			uint16_t str = unicodetogb2312(e);
+			get_font(buf, 1, str, size*font_g, size*font_g, size*font_g);
+			Gray_Process(buf,size,size,font_g);
+      gtfont_draw_gray_hz(buf, x, y, size , size, font_g, 1,Paint_DrawPixel,&paint,1);
+        	x+=size;    
+        }
+    }
+    return 0;
+}
+
+#endif // LUAT_USE_GTFONT_UTF8
+
+#endif // LUAT_USE_GTFONT
+
 #include "rotable.h"
 static const rotable_Reg reg_eink[] =
 {
@@ -862,7 +976,14 @@ static const rotable_Reg reg_eink[] =
     { "weather_icon",   l_eink_weather_icon,    0},
 
     { "model",          l_eink_model,           0},
-
+#ifdef LUAT_USE_GTFONT
+    { "drawGtfontGb2312", l_eink_draw_gtfont_gb2312, 0},
+    { "drawGtfontGb2312Gray", l_eink_draw_gtfont_gb2312_gray, 0},
+#ifdef LUAT_USE_GTFONT_UTF8
+    { "drawGtfontUtf8", l_eink_draw_gtfont_utf8, 0},
+    { "drawGtfontUtf8Gray", l_eink_draw_gtfont_utf8_gray, 0},
+#endif // LUAT_USE_GTFONT_UTF8
+#endif // LUAT_USE_GTFONT
     { "MODEL_1in02d",         NULL,                 MODEL_1in02d},
     { "MODEL_1in54",          NULL,                 MODEL_1in54},
     { "MODEL_1in54_V2",       NULL,                 MODEL_1in54_V2},