diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 02edb32fb..1066c2cbc 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -157,6 +157,7 @@ static constexpr const char *LINE_GAP_ATTR = "line_gap"; static constexpr const char *LINE_HEIGHT_ATTR = "line_height"; static constexpr const char *DEPTH_ATTR = "depth"; +static constexpr const char *FONT_FAMILY_ATTR = "family"; static constexpr const char *FONT_FACE_NAME_ATTR = "face_name"; static constexpr const char *FONT_STYLE_ATTR = "style"; static constexpr const char *FONT_WEIGHT_ATTR = "weight"; @@ -3264,6 +3265,8 @@ void TextConfigurationSerialization::to_xml(std::stringstream &stream, const Tex stream << LINE_HEIGHT_ATTR << "=\"" << fp.size_in_mm << "\" "; stream << DEPTH_ATTR << "=\"" << fp.emboss << "\" "; // font descriptor + if (fp.family.has_value()) + stream << FONT_FAMILY_ATTR << "=\"" << *fp.family << "\" "; if (fp.face_name.has_value()) stream << FONT_FACE_NAME_ATTR << "=\"" << *fp.face_name << "\" "; if (fp.style.has_value()) @@ -3288,6 +3291,8 @@ std::optional TextConfigurationSerialization::read(const char fp.size_in_mm = get_attribute_value_float(attributes, num_attributes, LINE_HEIGHT_ATTR); fp.emboss = get_attribute_value_float(attributes, num_attributes, DEPTH_ATTR); + std::string family = get_attribute_value_string(attributes, num_attributes, FONT_FAMILY_ATTR); + if (!family.empty()) fp.family = family; std::string face_name = get_attribute_value_string(attributes, num_attributes, FONT_FACE_NAME_ATTR); if (!face_name.empty()) fp.face_name = face_name; std::string style = get_attribute_value_string(attributes, num_attributes, FONT_STYLE_ATTR); diff --git a/src/libslic3r/TextConfiguration.hpp b/src/libslic3r/TextConfiguration.hpp index f018d9df3..3955f32d4 100644 --- a/src/libslic3r/TextConfiguration.hpp +++ b/src/libslic3r/TextConfiguration.hpp @@ -54,7 +54,7 @@ struct FontProp // duplicit to wxFont::PointSize float size_in_mm = 10; // Define type of font - // duplicit to wxFont::FaceName + std::optional family; std::optional face_name; std::optional style; std::optional weight; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 22ba05c91..f041dc474 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -67,7 +67,10 @@ public: // update font property by wxFont static void update_property(FontProp& font_prop, const wxFont& font); - // map to convert wxFont stype to string and vice versa + // map to convert wxFont type to string and vice versa + static const std::map from_family; + static const std::map to_family; + static const std::map from_style; static const std::map to_style; @@ -679,10 +682,11 @@ void GLGizmoEmboss::draw_advanced() { #ifdef ALLOW_DEBUG_MODE std::string descriptor = m_font_list[m_font_selected].path; - ImGui::Text("descriptor = %s", descriptor.c_str()); + ImGui::Text("family = %s", (m_font_prop.family.has_value()?m_font_prop.family->c_str() : " --- ")); + ImGui::Text("face name = %s", (m_font_prop.face_name.has_value()?m_font_prop.face_name->c_str() : " --- ")); ImGui::Text("style = %s", (m_font_prop.style.has_value()?m_font_prop.style->c_str() : " --- ")); ImGui::Text("weight = %s", (m_font_prop.weight.has_value()? m_font_prop.weight->c_str() : " --- ")); - ImGui::Text("face name = %s", (m_font_prop.face_name.has_value()?m_font_prop.face_name->c_str() : " --- ")); + ImGui::Text("descriptor = %s", descriptor.c_str()); ImGui::Image(m_imgui_font_atlas.TexID, ImVec2(m_imgui_font_atlas.TexWidth, m_imgui_font_atlas.TexHeight)); #endif // ALLOW_DEBUG_MODE } @@ -1350,6 +1354,19 @@ std::optional WxFontUtils::load_wxFont(const std::string &font_descripto return wx_font; } +const std::map WxFontUtils::from_family( + {{wxFONTFAMILY_DEFAULT, "default"}, + {wxFONTFAMILY_DECORATIVE, "decorative"}, + {wxFONTFAMILY_ROMAN, "roman"}, + {wxFONTFAMILY_SCRIPT, "script"}, + {wxFONTFAMILY_SWISS, "swiss"}, + {wxFONTFAMILY_MODERN, "modern"}, + {wxFONTFAMILY_TELETYPE, "teletype"}, + {wxFONTFAMILY_MAX, "max"}, + {wxFONTFAMILY_UNKNOWN, "unknown"}}); +const std::map WxFontUtils::to_family = + MapUtils::create_oposit(WxFontUtils::from_family); + const std::map WxFontUtils::from_style( {{wxFONTSTYLE_ITALIC, "italic"}, {wxFONTSTYLE_SLANT, "slant"}, @@ -1376,6 +1393,10 @@ std::optional WxFontUtils::create_wxFont(const FontItem &fi, { double point_size = static_cast(fp.size_in_mm); wxFontInfo info(point_size); + if (fp.family.has_value()) { + auto it = to_family.find(*fp.style); + if (it != to_family.end()) info.Family(it->second); + } if (fp.face_name.has_value()) { wxString face_name(*fp.face_name); info.FaceName(face_name); @@ -1413,18 +1434,22 @@ void WxFontUtils::update_property(FontProp &font_prop, const wxFont &font) { std::string face_name((const char *) wx_face_name.ToUTF8()); if (!face_name.empty()) font_prop.face_name = face_name; + wxFontFamily wx_family = font.GetFamily(); + if (wx_family != wxFONTFAMILY_DEFAULT) { + auto it = from_family.find(wx_family); + if (it != from_family.end()) font_prop.family = it->second; + } + wxFontStyle wx_style = font.GetStyle(); if (wx_style != wxFONTSTYLE_NORMAL) { auto it = from_style.find(wx_style); - if (it != from_style.end()) - font_prop.style = it->second; + if (it != from_style.end()) font_prop.style = it->second; } wxFontWeight wx_weight = font.GetWeight(); if (wx_weight != wxFONTWEIGHT_NORMAL) { auto it = from_weight.find(wx_weight); - if (it != from_weight.end()) - font_prop.weight = it->second; + if (it != from_weight.end()) font_prop.weight = it->second; } }