From 1e2fe6027d603d7a24fb85c588490f041eeedb7e Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 29 Sep 2022 07:59:31 +0200 Subject: [PATCH] Fix storing of wxFont property which describing font to reconstruct on another computer --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 18 +++++++++++++++--- src/slic3r/Utils/EmbossStyleManager.cpp | 3 ++- src/slic3r/Utils/WxFontUtils.cpp | 19 ++++++++++--------- src/slic3r/Utils/WxFontUtils.hpp | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 5c985fac4..074da2734 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1256,6 +1256,9 @@ bool GLGizmoEmboss::select_facename(const wxString &facename) { const wxFontEncoding &encoding = m_face_names.encoding; wxFont wx_font(wxFontInfo().FaceName(facename).Encoding(encoding)); if (!wx_font.IsOk()) return false; + // wx font could change source file by size of font + int point_size = static_cast(m_style_manager.get_font_prop().size_in_mm); + wx_font.SetPointSize(point_size); if (!m_style_manager.set_wx_font(wx_font)) return false; process(); return true; @@ -2832,9 +2835,18 @@ void GLGizmoEmboss::create_notification_not_valid_font( const std::string &origin_font_name = origin_family.has_value() ? *origin_family : tc.style.path; - const std::string &actual_font_name = actual_family.has_value() ? - *actual_family : - es.name; + + std::string actual_wx_face_name; + if (!actual_family.has_value()) { + auto& wx_font = m_style_manager.get_wx_font(); + if (wx_font.has_value()) { + wxString wx_face_name = wx_font->GetFaceName(); + actual_wx_face_name = std::string((const char *) wx_face_name.ToUTF8()); + } + } + + const std::string &actual_font_name = actual_family.has_value() ? *actual_family : + (!actual_wx_face_name.empty() ? actual_wx_face_name : es.path); std::string text = GUI::format(_L("Can't load exactly same font(\"%1%\"), " diff --git a/src/slic3r/Utils/EmbossStyleManager.cpp b/src/slic3r/Utils/EmbossStyleManager.cpp index 40c4b963d..3799dfa6c 100644 --- a/src/slic3r/Utils/EmbossStyleManager.cpp +++ b/src/slic3r/Utils/EmbossStyleManager.cpp @@ -474,6 +474,7 @@ bool EmbossStyleManager::set_wx_font(const wxFont &wx_font, std::unique_ptr WxFontUtils::create_wxFont(const EmbossStyle &style) void WxFontUtils::update_property(FontProp &font_prop, const wxFont &font) { - // The point size is defined as 1/72 of the Anglo-Saxon inch (25.4 mm): it - // is approximately 0.0139 inch or 352.8 um. But it is too small, so I - // decide use point size as mm for emboss - font_prop.size_in_mm = font.GetPointSize(); // *0.3528f; - font_prop.emboss = font_prop.size_in_mm / 2.f; - - wxString wx_face_name = font.GetFaceName(); + wxString wx_face_name = font.GetFaceName(); std::string face_name((const char *) wx_face_name.ToUTF8()); if (!face_name.empty()) font_prop.face_name = face_name; diff --git a/src/slic3r/Utils/WxFontUtils.hpp b/src/slic3r/Utils/WxFontUtils.hpp index 13f6812b5..d047740b1 100644 --- a/src/slic3r/Utils/WxFontUtils.hpp +++ b/src/slic3r/Utils/WxFontUtils.hpp @@ -37,7 +37,7 @@ public: // Try to create similar font, loaded from 3mf from different Computer static std::optional create_wxFont(const EmbossStyle &style); - // update font property by wxFont + // update font property by wxFont - without emboss depth and font size static void update_property(FontProp &font_prop, const wxFont &font); static bool is_italic(const wxFont &font);