Cache Font config configuration into static variable

This commit is contained in:
Filip Sykala - NTB T15p 2022-10-26 10:12:23 +02:00
parent 1a285dd5f1
commit 59fc9328f4
2 changed files with 13 additions and 5 deletions

View file

@ -14,21 +14,26 @@ using namespace Slic3r::GUI;
// Will be finalized on application exit
// It seams that it NOT work
static std::optional<Slic3r::ScopeGuard> 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();

View file

@ -15,7 +15,10 @@ namespace Slic3r::GUI {
/// inspired by wxpdfdoc -
/// https://github.com/utelle/wxpdfdoc/blob/5bdcdb9953327d06dc50ec312685ccd9bc8400e0/src/pdffontmanager.cpp
/// </summary>
std::string get_font_path(const wxFont &font);
/// <param name="font">Wx descriptor of font</param>
/// <param name="reload_fonts">flag to reinitialize font list</param>
/// <returns>Font FilePath by FontConfig</returns>
std::string get_font_path(const wxFont &font, bool reload_fonts = false);
} // namespace Slic3r
#endif // EXIST_FONT_CONFIG_INCLUDE