diff --git a/fontool/bdfont.c b/fontool/bdfont.c index 5f94bd2..5a06061 100644 --- a/fontool/bdfont.c +++ b/fontool/bdfont.c @@ -296,6 +296,10 @@ int load_ttf(char *ttf_name) } } + // 针对7段数字字体的空格,将其宽度处理成和数字一样。 + if(font_size>24 && ctab[0x20] && ctab[0x30]){ + ctab[0x20]->advance = ctab[0x30]->advance; + } FT_Done_Face(ft_face); FT_Done_FreeType(ft_lib); diff --git a/fontool/dseg.txt b/fontool/dseg.txt index 47b150b..8fc6518 100644 Binary files a/fontool/dseg.txt and b/fontool/dseg.txt differ diff --git a/fontool/epd_gui.c b/fontool/epd_gui.c index 7295ba5..7f71d2f 100644 --- a/fontool/epd_gui.c +++ b/fontool/epd_gui.c @@ -69,6 +69,12 @@ const u8 *font_list[6] = { F_DSEG7_66, }; +const u8 font_bt[] = { + 0x08, 0x08, 0x0f, 0x00, 0x00, + 0x10, 0x18, 0x14, 0x92, 0x51, 0x32, 0x14, 0x18, + 0x14, 0x32, 0x51, 0x92, 0x14, 0x18, 0x10, +}; + const u8 *current_font = (u8*)sfont; int select_font(int id) @@ -95,13 +101,9 @@ static const u8 *find_font(const u8 *font, int ucs) } -int fb_draw_font(int x, int y, int ucs, int color) +int fb_draw_font_info(int x, int y, const u8 *font_data, int color) { int r, c; - const u8 *font_data = find_font(current_font, ucs); - if(font_data==NULL){ - printf("fb_draw %04x: not found!\n", ucs); - } int ft_adv = font_data[0]; int ft_bw = font_data[1]; @@ -131,6 +133,18 @@ int fb_draw_font(int x, int y, int ucs, int color) } +int fb_draw_font(int x, int y, int ucs, int color) +{ + const u8 *font_data = find_font(current_font, ucs); + if(font_data==NULL){ + printf("fb_draw %04x: not found!\n", ucs); + return -1; + } + + return fb_draw_font_info(x, y, font_data, color); +} + + static int utf8_to_ucs(char **ustr) { u8 *str = (u8*)*ustr; @@ -172,26 +186,53 @@ char *wday_str[] = {"日", "一", "二", "三", "四", "五", "六"}; static int wday = 0; + typedef struct { int xres, yres; int font_char; int font_dseg; - int top; - int mid; - int bottom; - int t1; - int m1; - int b1; + u16 x[8]; + u16 y[8]; }LAYOUT; +// 坐标0: 公历日期 +// 坐标1: 蓝牙图标 +// 坐标2: 电池图标 +// 坐标3: 时间 +// 坐标4: 农历日期 +// 坐标5: 节气 +// 坐标6: 节日 +// 坐标7: 上下午 + LAYOUT layouts[3] = { - {212, 104, 0, 2, 6, 27, 82, 15, 20, 12}, - {250, 122, 1, 3, 6, 28, 98, 15, 16, 12}, - {296, 128, 1, 3, 6, 30, 102, 15, 36, 12}, + {212, 104, 0, 2, + {15, 172, 190, 16, 12, 98, 150, 12}, + { 6, 7, 14, 27, 82, 82, 82, 44}, + }, + {250, 122, 1, 3, + {15, 206, 226, 12, 12, 118, 176, 15}, + { 6, 8, 15, 28, 98, 98, 98, 50}, + }, + {296, 128, 1, 3, + {15, 246, 268, 30, 12, 140, 220, 15,}, + { 6, 8, 15, 30, 102, 102, 102, 52,}, + }, }; int current_layout = 0; + +static void draw_batt(int x, int y, int level) +{ + int p = level; + + draw_rect(x, y-4, x+14, y+4, BLACK); + draw_box(x-2, y-1, x-1, y+1, BLACK); + + draw_box(x+12-p, y-2, x+12, y+2, BLACK); +} + + void fb_test(void) { LAYOUT *lt = &layouts[current_layout]; @@ -200,19 +241,40 @@ void fb_test(void) select_font(lt->font_char); char tbuf[64]; sprintf(tbuf, "%4d年%2d月%2d日 星期%s", 2025, 4, 29, wday_str[wday]); - draw_text(lt->t1, lt->top, tbuf, BLACK); + draw_text(lt->x[0], lt->y[0], tbuf, BLACK); + + // 显示蓝牙图标 + fb_draw_font_info(lt->x[1], lt->y[1], font_bt, BLACK); + + // 显示电池图标 + draw_batt(lt->x[2], lt->y[2], 9); + + // 显示农历日期(不显示年) - sprintf(tbuf, "%s月%s日", wday_str[wday], wday_str[wday]); - draw_text(lt->b1, lt->bottom, tbuf, BLACK); + sprintf(tbuf, "%s月%s日", wday_str[wday+1], wday_str[wday+2]); + draw_text(lt->x[4], lt->y[4], tbuf, BLACK); + + // 显示节气 + strcpy(tbuf, "小寒"); + draw_text(lt->x[5], lt->y[5], tbuf, BLACK); + + // 显示节日 + strcpy(tbuf, "中秋节"); + draw_text(lt->x[6], lt->y[6], tbuf, BLACK); + + // 使用大字显示时间 + select_font(lt->font_dseg); + sprintf(tbuf, "%2d:%02d", 12+wday, 31+wday); + draw_text(lt->x[3], lt->y[3], tbuf, BLACK); + + select_font(lt->font_char); + draw_text(lt->x[7], lt->y[7], "上午", BLACK); + wday += 1; if(wday==7) wday = 0; - // 使用大字显示时间 - select_font(lt->font_dseg); - sprintf(tbuf, "%02d:%02d", 2+wday, 31+wday); - draw_text(lt->m1, lt->mid, tbuf, BLACK); } @@ -220,22 +282,24 @@ void fb_test(void) int main(int argc, char *argv[]) { - int scr_w, scr_h; + int i, scr_w, scr_h; + for(i=0; i<3; i++){ + current_layout = i; + scr_w = layouts[i].xres; + scr_h = layouts[i].yres; + printf("Layout %d: %dx%d\n", i, scr_w, scr_h); -// scr_w = 212; scr_h = 104; current_layout = 0; -// scr_w = 250; scr_h = 122; current_layout = 1; - scr_w = 296; scr_h = 128; current_layout = 2; + gdifb_init(scr_w, scr_h); + draw_box(0, 0, scr_w-1, scr_h-1, WHITE); + draw_rect(0, 0, scr_w-1, scr_h-1, RED); + fb_test(); - gdifb_init(scr_w, scr_h); - draw_box(0, 0, scr_w-1, scr_h-1, WHITE); - draw_rect(0, 0, scr_w-1, scr_h-1, RED); - - fb_test(); - - gdifb_flush(); - gdifb_exit(); + gdifb_flush(); + gdifb_waitkey(); + gdifb_exit(1); + } return 0; } diff --git a/fontool/gdifb.c b/fontool/gdifb.c index 49de35d..7e677af 100644 --- a/fontool/gdifb.c +++ b/fontool/gdifb.c @@ -20,6 +20,7 @@ static HBITMAP hbmp; static HDC hmemdc; static HANDLE h_gdifb; +static HANDLE h_window; static DWORD gdifb_id; static HWND gdifb; @@ -95,7 +96,6 @@ void memdc_create(HWND hwnd) BOOL InitInstance() { - HWND hWnd; DWORD style = WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_MAXIMIZEBOX; RECT rect; @@ -105,18 +105,18 @@ BOOL InitInstance() rect.bottom = height; AdjustWindowRect(&rect, style, FALSE); - hWnd=CreateWindow("GDI_FB", "GDI_FB", style, CW_USEDEFAULT, 0, + h_window = CreateWindow("GDI_FB", "GDI_FB", style, CW_USEDEFAULT, 0, rect.right-rect.left, rect.bottom-rect.top, 0, 0, hInst, 0); - if (!hWnd){ + if (!h_window){ return FALSE; } - memdc_create(hWnd); + memdc_create(h_window); - ShowWindow(hWnd, SW_SHOWDEFAULT); - UpdateWindow(hWnd); + ShowWindow(h_window, SW_SHOWDEFAULT); + UpdateWindow(h_window); return TRUE; } @@ -248,8 +248,12 @@ int gdifb_init(int w, int h) } -int gdifb_exit(void) +int gdifb_exit(int force) { + if(force){ + SendMessage(h_window, WM_CLOSE, 0, 0); + } + WaitForSingleObject(h_gdifb,INFINITE); CloseHandle(h_gdifb); diff --git a/fontool/gdifb.h b/fontool/gdifb.h index 46340de..f44e8f8 100644 --- a/fontool/gdifb.h +++ b/fontool/gdifb.h @@ -5,7 +5,7 @@ extern unsigned char *gdifbuf; int gdifb_init(int w, int h); void gdifb_flush(void); -int gdifb_exit(void); +int gdifb_exit(int force); void gdifb_textout(int x, int y, char *text); diff --git a/fontool/small.txt b/fontool/small.txt index bd5343c..df39881 100644 Binary files a/fontool/small.txt and b/fontool/small.txt differ