mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 14:36:02 +08:00
Cache Font config configuration into static variable
This commit is contained in:
parent
1a285dd5f1
commit
59fc9328f4
@ -14,21 +14,26 @@ using namespace Slic3r::GUI;
|
|||||||
// Will be finalized on application exit
|
// Will be finalized on application exit
|
||||||
// It seams that it NOT work
|
// It seams that it NOT work
|
||||||
static std::optional<Slic3r::ScopeGuard> finalize_guard;
|
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()) {
|
if (!finalize_guard.has_value()) {
|
||||||
FcInit();
|
FcInit();
|
||||||
|
fc = FcInitLoadConfigAndFonts();
|
||||||
finalize_guard.emplace([]() {
|
finalize_guard.emplace([]() {
|
||||||
// Some internal problem of Font config or other library use FC too(like wxWidget)
|
// Some internal problem of Font config or other library use FC too(like wxWidget)
|
||||||
// fccache.c:795: FcCacheFini: Assertion `fcCacheChains[i] == NULL' failed.
|
// fccache.c:795: FcCacheFini: Assertion `fcCacheChains[i] == NULL' failed.
|
||||||
//FcFini();
|
//FcFini();
|
||||||
|
FcConfigDestroy(fc);
|
||||||
});
|
});
|
||||||
}
|
} else if (reload_fonts) {
|
||||||
|
FcConfigDestroy(fc);
|
||||||
|
fc = FcInitLoadConfigAndFonts();
|
||||||
|
}
|
||||||
|
|
||||||
FcConfig *fc = FcInitLoadConfigAndFonts();
|
|
||||||
if (fc == nullptr) return "";
|
if (fc == nullptr) return "";
|
||||||
ScopeGuard sg_fc([fc]() { FcConfigDestroy(fc); });
|
|
||||||
|
|
||||||
wxString fontDesc = font.GetNativeFontInfoUserDesc();
|
wxString fontDesc = font.GetNativeFontInfoUserDesc();
|
||||||
wxString faceName = font.GetFaceName();
|
wxString faceName = font.GetFaceName();
|
||||||
|
@ -15,7 +15,10 @@ namespace Slic3r::GUI {
|
|||||||
/// inspired by wxpdfdoc -
|
/// inspired by wxpdfdoc -
|
||||||
/// https://github.com/utelle/wxpdfdoc/blob/5bdcdb9953327d06dc50ec312685ccd9bc8400e0/src/pdffontmanager.cpp
|
/// https://github.com/utelle/wxpdfdoc/blob/5bdcdb9953327d06dc50ec312685ccd9bc8400e0/src/pdffontmanager.cpp
|
||||||
/// </summary>
|
/// </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
|
} // namespace Slic3r
|
||||||
#endif // EXIST_FONT_CONFIG_INCLUDE
|
#endif // EXIST_FONT_CONFIG_INCLUDE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user