1 /** 2 * @file lv_freetype_private.h 3 * 4 */ 5 6 #ifndef LV_FREETYPE_PRIVATE_H 7 #define LV_FREETYPE_PRIVATE_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /********************* 14 * INCLUDES 15 *********************/ 16 17 #include "lv_freetype.h" 18 19 #if LV_USE_FREETYPE 20 21 #include "../../misc/cache/lv_cache.h" 22 #include "../../misc/lv_ll.h" 23 #include "../../font/lv_font.h" 24 #include "ft2build.h" 25 #include FT_FREETYPE_H 26 #include FT_GLYPH_H 27 #include FT_CACHE_H 28 #include FT_SIZES_H 29 #include FT_IMAGE_H 30 #include FT_OUTLINE_H 31 32 /********************* 33 * DEFINES 34 *********************/ 35 36 #ifdef FT_CONFIG_OPTION_ERROR_STRINGS 37 #define FT_ERROR_MSG(msg, error_code) \ 38 LV_LOG_ERROR(msg " error(0x%x): %s", (int)error_code, FT_Error_String(error_code)) 39 #else 40 #define FT_ERROR_MSG(msg, error_code) \ 41 LV_LOG_ERROR(msg " error(0x%x)", (int)error_code) 42 #endif 43 44 #define LV_FREETYPE_FONT_DSC_MAGIC_NUM 0x5F5F4654 /* '__FT' */ 45 #define LV_FREETYPE_FONT_DSC_HAS_MAGIC_NUM(dsc) ((dsc)->magic_num == LV_FREETYPE_FONT_DSC_MAGIC_NUM) 46 #define LV_ASSERT_FREETYPE_FONT_DSC(dsc) \ 47 do { \ 48 LV_ASSERT_NULL(dsc); \ 49 LV_ASSERT_FORMAT_MSG(LV_FREETYPE_FONT_DSC_HAS_MAGIC_NUM(dsc), \ 50 "Invalid font descriptor: 0x%" LV_PRIx32, (dsc)->magic_num); \ 51 } while (0) 52 53 #define FT_INT_TO_F26DOT6(x) ((x) << 6) 54 #define FT_F26DOT6_TO_INT(x) ((x) >> 6) 55 56 #define FT_INT_TO_F16DOT16(x) ((x) << 16) 57 #define FT_F16DOT16_TO_INT(x) ((x) >> 16) 58 59 /********************** 60 * TYPEDEFS 61 **********************/ 62 63 struct _lv_freetype_outline_vector_t { 64 int32_t x; 65 int32_t y; 66 }; 67 68 typedef struct { 69 int32_t segments_size; 70 int32_t data_size; 71 } lv_freetype_outline_sizes_t; 72 73 struct _lv_freetype_outline_event_param_t { 74 lv_freetype_outline_t outline; 75 lv_freetype_outline_type_t type; 76 lv_freetype_outline_vector_t to; 77 lv_freetype_outline_vector_t control1; 78 lv_freetype_outline_vector_t control2; 79 lv_freetype_outline_sizes_t sizes; 80 }; 81 82 83 typedef struct _lv_freetype_cache_node_t lv_freetype_cache_node_t; 84 85 struct _lv_freetype_cache_node_t { 86 const char * pathname; 87 lv_freetype_font_style_t style; 88 lv_freetype_font_render_mode_t render_mode; 89 90 uint32_t ref_size; /**< Reference size for calculating outline glyph's real size.*/ 91 92 FT_Face face; 93 lv_mutex_t face_lock; 94 95 /*glyph cache*/ 96 lv_cache_t * glyph_cache; 97 98 /*draw data cache*/ 99 lv_cache_t * draw_data_cache; 100 }; 101 102 typedef struct _lv_freetype_context_t { 103 FT_Library library; 104 lv_ll_t face_id_ll; 105 lv_event_cb_t event_cb; 106 107 uint32_t max_glyph_cnt; 108 109 lv_cache_t * cache_node_cache; 110 } lv_freetype_context_t; 111 112 typedef struct _lv_freetype_font_dsc_t { 113 uint32_t magic_num; 114 lv_font_t font; 115 uint32_t size; 116 lv_freetype_font_style_t style; 117 lv_freetype_font_render_mode_t render_mode; 118 lv_freetype_context_t * context; 119 lv_freetype_cache_node_t * cache_node; 120 lv_cache_entry_t * cache_node_entry; 121 FTC_FaceID face_id; 122 } lv_freetype_font_dsc_t; 123 124 /********************** 125 * GLOBAL PROTOTYPES 126 **********************/ 127 128 /** 129 * Get the FreeType context. 130 * 131 * @return A pointer to the FreeType context used by LittlevGL. 132 */ 133 lv_freetype_context_t * lv_freetype_get_context(void); 134 135 void lv_freetype_italic_transform(FT_Face face); 136 int32_t lv_freetype_italic_transform_on_pos(lv_point_t point); 137 138 lv_cache_t * lv_freetype_create_glyph_cache(uint32_t cache_size); 139 void lv_freetype_set_cbs_glyph(lv_freetype_font_dsc_t * dsc); 140 141 lv_cache_t * lv_freetype_create_draw_data_image(uint32_t cache_size); 142 void lv_freetype_set_cbs_image_font(lv_freetype_font_dsc_t * dsc); 143 144 lv_cache_t * lv_freetype_create_draw_data_outline(uint32_t cache_size); 145 void lv_freetype_set_cbs_outline_font(lv_freetype_font_dsc_t * dsc); 146 147 /********************** 148 * MACROS 149 **********************/ 150 151 #endif /*LV_USE_FREETYPE*/ 152 153 #ifdef __cplusplus 154 } /*extern "C"*/ 155 #endif 156 157 #endif /*LV_FREETYPE_PRIVATE_H*/ 158