diff --git a/release/datafiles/userdef/userdef_default.c b/release/datafiles/userdef/userdef_default.c index ab47439d6c7..a18bb88c8f6 100644 --- a/release/datafiles/userdef/userdef_default.c +++ b/release/datafiles/userdef/userdef_default.c @@ -32,6 +32,8 @@ const UserDef U_default = { .pref_flag = USER_PREF_FLAG_SAVE, .savetime = 2, .tempdir = "", + /* Overwritten by #BKE_appdir_font_folder_default(..) + * unless the system font's cannot be found. */ .fontdir = "//", .renderdir = "//", .render_cachedir = "", diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index 9685932d299..affb9c0ab82 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -131,7 +131,7 @@ const char *BKE_appdir_program_dir(void) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NO /** * Gets a good default directory for fonts. */ -bool BKE_appdir_font_folder_default(char *dir); +bool BKE_appdir_font_folder_default(char *dir, size_t dir_maxncpy); /** * Find Python executable. diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index 7aa23efa346..83b5472b60e 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -227,26 +227,24 @@ bool BKE_appdir_folder_caches(char *path, const size_t path_maxncpy) return true; } -bool BKE_appdir_font_folder_default(char *dir) +bool BKE_appdir_font_folder_default(char *dir, size_t dir_maxncpy) { char test_dir[FILE_MAXDIR]; test_dir[0] = '\0'; #ifdef WIN32 - wchar_t wpath[FILE_MAXDIR]; + wchar_t wpath[MAX_PATH]; if (SHGetSpecialFolderPathW(0, wpath, CSIDL_FONTS, 0)) { - wcscat(wpath, L"\\"); BLI_strncpy_wchar_as_utf8(test_dir, wpath, sizeof(test_dir)); } #elif defined(__APPLE__) - STRNCPY(test_dir, BLI_expand_tilde("~/Library/Fonts/")); - BLI_path_slash_ensure(test_dir, sizeof(test_dir)); + STRNCPY(test_dir, BLI_expand_tilde("~/Library/Fonts")); #else STRNCPY(test_dir, "/usr/share/fonts"); #endif if (test_dir[0] && BLI_exists(test_dir)) { - BLI_strncpy(dir, test_dir, FILE_MAXDIR); + BLI_strncpy(dir, test_dir, dir_maxncpy); return true; } return false; diff --git a/source/blender/blenkernel/intern/blendfile.cc b/source/blender/blenkernel/intern/blendfile.cc index ccb8fa5b0ce..4597c0f681d 100644 --- a/source/blender/blenkernel/intern/blendfile.cc +++ b/source/blender/blenkernel/intern/blendfile.cc @@ -1214,8 +1214,13 @@ UserDef *BKE_blendfile_userdef_from_defaults(void) userdef->flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE; #endif - /* System-specific fonts directory. */ - BKE_appdir_font_folder_default(userdef->fontdir); + /* System-specific fonts directory. + * NOTE: when not found, leaves as-is (`//` for the blend-file directory). */ + if (BKE_appdir_font_folder_default(userdef->fontdir, sizeof(userdef->fontdir))) { + /* Not actually needed, just a convention that directory selection + * adds a trailing slash. */ + BLI_path_slash_ensure(userdef->fontdir, sizeof(userdef->fontdir)); + } userdef->memcachelimit = min_ii(BLI_system_memory_max_in_megabytes_int() / 2, userdef->memcachelimit);