Refactor: BLF API Function Overloading #120029

Closed
Harley Acheson wants to merge 1 commits from Harley/blender:BLFOverloading into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
6 changed files with 21 additions and 23 deletions

View File

@ -50,27 +50,25 @@ void BLF_cache_flush_set_fn(void (*cache_flush_fn)());
* Loads a font, or returns an already loaded font and increments its reference count.
*/
int BLF_load(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT
int BLF_load(const char *name, const unsigned char *mem, int mem_size) ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL(1, 2);
bool BLF_is_loaded(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
bool BLF_is_loaded_mem(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
int BLF_load_unique(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size)
ATTR_NONNULL(1, 2);
int BLF_load_unique(const char *name, const unsigned char *mem, int mem_size) ATTR_NONNULL(1, 2);
void BLF_unload(const char *filepath) ATTR_NONNULL(1);
#if 0 /* Not needed at the moment. */
void BLF_unload_mem(const char *name) ATTR_NONNULL(1);
#endif
void BLF_unload(int fontid);
void BLF_unload_id(int fontid);
void BLF_unload_all();
char *BLF_display_name_from_file(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
char *BLF_display_name_from_id(int fontid);
char *BLF_display_name(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
char *BLF_display_name(int fontid);
/**
* Get the metrics needed for the initial sizing of text objects.

View File

@ -223,17 +223,17 @@ void BLF_metrics_attach(int fontid, uchar *mem, int mem_size)
}
}
int BLF_load_mem(const char *name, const uchar *mem, int mem_size)
int BLF_load(const char *name, const uchar *mem, int mem_size)
{
int i = blf_search_by_mem_name(name);
if (i >= 0) {
// font = global_font[i]; /* UNUSED */
return i;
}
return BLF_load_mem_unique(name, mem, mem_size);
return BLF_load_unique(name, mem, mem_size);
}
int BLF_load_mem_unique(const char *name, const uchar *mem, int mem_size)
int BLF_load_unique(const char *name, const uchar *mem, int mem_size)
{
/*
* Don't search in the cache, make a new object font!
@ -281,7 +281,7 @@ void BLF_unload(const char *filepath)
}
}
void BLF_unload_id(int fontid)
void BLF_unload(int fontid)
{
FontBLF *font = blf_get(fontid);
if (font) {
@ -924,7 +924,7 @@ blender::Vector<blender::StringRef> BLF_string_wrap(int fontid,
return blf_font_string_wrap(font, str, max_pixel_width);
}
char *BLF_display_name_from_file(const char *filepath)
char *BLF_display_name(const char *filepath)
{
/* While listing font directories this function can be called simultaneously from a greater
* number of threads than we want the FreeType cache to keep open at a time. Therefore open
@ -944,7 +944,7 @@ char *BLF_display_name_from_file(const char *filepath)
return name;
}
char *BLF_display_name_from_id(int fontid)
char *BLF_display_name(int fontid)
{
FontBLF *font = blf_get(fontid);
if (!font) {

View File

@ -331,7 +331,7 @@ void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts)
if (clear_fonts) {
LISTBASE_FOREACH (uiFont *, font, &userdef->uifonts) {
BLF_unload_id(font->blf_id);
BLF_unload(font->blf_id);
}
BLF_default_set(-1);
}

View File

@ -33,7 +33,7 @@ extern int builtin_font_size;
VFontData *BKE_vfontdata_from_freetypefont(PackedFile *pf)
{
int fontid = BLF_load_mem("FTVFont", static_cast<const uchar *>(pf->data), pf->size);
int fontid = BLF_load("FTVFont", static_cast<const uchar *>(pf->data), pf->size);
if (fontid == -1) {
return nullptr;
}
@ -42,7 +42,7 @@ VFontData *BKE_vfontdata_from_freetypefont(PackedFile *pf)
VFontData *vfd = static_cast<VFontData *>(MEM_callocN(sizeof(*vfd), "FTVFontData"));
/* Get the font name. */
char *name = BLF_display_name_from_id(fontid);
char *name = BLF_display_name(fontid);
STRNCPY(vfd->name, name);
/* BLF_display_name result must be freed. */
MEM_freeN(name);
@ -53,7 +53,7 @@ VFontData *BKE_vfontdata_from_freetypefont(PackedFile *pf)
vfd->characters = BLI_ghash_int_new_ex(__func__, 255);
BLF_unload_id(fontid);
BLF_unload(fontid);
return vfd;
}
@ -84,11 +84,11 @@ VChar *BKE_vfontdata_char_from_freetypefont(VFont *vfont, ulong character)
int font_id = -1;
if (BKE_vfont_is_builtin(vfont)) {
font_id = BLF_load_mem(
font_id = BLF_load(
vfont->data->name, static_cast<const uchar *>(builtin_font_data), builtin_font_size);
}
else if (vfont->temp_pf) {
font_id = BLF_load_mem(
font_id = BLF_load(
vfont->data->name, static_cast<const uchar *>(vfont->temp_pf->data), vfont->temp_pf->size);
}
@ -105,7 +105,7 @@ VChar *BKE_vfontdata_char_from_freetypefont(VFont *vfont, ulong character)
che->width = BLF_character_to_curves(font_id, character, &che->nurbsbase, vfont->data->scale);
BLI_ghash_insert(vfont->data->characters, POINTER_FROM_UINT(che->index), che);
BLF_unload_id(font_id);
BLF_unload(font_id);
return che;
}

View File

@ -1981,7 +1981,7 @@ static const char *fileentry_uiname(const char *root, FileListInternEntry *entry
if (typeflag & FILE_TYPE_FTFONT && !(typeflag & FILE_TYPE_BLENDERLIB)) {
char abspath[FILE_MAX_LIBEXTRA];
BLI_path_join(abspath, sizeof(abspath), root, relpath);
name = BLF_display_name_from_file(abspath);
name = BLF_display_name(abspath);
if (name) {
/* Allocated string, so no need to #BLI_strdup. */
return name;

View File

@ -2612,7 +2612,7 @@ void SEQ_effect_text_font_unload(TextVars *data, const bool do_id_user)
/* Unload the BLF font. */
if (data->text_blf_id >= 0) {
BLF_unload_id(data->text_blf_id);
BLF_unload(data->text_blf_id);
}
}
@ -2638,7 +2638,7 @@ void SEQ_effect_text_font_load(TextVars *data, const bool do_id_user)
char name[MAX_ID_FULL_NAME];
BKE_id_full_name_get(name, &vfont->id, 0);
data->text_blf_id = BLF_load_mem(name, static_cast<const uchar *>(pf->data), pf->size);
data->text_blf_id = BLF_load(name, static_cast<const uchar *>(pf->data), pf->size);
}
else {
char filepath[FILE_MAX];