Fix T75028: Improved Font Names in File Manager
When viewing font files in the File Manager, this patch uses the font's family and style names to show the same type of string shown to users in operating system lists. For example "Book Antiqua Regular" instead of "BKANT.ttf" see D12020 for details and examples. Differential Revision: https://developer.blender.org/D12020 Reviewed by Campbell Barton and Julian Eisel
This commit is contained in:
parent
073bf8bf52
commit
8aa1c0a326
Notes:
blender-bot
2023-02-13 23:05:54 +01:00
Referenced by issue #90263, Nodes connected to Subsurface Radius input not working properly on Eevee Referenced by issue #75028, Font Names missing in Windows 10
|
@ -53,6 +53,8 @@ int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size
|
|||
void BLF_unload(const char *name) ATTR_NONNULL();
|
||||
void BLF_unload_id(int fontid);
|
||||
|
||||
char *BLF_display_name_from_file(const char *filename);
|
||||
|
||||
/* Check if font supports a particular glyph. */
|
||||
bool BLF_has_glyph(int fontid, unsigned int unicode);
|
||||
|
||||
|
|
|
@ -915,6 +915,17 @@ void BLF_draw_buffer(int fontid, const char *str, size_t len)
|
|||
BLF_draw_buffer_ex(fontid, str, len, NULL);
|
||||
}
|
||||
|
||||
char *BLF_display_name_from_file(const char *filename)
|
||||
{
|
||||
FontBLF *font = blf_font_new("font_name", filename);
|
||||
if (!font) {
|
||||
return NULL;
|
||||
}
|
||||
char *name = blf_display_name(font);
|
||||
blf_font_free(font);
|
||||
return name;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
void BLF_state_print(int fontid)
|
||||
{
|
||||
|
|
|
@ -1465,3 +1465,11 @@ float blf_font_ascender(FontBLF *font)
|
|||
blf_glyph_cache_release(font);
|
||||
return ascender;
|
||||
}
|
||||
|
||||
char *blf_display_name(FontBLF *font)
|
||||
{
|
||||
if (!font->face->family_name) {
|
||||
return NULL;
|
||||
}
|
||||
return BLI_sprintfN("%s %s", font->face->family_name, font->face->style_name);
|
||||
}
|
||||
|
|
|
@ -99,6 +99,8 @@ int blf_font_width_max(struct FontBLF *font);
|
|||
float blf_font_descender(struct FontBLF *font);
|
||||
float blf_font_ascender(struct FontBLF *font);
|
||||
|
||||
char *blf_display_name(struct FontBLF *font);
|
||||
|
||||
void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#endif
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLF_api.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_fileops_types.h"
|
||||
|
@ -1812,13 +1814,23 @@ BlendHandle *filelist_lib(struct FileList *filelist)
|
|||
return filelist->libfiledata;
|
||||
}
|
||||
|
||||
static const char *fileentry_uiname(const char *root,
|
||||
const char *relpath,
|
||||
const eFileSel_File_Types typeflag,
|
||||
char *buff)
|
||||
static char *fileentry_uiname(const char *root,
|
||||
const char *relpath,
|
||||
const eFileSel_File_Types typeflag,
|
||||
char *buff)
|
||||
{
|
||||
char *name = NULL;
|
||||
|
||||
if (typeflag & FILE_TYPE_FTFONT && !(typeflag & FILE_TYPE_BLENDERLIB)) {
|
||||
char abspath[FILE_MAX_LIBEXTRA];
|
||||
BLI_join_dirfile(abspath, sizeof(abspath), root, relpath);
|
||||
name = BLF_display_name_from_file(abspath);
|
||||
if (name) {
|
||||
/* Allocated string, so no need to BLI_strdup.*/
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeflag & FILE_TYPE_BLENDERLIB) {
|
||||
char abspath[FILE_MAX_LIBEXTRA];
|
||||
char *group;
|
||||
|
@ -1840,7 +1852,7 @@ static const char *fileentry_uiname(const char *root,
|
|||
}
|
||||
BLI_assert(name);
|
||||
|
||||
return name;
|
||||
return BLI_strdup(name);
|
||||
}
|
||||
|
||||
const char *filelist_dir(struct FileList *filelist)
|
||||
|
@ -3203,7 +3215,7 @@ static void filelist_readjob_do(const bool do_lib,
|
|||
MEM_freeN(entry->relpath);
|
||||
entry->relpath = BLI_strdup(dir + 2); /* + 2 to remove '//'
|
||||
* added by BLI_path_rel to rel_subdir. */
|
||||
entry->name = BLI_strdup(fileentry_uiname(root, entry->relpath, entry->typeflag, dir));
|
||||
entry->name = fileentry_uiname(root, entry->relpath, entry->typeflag, dir);
|
||||
entry->free_name = true;
|
||||
|
||||
/* Here we decide whether current filedirentry is to be listed too, or not. */
|
||||
|
|
Loading…
Reference in New Issue