diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 5a39d8033d..d794118b41 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -2621,23 +2621,25 @@ EmbossDataBase GLGizmoEmboss::create_emboss_data_base() { bool GLGizmoEmboss::load_configuration(ModelVolume *volume) { if (volume == nullptr) return false; - if (!volume->text_configuration.has_value()) return false; + const std::optional tc_opt = volume->text_configuration; + if (!tc_opt.has_value()) return false; + const TextConfiguration &tc = *tc_opt; + const EmbossStyle &style = tc.style; - TextConfiguration &tc = *volume->text_configuration; - EmbossStyle &tc_es = tc.style; - - auto has_same_name = [&tc_es](const EmbossStyleManager::Item &style) -> bool { - const EmbossStyle &es = style.style; - return es.name == tc_es.name; + auto has_same_name = [&style](const EmbossStyleManager::Item &style_item) -> bool { + const EmbossStyle &es = style_item.style; + return es.name == style.name; }; std::optional wx_font_opt; - if (tc_es.type == WxFontUtils::get_actual_type()) - wx_font_opt = WxFontUtils::load_wxFont(tc_es.path); + if (style.type == WxFontUtils::get_actual_type()) + wx_font_opt = WxFontUtils::load_wxFont(style.path); + bool is_path_changed = false; if (!wx_font_opt.has_value()) { create_notification_not_valid_font(tc); // Try create similar wx font - wx_font_opt = WxFontUtils::create_wxFont(tc_es); + wx_font_opt = WxFontUtils::create_wxFont(style); + is_path_changed = wx_font_opt.has_value(); } const auto& styles = m_style_manager.get_styles(); @@ -2645,22 +2647,25 @@ bool GLGizmoEmboss::load_configuration(ModelVolume *volume) if (it == styles.end()) { // style was not found if (wx_font_opt.has_value()) - m_style_manager.load_style(tc_es, *wx_font_opt); + m_style_manager.load_style(style, *wx_font_opt); } else { size_t style_index = it - styles.begin(); if (!m_style_manager.load_style(style_index)) { // can`t load stored style m_style_manager.erase(style_index); if (wx_font_opt.has_value()) - m_style_manager.load_style(tc_es, *wx_font_opt); + m_style_manager.load_style(style, *wx_font_opt); } else { // stored style is loaded, now set modification of style - m_style_manager.get_style() = tc_es; + m_style_manager.get_style() = style; m_style_manager.set_wx_font(*wx_font_opt); } } + if (is_path_changed) + m_style_manager.get_style().path = WxFontUtils::store_wxFont(*wx_font_opt); + m_text = tc.text; m_volume = volume; return true; diff --git a/src/slic3r/Utils/WxFontUtils.cpp b/src/slic3r/Utils/WxFontUtils.cpp index 4577bbcd6f..b2fba00e0d 100644 --- a/src/slic3r/Utils/WxFontUtils.cpp +++ b/src/slic3r/Utils/WxFontUtils.cpp @@ -194,10 +194,10 @@ const TypeToWeight WxFontUtils::type_to_weight = (wxFONTWEIGHT_HEAVY, "heavy") (wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy"); -std::optional WxFontUtils::create_wxFont(const EmbossStyle &fi) +std::optional WxFontUtils::create_wxFont(const EmbossStyle &style) { - const FontProp &fp = fi.prop; - double point_size = static_cast(fp.size_in_mm); + const FontProp &fp = style.prop; + double point_size = static_cast(fp.size_in_mm); wxFontInfo info(point_size); if (fp.family.has_value()) { auto it = type_to_family.right.find(*fp.style); diff --git a/src/slic3r/Utils/WxFontUtils.hpp b/src/slic3r/Utils/WxFontUtils.hpp index 05404ddd77..13f6812b5a 100644 --- a/src/slic3r/Utils/WxFontUtils.hpp +++ b/src/slic3r/Utils/WxFontUtils.hpp @@ -36,7 +36,7 @@ public: static std::optional load_wxFont(const std::string &font_descriptor); // Try to create similar font, loaded from 3mf from different Computer - static std::optional create_wxFont(const EmbossStyle &fi); + static std::optional create_wxFont(const EmbossStyle &style); // update font property by wxFont static void update_property(FontProp &font_prop, const wxFont &font);