bitmap_font_api.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef __BITMAP_FONT_API_H__
  2. #define __BITMAP_FONT_API_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*********************
  7. * INCLUDES
  8. *********************/
  9. #include <fs/fs.h>
  10. #include <stdint.h>
  11. /*********************
  12. * DEFINES
  13. *********************/
  14. #define MAX_FONT_PATH_LEN 64
  15. #ifdef CONFIG_BITMAP_FONT_USE_HIGH_FREQ_CACHE
  16. #define MAX_CACHED_GLYPH_BITMAPS 64
  17. #else
  18. #define MAX_CACHED_GLYPH_BITMAPS 200
  19. #endif
  20. #define CACHED_GLYPH_ID_BITS 4
  21. #define MAX_CACHED_GLYPH_IDS (1 << CACHED_GLYPH_ID_BITS)
  22. #define USE_BSEARCH_IN_GLYPH_ID 1
  23. /**********************
  24. * TYPEDEFS
  25. **********************/
  26. typedef enum
  27. {
  28. BITMAP_FONT_FORMAT_4BPP,
  29. BITMAP_FONT_FORMAT_UNSUPPORTED,
  30. }bitmap_font_format_e;
  31. typedef struct
  32. {
  33. uint32_t advance;
  34. uint32_t bbw;
  35. uint32_t bbh;
  36. int32_t bbx;
  37. int32_t bby;
  38. int32_t metric_size;
  39. }glyph_metrics_t;
  40. typedef struct
  41. {
  42. uint32_t current;
  43. uint32_t next;
  44. uint32_t cached_total;
  45. uint32_t* glyph_index;
  46. glyph_metrics_t* metrics;
  47. uint8_t* data;
  48. glyph_metrics_t default_metric;
  49. uint8_t* default_data;
  50. uint32_t inited;
  51. uint32_t unit_size;
  52. uint32_t cached_max;
  53. uint32_t cache_max_size;
  54. /* last mapping */
  55. uint32_t last_unicode[MAX_CACHED_GLYPH_IDS];
  56. uint32_t last_glyph_id[MAX_CACHED_GLYPH_IDS];
  57. #if MAX_CACHED_GLYPH_IDS > 1
  58. uint16_t last_unicode_idx;
  59. uint16_t curr_unicode_idx;
  60. #endif
  61. uint32_t last_glyph_idx;
  62. }bitmap_cache_t;
  63. typedef struct{
  64. uint32_t unicode;
  65. uint16_t width;
  66. uint16_t height;
  67. uint32_t offset;
  68. uint16_t advance;
  69. int16_t descent;
  70. }emoji_font_entry_t;
  71. typedef struct
  72. {
  73. struct fs_file_t font_fp;
  74. bitmap_cache_t* cache;
  75. emoji_font_entry_t* glyf_list;
  76. uint32_t glyf_count;
  77. uint16_t font_width;
  78. uint16_t font_height;
  79. int16_t ascent;
  80. int16_t descent;
  81. uint32_t default_advance;
  82. uint32_t bpp;
  83. uint32_t inited;
  84. uint32_t ref_count;
  85. uint32_t default_code;
  86. uint32_t first_code;
  87. uint8_t* emoji_mmap_addr;
  88. }bitmap_emoji_font_t;
  89. typedef struct
  90. {
  91. struct fs_file_t font_fp;
  92. bitmap_cache_t* cache;
  93. uint8_t font_path[MAX_FONT_PATH_LEN];
  94. uint16_t font_size;
  95. int16_t ascent;
  96. int16_t descent;
  97. uint16_t default_advance;
  98. uint32_t font_format;
  99. uint32_t loca_format;
  100. uint32_t glyfid_format;
  101. uint32_t adw_format;
  102. uint32_t bpp;
  103. uint32_t bbxy_length;
  104. uint32_t bbwh_length;
  105. uint32_t adw_length;
  106. uint32_t compress_alg;
  107. uint32_t cmap_offset;
  108. uint32_t loca_offset;
  109. uint32_t glyf_offset;
  110. uint32_t ref_count;
  111. uint8_t* cmap_sub_headers;
  112. uint32_t cmap_sub_count;
  113. uint32_t default_code;
  114. }bitmap_font_t;
  115. typedef struct
  116. {
  117. char* font_path;
  118. int cache_size_preset;
  119. }bitmap_font_cache_preset_t;
  120. /**********************
  121. * GLOBAL PROTOTYPES
  122. **********************/
  123. int bitmap_font_init(void);
  124. int bitmap_font_deinit(void);
  125. bitmap_font_t* bitmap_font_open(const char* file_path);
  126. void bitmap_font_close(bitmap_font_t* font);
  127. uint8_t * bitmap_font_get_bitmap(bitmap_font_t* font, bitmap_cache_t* cache, uint32_t unicode);
  128. glyph_metrics_t* bitmap_font_get_glyph_dsc(bitmap_font_t* font, bitmap_cache_t *cache, uint32_t unicode);
  129. bitmap_cache_t* bitmap_font_get_cache(bitmap_font_t* font);
  130. bitmap_emoji_font_t* bitmap_emoji_font_open(const char* file_path);
  131. void bitmap_emoji_font_close(bitmap_emoji_font_t* emoji_font);
  132. uint8_t * bitmap_font_get_emoji_bitmap(bitmap_emoji_font_t* font, uint32_t unicode);
  133. glyph_metrics_t* bitmap_font_get_emoji_glyph_dsc(bitmap_emoji_font_t* font, uint32_t unicode, bool force_retrieve);
  134. void bitmap_font_load_high_freq_chars(const uint8_t* file_path);
  135. int bitmap_font_set_default_emoji_code(bitmap_emoji_font_t* font, uint32_t emoji_code);
  136. int bitmap_font_set_default_code(bitmap_font_t* font, uint32_t letter_code);
  137. int bitmap_font_set_default_bitmap(bitmap_font_t* font, uint8_t* bitmap, uint32_t width, uint32_t height, uint32_t gap, uint32_t bpp);
  138. int bitmap_font_cache_preset(bitmap_font_cache_preset_t* preset, int count);
  139. void bitmap_font_dump_info(void);
  140. /**********************
  141. * MACROS
  142. **********************/
  143. #ifdef __cplusplus
  144. } /* extern "C" */
  145. #endif
  146. #endif /*__BITMAP_FONT_API_H__*/