Add warning on to large and to small font which are not used in emboss text input

This commit is contained in:
Filip Sykala 2022-02-22 09:56:47 +01:00
parent ebbdaf7336
commit 6181b166a4
3 changed files with 55 additions and 27 deletions

View File

@ -776,21 +776,44 @@ void GLGizmoEmboss::draw_text_input()
if (exist_font) ImGui::PopFont(); if (exist_font) ImGui::PopFont();
// show warning about incorrectness view of font // show warning about incorrectness view of font
// TODO: add char gap and line gap
std::string warning; std::string warning;
std::string tool_tip;
const FontProp& prop = m_font_manager.get_font_prop(); const FontProp& prop = m_font_manager.get_font_prop();
if (!exist_font) { if (!exist_font) {
warning = _u8L("Can't write text by selected font."); warning = _u8L("Can't write text by selected font.");
tool_tip = _u8L("Try to choose another font.");
} else { } else {
std::string who; std::string who;
if (prop.skew.has_value()) who = _u8L("Italic"); auto append_warning = [&who, &tool_tip](std::string& w, std::string& t) {
if (prop.boldness.has_value()) { if (!w.empty()) {
if (!who.empty()) who += " & "; if (!who.empty()) who += " & ";
who += _u8L("Boldness"); 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()) {
append_warning(_u8L("Boldness"),
_u8L("Unsupported visualization of font boldness for text input."));
} }
if (prop.line_gap.has_value()) { if (prop.line_gap.has_value()) {
if (!who.empty()) who += " & "; append_warning(_u8L("Line gap"),
who += _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()) { if (!who.empty()) {
warning = GUI::format(_u8L("%1% is NOT shown."), who); 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, ImGui::SetCursorPos(ImVec2(width - size.x + padding.x,
cursor.y - size.y - padding.y)); cursor.y - size.y - padding.y));
m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, warning); 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); ImGui::SetCursorPos(cursor);
} }
@ -1616,7 +1641,7 @@ void GLGizmoEmboss::draw_advanced()
auto def_distance = m_stored_font_item.has_value() ? auto def_distance = m_stored_font_item.has_value() ?
&m_stored_font_item->prop.distance : nullptr; &m_stored_font_item->prop.distance : nullptr;
if (rev_slider(tr.surface_distance, distance, def_distance, _u8L("Undo translation"), 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 != nullptr && m_volume->text_configuration.has_value()){
m_volume->text_configuration->font_item.prop.distance = font_prop.distance; m_volume->text_configuration->font_item.prop.distance = font_prop.distance;
float act_distance = font_prop.distance.has_value() ? *font_prop.distance : .0f; float act_distance = font_prop.distance.has_value() ? *font_prop.distance : .0f;

View File

@ -541,6 +541,19 @@ void FontManager::free_imgui_fonts()
m_imgui_font_atlas.Clear(); 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) ImFont * FontManager::load_imgui_font(size_t index, const std::string &text)
{ {
free_imgui_fonts(); // TODO: remove it after correct initialization 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; ImFontAtlasFlags_NoPowerOfTwoHeight;
const FontProp &font_prop = item.font_item.prop; const FontProp &font_prop = item.font_item.prop;
float font_size = get_imgui_font_size(font_prop, font_file);
// coeficient for convert line height to font size if (font_size < min_imgui_font_size)
float c1 = (font_file.ascent - font_file.descent + font_file.linegap) / (float) font_file.unit_per_em; font_size = min_imgui_font_size;
if (font_size > max_imgui_font_size)
// The point size is defined as 1/72 of the Anglo-Saxon inch (25.4 mm): font_size = max_imgui_font_size;
// 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;
ImFontConfig font_config; ImFontConfig font_config;
// TODO: start using merge mode // TODO: start using merge mode

View File

@ -154,6 +154,11 @@ public:
// check if exist selected font style in manager // check if exist selected font style in manager
bool is_activ_font(); 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: private:
ImFontAtlas m_imgui_font_atlas; ImFontAtlas m_imgui_font_atlas;
@ -182,14 +187,6 @@ private:
bool check_imgui_font_range(ImFont *font, const std::string &text); bool check_imgui_font_range(ImFont *font, const std::string &text);
void free_imgui_fonts(); 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); bool set_up_font_file(size_t item_index);
void make_unique_name(std::string &name); void make_unique_name(std::string &name);