refactor(freetype): refactor glyph_index acquire method
This commit is contained in:
@@ -40,10 +40,6 @@ typedef struct {
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static FT_Error lv_freetype_face_requester(FTC_FaceID face_id,
|
|
||||||
FT_Library library,
|
|
||||||
FT_Pointer req_data,
|
|
||||||
FT_Face * aface);
|
|
||||||
static void lv_freetype_cleanup(lv_freetype_context_t * ctx);
|
static void lv_freetype_cleanup(lv_freetype_context_t * ctx);
|
||||||
static FTC_FaceID lv_freetype_req_face_id(lv_freetype_context_t * ctx, const char * pathname);
|
static FTC_FaceID lv_freetype_req_face_id(lv_freetype_context_t * ctx, const char * pathname);
|
||||||
static void lv_freetype_drop_face_id(lv_freetype_context_t * ctx, FTC_FaceID face_id);
|
static void lv_freetype_drop_face_id(lv_freetype_context_t * ctx, FTC_FaceID face_id);
|
||||||
@@ -66,7 +62,7 @@ static lv_cache_compare_res_t cache_node_cache_compare_cb(const lv_freetype_cach
|
|||||||
* GLOBAL FUNCTIONS
|
* GLOBAL FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
lv_result_t lv_freetype_init(uint32_t max_faces, uint32_t max_sizes, uint32_t max_kilobytes)
|
lv_result_t lv_freetype_init(void)
|
||||||
{
|
{
|
||||||
if(ft_ctx) {
|
if(ft_ctx) {
|
||||||
LV_LOG_WARN("freetype already initialized");
|
LV_LOG_WARN("freetype already initialized");
|
||||||
@@ -89,26 +85,6 @@ lv_result_t lv_freetype_init(uint32_t max_faces, uint32_t max_sizes, uint32_t ma
|
|||||||
return LV_RESULT_INVALID;
|
return LV_RESULT_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = FTC_Manager_New(ctx->library,
|
|
||||||
max_faces,
|
|
||||||
max_sizes,
|
|
||||||
max_kilobytes * 1024,
|
|
||||||
lv_freetype_face_requester,
|
|
||||||
NULL,
|
|
||||||
&ctx->cache_manager);
|
|
||||||
if(error) {
|
|
||||||
FT_ERROR_MSG("FTC_Manager_New", error);
|
|
||||||
lv_freetype_cleanup(ctx);
|
|
||||||
return LV_RESULT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = FTC_CMapCache_New(ctx->cache_manager, &ctx->cmap_cache);
|
|
||||||
if(error) {
|
|
||||||
FT_ERROR_MSG("FTC_CMapCache_New", error);
|
|
||||||
lv_freetype_cleanup(ctx);
|
|
||||||
return LV_RESULT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
_lv_ll_init(&ctx->face_id_ll, sizeof(face_id_node_t));
|
_lv_ll_init(&ctx->face_id_ll, sizeof(face_id_node_t));
|
||||||
|
|
||||||
lv_cache_ops_t ops = {
|
lv_cache_ops_t ops = {
|
||||||
@@ -221,27 +197,6 @@ lv_freetype_context_t * lv_freetype_get_context(void)
|
|||||||
return LV_GLOBAL_DEFAULT()->ft_context;
|
return LV_GLOBAL_DEFAULT()->ft_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_Size lv_freetype_lookup_size(const lv_freetype_font_dsc_t * dsc)
|
|
||||||
{
|
|
||||||
FT_Error error;
|
|
||||||
lv_freetype_context_t * ctx = dsc->context;
|
|
||||||
|
|
||||||
FT_Size ft_size;
|
|
||||||
struct FTC_ScalerRec_ scaler;
|
|
||||||
scaler.face_id = dsc->face_id;
|
|
||||||
scaler.width = dsc->size;
|
|
||||||
scaler.height = dsc->size;
|
|
||||||
scaler.pixel = 1;
|
|
||||||
error = FTC_Manager_LookupSize(ctx->cache_manager, &scaler, &ft_size);
|
|
||||||
|
|
||||||
if(error) {
|
|
||||||
FT_ERROR_MSG("FTC_Manager_LookupSize", error);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ft_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void lv_freetype_italic_transform(FT_Face face)
|
void lv_freetype_italic_transform(FT_Face face)
|
||||||
{
|
{
|
||||||
LV_ASSERT_NULL(face);
|
LV_ASSERT_NULL(face);
|
||||||
@@ -310,24 +265,6 @@ static void freetype_on_font_set_cbs(lv_freetype_font_dsc_t * dsc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FT_Error lv_freetype_face_requester(FTC_FaceID face_id,
|
|
||||||
FT_Library library,
|
|
||||||
FT_Pointer req_data,
|
|
||||||
FT_Face * aface)
|
|
||||||
{
|
|
||||||
LV_UNUSED(library);
|
|
||||||
LV_UNUSED(req_data);
|
|
||||||
|
|
||||||
const char * pathname = lv_freetype_get_pathname(face_id);
|
|
||||||
|
|
||||||
FT_Error error = FT_New_Face(library, pathname, 0, aface);
|
|
||||||
if(error) {
|
|
||||||
FT_ERROR_MSG("FT_New_Face", error);
|
|
||||||
LV_LOG_ERROR("error pathname = %s", pathname);
|
|
||||||
}
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void lv_freetype_cleanup(lv_freetype_context_t * ctx)
|
static void lv_freetype_cleanup(lv_freetype_context_t * ctx)
|
||||||
{
|
{
|
||||||
LV_ASSERT_NULL(ctx);
|
LV_ASSERT_NULL(ctx);
|
||||||
@@ -336,11 +273,6 @@ static void lv_freetype_cleanup(lv_freetype_context_t * ctx)
|
|||||||
ctx->cache_node_cache = NULL;
|
ctx->cache_node_cache = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx->cache_manager) {
|
|
||||||
FTC_Manager_Done(ctx->cache_manager);
|
|
||||||
ctx->cache_manager = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx->library) {
|
if(ctx->library) {
|
||||||
FT_Done_FreeType(ctx->library);
|
FT_Done_FreeType(ctx->library);
|
||||||
ctx->library = NULL;
|
ctx->library = NULL;
|
||||||
@@ -401,7 +333,6 @@ static void lv_freetype_drop_face_id(lv_freetype_context_t * ctx, FTC_FaceID fac
|
|||||||
if(node->ref_cnt == 0) {
|
if(node->ref_cnt == 0) {
|
||||||
LV_LOG_INFO("drop face_id: %s", node->pathname);
|
LV_LOG_INFO("drop face_id: %s", node->pathname);
|
||||||
_lv_ll_remove(ll_p, node);
|
_lv_ll_remove(ll_p, node);
|
||||||
FTC_Manager_RemoveFaceID(ctx->cache_manager, face_id);
|
|
||||||
lv_free(node->pathname);
|
lv_free(node->pathname);
|
||||||
lv_free(node);
|
lv_free(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,13 +76,9 @@ typedef struct {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the freetype library.
|
* Initialize the freetype library.
|
||||||
* @param max_faces Maximum number of opened FT_Face objects managed by this cache instance. Use 0 for defaults.
|
|
||||||
* @param max_sizes Maximum number of opened FT_Size objects managed by this cache instance. Use 0 for defaults.
|
|
||||||
* @param max_kilobytes Maximum number of kilobytes to use for cached data nodes. Use 0 for defaults.
|
|
||||||
* Note that this value does not account for managed FT_Face and FT_Size objects.
|
|
||||||
* @return LV_RESULT_OK on success, otherwise LV_RESULT_INVALID.
|
* @return LV_RESULT_OK on success, otherwise LV_RESULT_INVALID.
|
||||||
*/
|
*/
|
||||||
lv_result_t lv_freetype_init(uint32_t max_faces, uint32_t max_sizes, uint32_t max_kilobytes);
|
lv_result_t lv_freetype_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uninitialize the freetype library
|
* Uninitialize the freetype library
|
||||||
|
|||||||
@@ -130,8 +130,7 @@ static bool freetype_glyph_create_cb(lv_freetype_glyph_cache_data_t * data, void
|
|||||||
lv_font_glyph_dsc_t * dsc_out = &data->glyph_dsc;
|
lv_font_glyph_dsc_t * dsc_out = &data->glyph_dsc;
|
||||||
|
|
||||||
FT_Face face = dsc->cache_node->face;
|
FT_Face face = dsc->cache_node->face;
|
||||||
FT_UInt charmap_index = FT_Get_Charmap_Index(face->charmap);
|
FT_UInt glyph_index = FT_Get_Char_Index(face, data->unicode);
|
||||||
FT_UInt glyph_index = FTC_CMapCache_Lookup(dsc->context->cmap_cache, dsc->face_id, charmap_index, data->unicode);
|
|
||||||
|
|
||||||
FT_Set_Pixel_Sizes(face, 0, dsc->size);
|
FT_Set_Pixel_Sizes(face, 0, dsc->size);
|
||||||
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_COMPUTE_METRICS | FT_LOAD_NO_BITMAP);
|
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_COMPUTE_METRICS | FT_LOAD_NO_BITMAP);
|
||||||
|
|||||||
@@ -87,8 +87,7 @@ static const void * freetype_get_glyph_bitmap_cb(lv_font_glyph_dsc_t * g_dsc,
|
|||||||
LV_ASSERT_FREETYPE_FONT_DSC(dsc);
|
LV_ASSERT_FREETYPE_FONT_DSC(dsc);
|
||||||
|
|
||||||
FT_Face face = dsc->cache_node->face;
|
FT_Face face = dsc->cache_node->face;
|
||||||
FT_UInt charmap_index = FT_Get_Charmap_Index(face->charmap);
|
FT_UInt glyph_index = FT_Get_Char_Index(face, unicode_letter);
|
||||||
FT_UInt glyph_index = FTC_CMapCache_Lookup(dsc->context->cmap_cache, dsc->face_id, charmap_index, unicode_letter);
|
|
||||||
|
|
||||||
lv_cache_t * cache = dsc->cache_node->draw_data_cache;
|
lv_cache_t * cache = dsc->cache_node->draw_data_cache;
|
||||||
|
|
||||||
|
|||||||
@@ -187,8 +187,8 @@ static lv_cache_entry_t * lv_freetype_outline_lookup(lv_freetype_font_dsc_t * ds
|
|||||||
{
|
{
|
||||||
lv_freetype_cache_node_t * cache_node = dsc->cache_node;
|
lv_freetype_cache_node_t * cache_node = dsc->cache_node;
|
||||||
|
|
||||||
FT_UInt charmap_index = FT_Get_Charmap_Index(cache_node->face->charmap);
|
FT_Face face = cache_node->face;
|
||||||
FT_UInt glyph_index = FTC_CMapCache_Lookup(dsc->context->cmap_cache, dsc->face_id, charmap_index, unicode_letter);
|
FT_UInt glyph_index = FT_Get_Char_Index(face, unicode_letter);
|
||||||
|
|
||||||
lv_freetype_outline_node_t tmp_node;
|
lv_freetype_outline_node_t tmp_node;
|
||||||
tmp_node.glyph_index = glyph_index;
|
tmp_node.glyph_index = glyph_index;
|
||||||
|
|||||||
@@ -80,8 +80,6 @@ struct _lv_freetype_cache_node_t {
|
|||||||
|
|
||||||
typedef struct _lv_freetype_context_t {
|
typedef struct _lv_freetype_context_t {
|
||||||
FT_Library library;
|
FT_Library library;
|
||||||
FTC_Manager cache_manager;
|
|
||||||
FTC_CMapCache cmap_cache;
|
|
||||||
lv_ll_t face_id_ll;
|
lv_ll_t face_id_ll;
|
||||||
lv_event_cb_t event_cb;
|
lv_event_cb_t event_cb;
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ void lv_init(void)
|
|||||||
#if LV_USE_FREETYPE
|
#if LV_USE_FREETYPE
|
||||||
/*Init freetype library*/
|
/*Init freetype library*/
|
||||||
# if LV_FREETYPE_CACHE_SIZE >= 0
|
# if LV_FREETYPE_CACHE_SIZE >= 0
|
||||||
lv_freetype_init(LV_FREETYPE_CACHE_FT_FACES, LV_FREETYPE_CACHE_FT_SIZES, LV_FREETYPE_CACHE_SIZE);
|
lv_freetype_init();
|
||||||
# else
|
# else
|
||||||
lv_freetype_init(0, 0, 0);
|
lv_freetype_init(0, 0, 0);
|
||||||
# endif
|
# endif
|
||||||
|
|||||||
Reference in New Issue
Block a user