diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 731d2cdb13..de58209e43 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -776,21 +776,44 @@ void GLGizmoEmboss::draw_text_input() if (exist_font) ImGui::PopFont(); // show warning about incorrectness view of font - // TODO: add char gap and line gap std::string warning; + std::string tool_tip; const FontProp& prop = m_font_manager.get_font_prop(); if (!exist_font) { warning = _u8L("Can't write text by selected font."); + tool_tip = _u8L("Try to choose another font."); } else { std::string who; - if (prop.skew.has_value()) who = _u8L("Italic"); + auto append_warning = [&who, &tool_tip](std::string& w, std::string& t) { + if (!w.empty()) { + if (!who.empty()) who += " & "; + who += w; + } + if (!t.empty()) { + if (!tool_tip.empty()) tool_tip += "\n"; + tool_tip += t; + } + }; + if (prop.skew.has_value()) { + append_warning(_u8L("Skew"), + _u8L("Unsupported visualization of font skew for text input.")); + } if (prop.boldness.has_value()) { - if (!who.empty()) who += " & "; - who += _u8L("Boldness"); + append_warning(_u8L("Boldness"), + _u8L("Unsupported visualization of font boldness for text input.")); } if (prop.line_gap.has_value()) { - if (!who.empty()) who += " & "; - who += _u8L("Line gap"); + append_warning(_u8L("Line gap"), + _u8L("Unsupported visualization of gap between lines inside text input.")); + } + float imgui_size = FontManager::get_imgui_font_size(prop, *m_font_manager.get_font_file()); + if (imgui_size > FontManager::max_imgui_font_size) { + append_warning(_u8L("Tall"), + _u8L("Diminished font height inside text input.")); + } + if (imgui_size < FontManager::min_imgui_font_size) { + append_warning(_u8L("Tiny"), + _u8L("Enlarged font height inside text input.")); } if (!who.empty()) { warning = GUI::format(_u8L("%1% is NOT shown."), who); @@ -805,6 +828,8 @@ void GLGizmoEmboss::draw_text_input() ImGui::SetCursorPos(ImVec2(width - size.x + padding.x, cursor.y - size.y - padding.y)); m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, warning); + if (ImGui::IsItemHovered() && !tool_tip.empty()) + ImGui::SetTooltip("%s", tool_tip.c_str()); ImGui::SetCursorPos(cursor); } @@ -1616,7 +1641,7 @@ void GLGizmoEmboss::draw_advanced() auto def_distance = m_stored_font_item.has_value() ? &m_stored_font_item->prop.distance : nullptr; if (rev_slider(tr.surface_distance, distance, def_distance, _u8L("Undo translation"), - min_distance, max_distance, "%.2f mm", _L("Distance from model surface")) && + min_distance, max_distance, "%.2f mm", _L("Distance center of text from model surface")) && m_volume != nullptr && m_volume->text_configuration.has_value()){ m_volume->text_configuration->font_item.prop.distance = font_prop.distance; float act_distance = font_prop.distance.has_value() ? *font_prop.distance : .0f; diff --git a/src/slic3r/Utils/FontManager.cpp b/src/slic3r/Utils/FontManager.cpp index dc417b90ac..b056b62c92 100644 --- a/src/slic3r/Utils/FontManager.cpp +++ b/src/slic3r/Utils/FontManager.cpp @@ -541,6 +541,19 @@ void FontManager::free_imgui_fonts() m_imgui_font_atlas.Clear(); } +float FontManager::min_imgui_font_size = 18.f; +float FontManager::max_imgui_font_size = 60.f; +float FontManager::get_imgui_font_size(const FontProp &prop, + const Emboss::FontFile &file) +{ + // coeficient for convert line height to font size + float c1 = (file.ascent - file.descent + file.linegap) / (float) file.unit_per_em; + + // 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. + return c1 * std::abs(prop.size_in_mm) / 0.3528f; +} + ImFont * FontManager::load_imgui_font(size_t index, const std::string &text) { free_imgui_fonts(); // TODO: remove it after correct initialization @@ -563,18 +576,11 @@ ImFont * FontManager::load_imgui_font(size_t index, const std::string &text) ImFontAtlasFlags_NoPowerOfTwoHeight; const FontProp &font_prop = item.font_item.prop; - - // coeficient for convert line height to font size - float c1 = (font_file.ascent - font_file.descent + font_file.linegap) / (float) font_file.unit_per_em; - - // 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 - float font_size = c1 * std::abs(font_prop.size_in_mm) / 0.3528f; - if (font_size < m_cfg.min_imgui_font_size) - font_size = m_cfg.min_imgui_font_size; - if (font_size > m_cfg.max_imgui_font_size) - font_size = m_cfg.max_imgui_font_size; + float font_size = get_imgui_font_size(font_prop, font_file); + if (font_size < min_imgui_font_size) + font_size = min_imgui_font_size; + if (font_size > max_imgui_font_size) + font_size = max_imgui_font_size; ImFontConfig font_config; // TODO: start using merge mode diff --git a/src/slic3r/Utils/FontManager.hpp b/src/slic3r/Utils/FontManager.hpp index cc359bd8e0..a0b75c51f3 100644 --- a/src/slic3r/Utils/FontManager.hpp +++ b/src/slic3r/Utils/FontManager.hpp @@ -154,6 +154,11 @@ public: // check if exist selected font style in manager bool is_activ_font(); + // Limits for imgui loaded font size + // Value out of limits is crop + static float min_imgui_font_size; + static float max_imgui_font_size; + static float get_imgui_font_size(const FontProp& prop, const Emboss::FontFile& file); private: ImFontAtlas m_imgui_font_atlas; @@ -182,14 +187,6 @@ private: bool check_imgui_font_range(ImFont *font, const std::string &text); void free_imgui_fonts(); - struct Configuration - { - // limits for imgui loaded font - // Value out of limits is crop - float min_imgui_font_size = 18.f; - float max_imgui_font_size = 60.f; - } m_cfg; - bool set_up_font_file(size_t item_index); void make_unique_name(std::string &name);