diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index fe4f159997..1d8d81949d 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -487,6 +487,7 @@ static const FileWildcards file_wildcards_by_type[FT_SIZE] = { /* FT_GCODE */ { "G-code files"sv, { ".gcode"sv, ".gco"sv, ".g"sv, ".ngc"sv } }, /* FT_MODEL */ { "Known files"sv, { ".stl"sv, ".obj"sv, ".3mf"sv, ".amf"sv, ".zip.amf"sv, ".xml"sv } }, /* FT_PROJECT */ { "Project files"sv, { ".3mf"sv, ".amf"sv, ".zip.amf"sv } }, + /* FT_FONTS */ { "Font files"sv, { ".ttc"sv, ".ttf"sv } }, /* FT_GALLERY */ { "Known files"sv, { ".stl"sv, ".obj"sv } }, /* FT_INI */ { "INI files"sv, { ".ini"sv } }, diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 1e4bf44eeb..0e9a604b8d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -43,10 +43,12 @@ #define SHOW_IMGUI_ATLAS #define SHOW_FINE_POSITION #define DRAW_PLACE_TO_ADD_TEXT +#define ALLOW_REVERT_ALL_STYLES #endif // ALLOW_DEBUG_MODE #define ALLOW_ADD_FONT_BY_FILE #define ALLOW_ADD_FONT_BY_OS_SELECTOR +#define ALLOW_REVERT_ALL_STYLES using namespace Slic3r; using namespace Slic3r::GUI; @@ -488,7 +490,7 @@ void GLGizmoEmboss::initialize() FontList font_list = load_font_list_from_app_config(app_cfg); m_font_manager.add_fonts(font_list); if (!m_font_manager.load_first_valid_font()) { - FontList font_list = FontListSerializable::create_default_font_list(); + FontList font_list = create_default_font_list(); m_font_manager.add_fonts(font_list); // TODO: What to do when default fonts are not loadable? bool success = m_font_manager.load_first_valid_font(); @@ -497,6 +499,33 @@ void GLGizmoEmboss::initialize() set_default_text(); } +FontList GLGizmoEmboss::create_default_font_list() +{ + // https://docs.wxwidgets.org/3.0/classwx_font.html + // Predefined objects/pointers: wxNullFont, wxNORMAL_FONT, wxSMALL_FONT, wxITALIC_FONT, wxSWISS_FONT + + FontItem par_fi = WxFontUtils::get_font_item(*wxNORMAL_FONT, _u8L("Parallel to bed")); + + FontItem perp_fi = WxFontUtils::get_font_item(*wxNORMAL_FONT, _u8L("Perpendicular to bed")); + + FontItem fix_fi = WxFontUtils::get_font_item(*wxNORMAL_FONT, _u8L("Fixed size")); + + FontItem negative_fi = WxFontUtils::get_font_item(*wxNORMAL_FONT, _u8L("Negative")); + + return { + par_fi, + perp_fi, + fix_fi, + negative_fi, + WxFontUtils::get_font_item(*wxNORMAL_FONT), // wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + WxFontUtils::get_font_item(*wxSMALL_FONT), // A font using the wxFONTFAMILY_SWISS family and 2 points smaller than wxNORMAL_FONT. + WxFontUtils::get_font_item(*wxITALIC_FONT), // A font using the wxFONTFAMILY_ROMAN family and wxFONTSTYLE_ITALIC style and of the same size of wxNORMAL_FONT. + WxFontUtils::get_font_item(*wxSWISS_FONT), // A font identic to wxNORMAL_FONT except for the family used which is wxFONTFAMILY_SWISS. + WxFontUtils::get_font_item(wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)) + //, WxFontUtils::get_os_font() == wxNORMAL_FONT + }; +} + void GLGizmoEmboss::set_default_text() { m_text = _u8L("Embossed text"); @@ -705,6 +734,8 @@ void GLGizmoEmboss::draw_font_list() if (m_facenames.empty()) return false; return true; } + + std::vector m_efacenames; protected: virtual bool OnFacename(const wxString& facename) wxOVERRIDE { // vertical font start with @, we will filter it out @@ -712,6 +743,13 @@ void GLGizmoEmboss::draw_font_list() wxFont wx_font(wxFontInfo().FaceName(facename).Encoding(m_encoding)); void *addr = WxFontUtils::can_load(wx_font); if (addr == nullptr) return true; // can't load + + //auto ff = WxFontUtils::create_font_file(wx_font); + //if (ff == nullptr) { + // m_efacenames.emplace_back(facename.c_str()); + // return true; // can't create font file + //} + m_facenames.Add(facename); return true; } @@ -978,6 +1016,17 @@ void GLGizmoEmboss::draw_style_list() { if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", _u8L("Reload original value of selected style").c_str()); } + +#ifdef ALLOW_REVERT_ALL_STYLES + ImGui::SameLine(); + if (draw_button(IconType::revert_all)) { + m_font_manager = FontManager(m_imgui->get_glyph_ranges()); + FontList font_list = create_default_font_list(); + m_font_manager.add_fonts(font_list); + // TODO: What to do when default fonts are not loadable? + bool success = m_font_manager.load_first_valid_font(); + } +#endif // ALLOW_REVERT_ALL_STYLES } bool GLGizmoEmboss::italic_button() @@ -1461,7 +1510,8 @@ bool GLGizmoEmboss::init_icons() "make_bold.svg", "make_unbold.svg", "search.svg", - "open.svg" + "open.svg", + "revert_all_.svg" }; assert(filenames.size() == static_cast(IconType::_count)); std::string path = resources_dir() + "/icons/"; @@ -1541,7 +1591,7 @@ FontList GLGizmoEmboss::load_font_list_from_app_config(const AppConfig *cfg) section_name = FontListSerializable::create_section_name(index++); } if (result.empty()) - return FontListSerializable::create_default_font_list(); + return create_default_font_list(); return result; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index fb5ba23125..2e3faf357f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -73,6 +73,7 @@ protected: private: void initialize(); + static FontList create_default_font_list(); void set_default_text(); void check_selection(); @@ -96,6 +97,7 @@ private: void set_minimal_window_size(bool is_edit_style, bool is_advance_edit_style); const ImVec2 &get_minimal_window_size() const; + // process mouse event bool on_mouse_for_rotation(const wxMouseEvent &mouse_event); bool on_mouse_for_translate(const wxMouseEvent &mouse_event); @@ -192,6 +194,7 @@ private: unbold, system_selector, open_file, + revert_all, _count /* automatic calc of icon size */ }; enum class IconState: unsigned { activable = 0, hovered /*1*/, disabled /*2*/}; diff --git a/src/slic3r/Utils/FontListSerializable.cpp b/src/slic3r/Utils/FontListSerializable.cpp index 88d0890c3f..8c77747133 100644 --- a/src/slic3r/Utils/FontListSerializable.cpp +++ b/src/slic3r/Utils/FontListSerializable.cpp @@ -15,20 +15,6 @@ const std::string FontListSerializable::APP_CONFIG_FONT_SKEW = "skew"; const std::string FontListSerializable::APP_CONFIG_FONT_CHAR_GAP = "char_gap"; const std::string FontListSerializable::APP_CONFIG_FONT_LINE_GAP = "line_gap"; -FontList FontListSerializable::create_default_font_list() -{ - // https://docs.wxwidgets.org/3.0/classwx_font.html - // Predefined objects/pointers: wxNullFont, wxNORMAL_FONT, wxSMALL_FONT, wxITALIC_FONT, wxSWISS_FONT - return { - WxFontUtils::get_font_item(*wxNORMAL_FONT), // wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) - WxFontUtils::get_font_item(*wxSMALL_FONT), // A font using the wxFONTFAMILY_SWISS family and 2 points smaller than wxNORMAL_FONT. - WxFontUtils::get_font_item(*wxITALIC_FONT), // A font using the wxFONTFAMILY_ROMAN family and wxFONTSTYLE_ITALIC style and of the same size of wxNORMAL_FONT. - WxFontUtils::get_font_item(*wxSWISS_FONT), // A font identic to wxNORMAL_FONT except for the family used which is wxFONTFAMILY_SWISS. - WxFontUtils::get_font_item(wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)) - //, WxFontUtils::get_os_font() == wxNORMAL_FONT - }; -} - std::string FontListSerializable::create_section_name(unsigned index) { return AppConfig::SECTION_FONT + ':' + std::to_string(index); diff --git a/src/slic3r/Utils/FontListSerializable.hpp b/src/slic3r/Utils/FontListSerializable.hpp index 4efcffbb8d..dc598885fe 100644 --- a/src/slic3r/Utils/FontListSerializable.hpp +++ b/src/slic3r/Utils/FontListSerializable.hpp @@ -28,7 +28,6 @@ class FontListSerializable public: FontListSerializable() = delete; - static FontList create_default_font_list(); static std::string create_section_name(unsigned index); static std::optional load_font_item(const std::map &app_cfg_section); static void store_font_item(AppConfig &cfg, const FontItem &fi, unsigned index); diff --git a/src/slic3r/Utils/FontManager.cpp b/src/slic3r/Utils/FontManager.cpp index 70a7f6b1b0..6df0751b02 100644 --- a/src/slic3r/Utils/FontManager.cpp +++ b/src/slic3r/Utils/FontManager.cpp @@ -401,8 +401,8 @@ void FontManager::init_style_images(int max_width) { double scale = font_prop.size_in_mm; BoundingBoxf bb2 = unscaled(bounding_box); bb2.scale(scale); - image.tex_size.x = bb2.max.x() - bb2.min.x(); - image.tex_size.y = bb2.max.y() - bb2.min.y(); + image.tex_size.x = bb2.max.x() - bb2.min.x()+1; + image.tex_size.y = bb2.max.y() - bb2.min.y()+1; // crop image width if (image.tex_size.x > max_width) image.tex_size.x = max_width; @@ -475,6 +475,7 @@ void FontManager::init_style_images(int max_width) { } void FontManager::free_style_images() { + if (!is_activ_font()) return; std::shared_ptr &font_file = m_font_list[m_font_selected].font_file; if(font_file != nullptr) diff --git a/src/slic3r/Utils/FontManager.hpp b/src/slic3r/Utils/FontManager.hpp index ccae1a8932..ff1be33f76 100644 --- a/src/slic3r/Utils/FontManager.hpp +++ b/src/slic3r/Utils/FontManager.hpp @@ -106,6 +106,9 @@ public: const std::vector &get_fonts() const; const Item &get_font() const; + /// + /// Describe image in GPU to show settings of style + /// struct StyleImage { void* texture_id = 0; // GLuint @@ -115,6 +118,10 @@ public: StyleImage() = default; }; + /// + /// All connected with one style + /// keep temporary data and caches for style + /// struct Item { FontItem font_item; @@ -137,12 +144,12 @@ public: std::optional image; }; - // TODO: make private - ImFontAtlas m_imgui_font_atlas; - + // check if exist selected font style in manager bool is_activ_font(); private: + ImFontAtlas m_imgui_font_atlas; + void duplicate(size_t index); // load actual selected font ImFont *load_imgui_font(size_t index, const std::string &text); diff --git a/src/slic3r/Utils/WxFontUtils.cpp b/src/slic3r/Utils/WxFontUtils.cpp index 24d57154fe..ae2c3f1259 100644 --- a/src/slic3r/Utils/WxFontUtils.cpp +++ b/src/slic3r/Utils/WxFontUtils.cpp @@ -75,16 +75,16 @@ FontItem::Type WxFontUtils::get_actual_type() #endif } -FontItem WxFontUtils::get_font_item(const wxFont &font) +FontItem WxFontUtils::get_font_item(const wxFont &font, const std::string& name) { - std::string name = get_human_readable_name(font); - std::string fontDesc = store_wxFont(font); + std::string name_item = name.empty()? get_human_readable_name(font) : name; + std::string fontDesc = store_wxFont(font); FontItem::Type type = get_actual_type(); // synchronize font property with actual font FontProp font_prop; WxFontUtils::update_property(font_prop, font); - return FontItem(name, fontDesc, type, font_prop); + return FontItem(name_item, fontDesc, type, font_prop); } FontItem WxFontUtils::get_os_font() diff --git a/src/slic3r/Utils/WxFontUtils.hpp b/src/slic3r/Utils/WxFontUtils.hpp index 79fb2bc45d..71ac40b590 100644 --- a/src/slic3r/Utils/WxFontUtils.hpp +++ b/src/slic3r/Utils/WxFontUtils.hpp @@ -23,7 +23,7 @@ public: static std::unique_ptr create_font_file(const wxFont &font); static FontItem::Type get_actual_type(); - static FontItem get_font_item(const wxFont &font); + static FontItem get_font_item(const wxFont &font, const std::string& name = ""); // load font used by Operating system as default GUI static FontItem get_os_font();