Add font family to .3mf
This commit is contained in:
parent
43230b2709
commit
2bf876e96c
@ -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<TextConfiguration> 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);
|
||||
|
@ -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<std::string> family;
|
||||
std::optional<std::string> face_name;
|
||||
std::optional<std::string> style;
|
||||
std::optional<std::string> weight;
|
||||
|
@ -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<wxFontFamily, std::string> from_family;
|
||||
static const std::map<std::string, wxFontFamily> to_family;
|
||||
|
||||
static const std::map<wxFontStyle, std::string> from_style;
|
||||
static const std::map<std::string, wxFontStyle> 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<wxFont> WxFontUtils::load_wxFont(const std::string &font_descripto
|
||||
return wx_font;
|
||||
}
|
||||
|
||||
const std::map<wxFontFamily, std::string> 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<std::string, wxFontFamily> WxFontUtils::to_family =
|
||||
MapUtils::create_oposit(WxFontUtils::from_family);
|
||||
|
||||
const std::map<wxFontStyle, std::string> WxFontUtils::from_style(
|
||||
{{wxFONTSTYLE_ITALIC, "italic"},
|
||||
{wxFONTSTYLE_SLANT, "slant"},
|
||||
@ -1376,6 +1393,10 @@ std::optional<wxFont> WxFontUtils::create_wxFont(const FontItem &fi,
|
||||
{
|
||||
double point_size = static_cast<double>(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user