mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 23:15:54 +08:00
Move static variable for finalize font config to be global scope
This commit is contained in:
parent
6610bf2eb1
commit
0bf90ae0af
@ -8,14 +8,18 @@
|
||||
|
||||
using namespace Slic3r::GUI;
|
||||
|
||||
FontConfigHelp::FontConfigHelp() { FcInit(); }
|
||||
FontConfigHelp::~FontConfigHelp() {
|
||||
// fccache.c:795: FcCacheFini: Assertion `fcCacheChains[i] == NULL' failed.
|
||||
// FcFini();
|
||||
}
|
||||
// @Vojta suggest to make static variable global
|
||||
// Guard for finalize Font Config
|
||||
// Will be finalized on application exit
|
||||
static std::optional<Slic3r::ScopeGuard> finalize_guard;
|
||||
|
||||
std::string FontConfigHelp::get_font_path(const wxFont &font)
|
||||
std::string Slic3r::GUI::get_font_path(const wxFont &font)
|
||||
{
|
||||
if (!finalize_guard.has_value()) {
|
||||
FcInit();
|
||||
finalize_guard.emplace([]() { FcFini(); });
|
||||
}
|
||||
|
||||
FcConfig *fc = FcInitLoadConfigAndFonts();
|
||||
if (fc == nullptr) return "";
|
||||
ScopeGuard sg_fc([fc]() { FcConfigDestroy(fc); });
|
||||
|
@ -10,30 +10,12 @@
|
||||
namespace Slic3r::GUI {
|
||||
|
||||
/// <summary>
|
||||
/// helper object for RAII access to font config
|
||||
/// initialize & finalize FontConfig
|
||||
/// initialize font config
|
||||
/// Convert wx widget font to file path
|
||||
/// inspired by wxpdfdoc -
|
||||
/// https://github.com/utelle/wxpdfdoc/blob/5bdcdb9953327d06dc50ec312685ccd9bc8400e0/src/pdffontmanager.cpp
|
||||
/// </summary>
|
||||
class FontConfigHelp
|
||||
{
|
||||
public:
|
||||
/// <summary>
|
||||
/// initialize font config
|
||||
/// </summary>
|
||||
FontConfigHelp();
|
||||
|
||||
/// <summary>
|
||||
/// free font config resources
|
||||
/// </summary>
|
||||
~FontConfigHelp();
|
||||
|
||||
/// <summary>
|
||||
/// initialize font config
|
||||
/// Convert wx widget font to file path
|
||||
/// inspired by wxpdfdoc -
|
||||
/// https://github.com/utelle/wxpdfdoc/blob/5bdcdb9953327d06dc50ec312685ccd9bc8400e0/src/pdffontmanager.cpp
|
||||
/// </summary>
|
||||
std::string get_font_path(const wxFont &font);
|
||||
};
|
||||
std::string get_font_path(const wxFont &font);
|
||||
|
||||
} // namespace Slic3r
|
||||
#endif // EXIST_FONT_CONFIG_INCLUDE
|
||||
|
@ -59,9 +59,7 @@ bool WxFontUtils::can_load(const wxFont &font)
|
||||
return false;
|
||||
return is_valid_ttf(file_path);
|
||||
#elif defined(__linux__)
|
||||
// TODO: find better way
|
||||
static FontConfigHelp help;
|
||||
std::string font_path = help.get_font_path(font);
|
||||
std::string font_path = Slic3r::GUI::get_font_path(font);
|
||||
return !font_path.empty();
|
||||
#endif
|
||||
return false;
|
||||
@ -88,8 +86,7 @@ std::unique_ptr<Emboss::FontFile> WxFontUtils::create_font_file(const wxFont &fo
|
||||
file_path = file_path.substr(start, file_path.size() - start);
|
||||
return Emboss::create_font_file(file_path.c_str());
|
||||
#elif defined(__linux__)
|
||||
static FontConfigHelp help;
|
||||
std::string font_path = help.get_font_path(font);
|
||||
std::string font_path = Slic3r::GUI::get_font_path(font);
|
||||
if (font_path.empty()) return nullptr;
|
||||
return Emboss::create_font_file(font_path.c_str());
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user