2019-07-15 15:34:23 +08:00
|
|
|
|
#include "tkc/utils.h"
|
|
|
|
|
#include "font_dummy.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
static glyph_t s_glyph_0;
|
|
|
|
|
static glyph_t s_glyph_1;
|
|
|
|
|
static glyph_t s_glyph_2;
|
|
|
|
|
|
2020-06-28 11:26:22 +08:00
|
|
|
|
static uint8_t glyph_data[] = {0x1, 0x2, 0x3, 0x4, 0x5};
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
typedef struct _font_dummy_t {
|
|
|
|
|
font_t base;
|
|
|
|
|
uint16_t font_size;
|
2018-03-18 17:02:10 +08:00
|
|
|
|
} font_dummy_t;
|
2018-03-18 11:29:31 +08:00
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ret_t font_dummy_init() {
|
|
|
|
|
s_glyph_0.x = 0;
|
|
|
|
|
s_glyph_0.y = -10;
|
|
|
|
|
s_glyph_0.w = 10;
|
|
|
|
|
s_glyph_0.h = 10;
|
2020-06-28 11:26:22 +08:00
|
|
|
|
s_glyph_0.data = glyph_data;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
s_glyph_1.x = 0;
|
|
|
|
|
s_glyph_1.y = -11;
|
|
|
|
|
s_glyph_1.w = 11;
|
|
|
|
|
s_glyph_1.h = 11;
|
2020-06-28 11:26:22 +08:00
|
|
|
|
s_glyph_1.data = glyph_data;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
s_glyph_2.x = 0;
|
|
|
|
|
s_glyph_2.y = -5;
|
|
|
|
|
s_glyph_2.w = 12;
|
|
|
|
|
s_glyph_2.h = 12;
|
2020-06-28 11:26:22 +08:00
|
|
|
|
s_glyph_2.data = glyph_data;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-28 17:43:54 +08:00
|
|
|
|
static ret_t font_dummy_get_glyph(font_t* f, wchar_t chr, uint16_t font_size, glyph_t* g) {
|
2018-02-21 19:36:38 +08:00
|
|
|
|
if (chr == 0) {
|
|
|
|
|
*g = s_glyph_0;
|
|
|
|
|
} else if (chr == 1) {
|
|
|
|
|
*g = s_glyph_1;
|
|
|
|
|
} else {
|
|
|
|
|
*g = s_glyph_2;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
(void)font_size;
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
static bool_t font_dummy_match(font_t* f, const char* name, uint16_t font_size) {
|
|
|
|
|
font_dummy_t* font = (font_dummy_t*)f;
|
|
|
|
|
|
2021-02-26 16:27:12 +08:00
|
|
|
|
return tk_str_cmp(f->name, name) == 0 && font->font_size == font_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static font_dummy_t s_font_default;
|
|
|
|
|
font_t* font_dummy_default(const char* name, uint16_t size) {
|
2023-08-01 16:10:16 +08:00
|
|
|
|
memset(&s_font_default, 0x00, sizeof(font_dummy_t));
|
2021-02-26 16:27:12 +08:00
|
|
|
|
s_font_default.font_size = size;
|
|
|
|
|
s_font_default.base.match = font_dummy_match;
|
|
|
|
|
s_font_default.base.get_glyph = font_dummy_get_glyph;
|
|
|
|
|
|
|
|
|
|
tk_strncpy(s_font_default.base.name, name, TK_NAME_LEN);
|
|
|
|
|
|
|
|
|
|
return &s_font_default.base;
|
2018-03-18 11:29:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 18:20:26 +08:00
|
|
|
|
static font_t* font_loader_load_default(font_loader_t* loader, const char* name,
|
|
|
|
|
const uint8_t* buff, uint32_t size) {
|
|
|
|
|
if (tk_str_eq(name, "default")) {
|
2023-08-01 16:10:16 +08:00
|
|
|
|
return font_dummy_default(name, size);
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 18:20:26 +08:00
|
|
|
|
static font_loader_t s_default_font_loader = {.load = font_loader_load_default};
|
2023-08-01 16:10:16 +08:00
|
|
|
|
|
|
|
|
|
font_loader_t* default_font_loader(void) {
|
|
|
|
|
return &s_default_font_loader;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
static font_dummy_t s_font0;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
font_t* font_dummy_0(const char* name, uint16_t size) {
|
2023-08-01 16:10:16 +08:00
|
|
|
|
memset(&s_font0, 0x00, sizeof(font_dummy_t));
|
2018-03-18 11:29:31 +08:00
|
|
|
|
s_font0.font_size = size;
|
|
|
|
|
s_font0.base.match = font_dummy_match;
|
2018-12-28 17:43:54 +08:00
|
|
|
|
s_font0.base.get_glyph = font_dummy_get_glyph;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2019-07-08 08:04:43 +08:00
|
|
|
|
tk_strncpy(s_font0.base.name, name, TK_NAME_LEN);
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
return &s_font0.base;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
static font_dummy_t s_font1;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
font_t* font_dummy_1(const char* name, uint16_t size) {
|
2023-08-01 16:10:16 +08:00
|
|
|
|
memset(&s_font1, 0x00, sizeof(font_dummy_t));
|
2018-03-18 11:29:31 +08:00
|
|
|
|
s_font1.font_size = size;
|
|
|
|
|
s_font1.base.match = font_dummy_match;
|
2018-12-28 17:43:54 +08:00
|
|
|
|
s_font1.base.get_glyph = font_dummy_get_glyph;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2019-07-08 08:04:43 +08:00
|
|
|
|
tk_strncpy(s_font1.base.name, name, TK_NAME_LEN);
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
return &s_font1.base;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
static font_dummy_t s_font2;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
font_t* font_dummy_2(const char* name, uint16_t size) {
|
2023-08-01 16:10:16 +08:00
|
|
|
|
memset(&s_font2, 0x00, sizeof(font_dummy_t));
|
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
s_font2.font_size = size;
|
|
|
|
|
s_font2.base.match = font_dummy_match;
|
2018-12-28 17:43:54 +08:00
|
|
|
|
s_font2.base.get_glyph = font_dummy_get_glyph;
|
2019-07-08 08:04:43 +08:00
|
|
|
|
tk_strncpy(s_font2.base.name, name, TK_NAME_LEN);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2018-03-18 11:29:31 +08:00
|
|
|
|
return &s_font2.base;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|