///|/ Copyright (c) Prusa Research 2022 Filip Sykala @Jony01 ///|/ ///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher ///|/ #ifndef slic3r_EmbossStyleManager_hpp_ #define slic3r_EmbossStyleManager_hpp_ #include #include #include #include #include #include #include #include #include #include #include #include namespace Slic3r::GUI::Emboss { /// /// Manage Emboss text styles /// Cache actual state of style /// + imgui font /// + wx font /// class StyleManager { friend class CreateFontStyleImagesJob; // access to StyleImagesData public: /// Character to load for imgui when initialize imgui font /// Function to create default styles StyleManager(const ImWchar *language_glyph_range, const std::function& create_default_styles); /// /// Release imgui font and style images from GPU /// ~StyleManager(); /// /// Load font style list from config /// Also select actual activ font /// /// Application configuration loaded from file "PrusaSlicer.ini" /// + cfg is stored to privat variable void init(AppConfig *app_config); /// /// Write font list into AppConfig /// /// Configuration /// When true cache state will be used for store /// When true store activ index into configuration /// True on succes otherwise False. bool store_styles_to_app_config(bool use_modification = true, bool store_active_index = true); /// /// Append actual style to style list /// /// New name for style void add_style(const std::string& name); /// /// Change order of style item in m_styles. /// Fix selected font index when (i1 || i2) == m_font_selected /// /// First index to m_styles /// Second index to m_styles void swap(size_t i1, size_t i2); /// /// Discard changes in activ style /// When no activ style use last used OR first loadable /// void discard_style_changes(); /// /// Remove style from m_styles. /// Fix selected font index when index is under m_font_selected /// /// Index of style to be removed void erase(size_t index); /// /// Rename actual selected font item /// /// New name void rename(const std::string &name); /// /// load some valid style /// void load_valid_style(); /// /// Change active font /// When font not loaded roll back activ font /// /// New font index(from m_styles range) /// True on succes. False on fail load font bool load_style(size_t font_index); // load font style not stored in list struct Style; bool load_style(const Style &style); // fastering load font on index by wxFont, ignore type and descriptor bool load_style(const Style &style, const wxFont &font); // clear actual selected glyphs cache void clear_glyphs_cache(); // remove cached imgui font for actual selected font void clear_imgui_font(); // getters for private data const Style *get_stored_style() const; const Style &get_style() const { return m_style_cache.style; } Style &get_style() { return m_style_cache.style; } size_t get_style_index() const { return m_style_cache.style_index; } std::string &get_truncated_name() { return m_style_cache.truncated_name; } const ImFontAtlas &get_atlas() const { return m_style_cache.atlas; } const FontProp &get_font_prop() const { return get_style().prop; } FontProp &get_font_prop() { return get_style().prop; } const wxFont &get_wx_font() const { return m_style_cache.wx_font; } const wxFont &get_stored_wx_font() const { return m_style_cache.stored_wx_font; } Slic3r::Emboss::FontFileWithCache &get_font_file_with_cache() { return m_style_cache.font_file; } bool has_collections() const { return m_style_cache.font_file.font_file != nullptr && m_style_cache.font_file.font_file->infos.size() > 1; } // True when activ style has same name as some of stored style bool exist_stored_style() const { return m_style_cache.style_index != std::numeric_limits::max(); } /// /// check whether current style differ to selected /// /// bool is_font_changed() const; bool is_unique_style_name(const std::string &name) const; /// /// Setter on wx_font when changed /// /// new wx font /// True on success set otherwise FALSE bool set_wx_font(const wxFont &wx_font); /// /// Faster way of set wx_font when font file is known(do not load font file twice) /// When you not sure that wx_font is made by font_file use only set_wx_font(wx_font) /// /// Must be source of font file /// font file created by WxFontUtils::create_font_file(wx_font) /// True on success otherwise false bool set_wx_font(const wxFont &wx_font, std::unique_ptr font_file); // Getter on acitve font pointer for imgui // Initialize imgui font(generate texture) when doesn't exist yet. // Extend font atlas when not in glyph range ImFont *get_imgui_font(); // initialize font range by unique symbols in text ImFont *create_imgui_font(const std::string& text, double scale); // init truncated names of styles void init_trunc_names(float max_width); /// /// Initialization texture with rendered font style /// /// Maximal width and height of one style texture /// Text to render by style void init_style_images(const Vec2i32& max_size, const std::string &text); void free_style_images(); // access to all managed font styles const std::vector