diff --git a/src/slic3r/Utils/FontConfigHelp.cpp b/src/slic3r/Utils/FontConfigHelp.cpp index 09c54521f1..15beca07ba 100644 --- a/src/slic3r/Utils/FontConfigHelp.cpp +++ b/src/slic3r/Utils/FontConfigHelp.cpp @@ -14,21 +14,26 @@ using namespace Slic3r::GUI; // Will be finalized on application exit // It seams that it NOT work static std::optional finalize_guard; +// cache for Loading of the default configuration file and building information about the available fonts. +static FcConfig *fc = nullptr; -std::string Slic3r::GUI::get_font_path(const wxFont &font) +std::string Slic3r::GUI::get_font_path(const wxFont &font, bool reload_fonts) { if (!finalize_guard.has_value()) { FcInit(); + fc = FcInitLoadConfigAndFonts(); finalize_guard.emplace([]() { // Some internal problem of Font config or other library use FC too(like wxWidget) // fccache.c:795: FcCacheFini: Assertion `fcCacheChains[i] == NULL' failed. //FcFini(); + FcConfigDestroy(fc); }); - } + } else if (reload_fonts) { + FcConfigDestroy(fc); + fc = FcInitLoadConfigAndFonts(); + } - FcConfig *fc = FcInitLoadConfigAndFonts(); if (fc == nullptr) return ""; - ScopeGuard sg_fc([fc]() { FcConfigDestroy(fc); }); wxString fontDesc = font.GetNativeFontInfoUserDesc(); wxString faceName = font.GetFaceName(); diff --git a/src/slic3r/Utils/FontConfigHelp.hpp b/src/slic3r/Utils/FontConfigHelp.hpp index 10f7d1c1fa..d2d7738767 100644 --- a/src/slic3r/Utils/FontConfigHelp.hpp +++ b/src/slic3r/Utils/FontConfigHelp.hpp @@ -15,7 +15,10 @@ namespace Slic3r::GUI { /// inspired by wxpdfdoc - /// https://github.com/utelle/wxpdfdoc/blob/5bdcdb9953327d06dc50ec312685ccd9bc8400e0/src/pdffontmanager.cpp /// -std::string get_font_path(const wxFont &font); +/// Wx descriptor of font +/// flag to reinitialize font list +/// Font FilePath by FontConfig +std::string get_font_path(const wxFont &font, bool reload_fonts = false); } // namespace Slic3r #endif // EXIST_FONT_CONFIG_INCLUDE