luat_ufont.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef LUAT_UFONT_H_
  2. #define LUAT_UFONT_H_
  3. #include "luat_base.h"
  4. // LVGL fonts
  5. #include "lvgl.h"
  6. #include "lv_font.h"
  7. typedef void (*ui_draw_point)(void* userdata, int x, int y, uint32_t color);
  8. typedef void (*ui_draw_line)(void* userdata, int x1, int y1, int x2, int y2, uint32_t color);
  9. typedef void (*ui_draw_block)(void* userdata, int x, int y, int w, int h, size_t bitw, void* data);
  10. typedef void (*ui_draw_fill)(void* userdata, int x, int y, int w, int h, uint32_t color);
  11. typedef void (*ui_draw_flush)(void* userdata);
  12. typedef struct ui_draw_opts {
  13. ui_draw_point draw_point;
  14. ui_draw_line draw_line;
  15. ui_draw_block draw_block;
  16. ui_draw_fill draw_fill;
  17. ui_draw_flush draw_flush;
  18. } ui_draw_opts_t;
  19. typedef struct ui_draw_str_ctx
  20. {
  21. const ui_draw_opts_t opts;
  22. void* userdata;
  23. const char* utf8_letters;
  24. const int x;
  25. const int y;
  26. const uint32_t front_color;
  27. const uint32_t bg_color;
  28. const lv_font_t *font;
  29. const uint16_t ui_w;
  30. const uint16_t ui_h;
  31. uint8_t draw_mode;
  32. }ui_draw_str_ctx_t;
  33. typedef struct luat_font_data {
  34. uint8_t map_type; // 类型数据, 后面有详细说明
  35. uint8_t unicode_size; // map表单个字符的字节大小, 可以是2,4
  36. uint16_t bitmap_size; // 单个字符的bitmap数据的字节大小
  37. uint8_t char_w_bit;
  38. uint8_t bitmap_compress_block;
  39. uint16_t count; // 字符数量
  40. uint32_t unicode_min;
  41. uint32_t unicode_max;
  42. uint8_t *map_data;
  43. uint16_t *bitmap_compress_size;
  44. uint8_t *bitmap_data;
  45. // uint32_t reserved; // 保留区域, 扩展用, 默认0x0000
  46. }luat_font_data_t;
  47. typedef struct luat_font_header
  48. {
  49. uint8_t magic; // 总是 0xC5
  50. uint8_t version; // 当前为0x0001
  51. uint8_t line_height; // 字号
  52. uint8_t access_mode : 4; // 访问模式
  53. uint8_t font_data_count : 4; // 数据总数, 通常就1或2个,不会很多.
  54. uint32_t reserved; // 保留区域, 扩展用, 默认0x0000
  55. }luat_font_header_t;
  56. typedef struct luat_font_desc
  57. {
  58. luat_font_header_t header;
  59. luat_font_data_t *datas;
  60. }luat_font_desc_t;
  61. typedef struct luat_font_char_desc
  62. {
  63. // uint32_t unicode;
  64. uint32_t line_height;
  65. uint16_t char_w;
  66. uint16_t reserved;
  67. uint16_t len;
  68. uint8_t *data;
  69. }luat_font_char_desc_t;
  70. int luat_font_get_bitmap(luat_font_header_t *font, luat_font_char_desc_t *dsc_out, uint32_t letter);
  71. uint16_t luat_utf8_next(uint8_t b, uint8_t *utf8_state, uint16_t *encoding);
  72. int luat_ufont_drawUTF8(ui_draw_str_ctx_t* ctx);
  73. /** Get a glyph's descriptor from a font*/
  74. bool luat_fonts_lvgl_get_glyph_dsc(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next);
  75. /** Get a glyph's bitmap from a font*/
  76. const uint8_t * luat_fonts_lvgl_get_glyph_bitmap(const struct _lv_font_struct *, uint32_t);
  77. lv_font_t* luat_fonts_default_font(void);
  78. typedef struct ufont_reg
  79. {
  80. const char* name;
  81. const lv_font_t* font;
  82. }ufont_reg_t;
  83. #endif