OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::Emboss::StyleManager Class Reference

Manage Emboss text styles Cache actual state of style. More...

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/EmbossStyleManager.hpp>

Collaboration diagram for Slic3r::GUI::Emboss::StyleManager:

Classes

struct  StyleImage
 Describe image in GPU to show settings of style. More...
struct  Style
 All connected with one style keep temporary data and caches for style. More...
struct  StyleCache
 Cache data from style to reduce amount of: 1) loading font from file 2) Create atlas of symbols for imgui 3) Keep loaded(and modified by style) glyphs from font. More...
struct  StyleImagesData
 Keep data needed to create Font Style Images in Job. More...

Public Types

using Styles = std::vector<Style>

Public Member Functions

 StyleManager (const ImWchar *language_glyph_range, const std::function< EmbossStyles()> &create_default_styles)
 
Parameters
language_glyph_rangeCharacter to load for imgui when initialize imgui font
create_default_stylesFunction to create default styles

 ~StyleManager ()
 Release imgui font and style images from GPU.
void init (AppConfig *app_config)
 Load font style list from config Also select actual activ font.
bool store_styles_to_app_config (bool use_modification=true, bool store_active_index=true)
 Write font list into AppConfig.
void add_style (const std::string &name)
 Append actual style to style list.
void swap (size_t i1, size_t i2)
 Change order of style item in m_styles. Fix selected font index when (i1 || i2) == m_font_selected.
void discard_style_changes ()
 Discard changes in activ style When no activ style use last used OR first loadable.
void erase (size_t index)
 Remove style from m_styles. Fix selected font index when index is under m_font_selected.
void rename (const std::string &name)
 Rename actual selected font item.
void load_valid_style ()
 load some valid style
bool load_style (size_t font_index)
 Change active font When font not loaded roll back activ font.
bool load_style (const Style &style)
bool load_style (const Style &style, const wxFont &font)
void clear_glyphs_cache ()
void clear_imgui_font ()
const Style * get_stored_style () const
const Style & get_style () const
Style & get_style ()
size_t get_style_index () const
std::string & get_truncated_name ()
const ImFontAtlas & get_atlas () const
const FontProp & get_font_prop () const
FontProp & get_font_prop ()
const wxFont & get_wx_font () const
const wxFont & get_stored_wx_font () const
Slic3r::Emboss::FontFileWithCache & get_font_file_with_cache ()
bool has_collections () const
bool exist_stored_style () const
bool is_font_changed () const
 check whether current style differ to selected
bool is_unique_style_name (const std::string &name) const
bool set_wx_font (const wxFont &wx_font)
 Setter on wx_font when changed.
bool set_wx_font (const wxFont &wx_font, std::unique_ptr< Slic3r::Emboss::FontFile > font_file)
 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).
ImFont * get_imgui_font ()
ImFont * create_imgui_font (const std::string &text, double scale)
void init_trunc_names (float max_width)
void init_style_images (const Vec2i32 &max_size, const std::string &text)
 Initialization texture with rendered font style.
void free_style_images ()
const std::vector< Style > & get_styles () const
bool is_active_font ()

Static Public Member Functions

static float get_imgui_font_size (const FontProp &prop, const Slic3r::Emboss::FontFile &file, double scale)

Static Public Attributes

static float min_imgui_font_size = 18.f
static float max_imgui_font_size = 60.f

Private Attributes

std::function< EmbossStyles()> m_create_default_styles
const ImWchar * m_imgui_init_glyph_range
struct Slic3r::GUI::Emboss::StyleManager::StyleCache m_style_cache
Styles m_styles
AppConfig * m_app_config = nullptr
size_t m_last_style_index = std::numeric_limits<size_t>::max()
std::shared_ptr< StyleImagesData::StyleImages > m_temp_style_images = nullptr
bool m_exist_style_images = false

Friends

class CreateFontStyleImagesJob

Detailed Description

Manage Emboss text styles Cache actual state of style.

  • imgui font
  • wx font

Class Documentation

◆ Slic3r::GUI::Emboss::StyleManager::StyleImage

struct Slic3r::GUI::Emboss::StyleManager::StyleImage

Describe image in GPU to show settings of style.

Collaboration diagram for Slic3r::GUI::Emboss::StyleManager::StyleImage:
Class Members
BoundingBox bounding_box
Point offset = Point(0, 0)
ImVec2 tex_size
void * texture_id = nullptr
ImVec2 uv0
ImVec2 uv1

◆ Slic3r::GUI::Emboss::StyleManager::StyleCache

struct Slic3r::GUI::Emboss::StyleManager::StyleCache

Cache data from style to reduce amount of: 1) loading font from file 2) Create atlas of symbols for imgui 3) Keep loaded(and modified by style) glyphs from font.

Collaboration diagram for Slic3r::GUI::Emboss::StyleManager::StyleCache:
Class Members
ImFontAtlas atlas = {}
FontFileWithCache font_file = {}
ImVector< ImWchar > ranges = {}
wxFont stored_wx_font = {}
Style style = {}
size_t style_index = std::numeric_limits<size_t>::max()
string truncated_name
wxFont wx_font = {}

◆ Slic3r::GUI::Emboss::StyleManager::StyleImagesData

struct Slic3r::GUI::Emboss::StyleManager::StyleImagesData

Keep data needed to create Font Style Images in Job.

Collaboration diagram for Slic3r::GUI::Emboss::StyleManager::StyleImagesData:
Class Members
typedef vector< Item > Items std::vector<Item>
Class Members
Vec2i32 max_size
double ppm
shared_ptr< StyleImages > result
Items styles
string text

Member Typedef Documentation

◆ Styles

Constructor & Destructor Documentation

◆ StyleManager()

StyleManager::StyleManager ( const ImWchar * language_glyph_range,
const std::function< EmbossStyles()> & create_default_styles )

Parameters
language_glyph_rangeCharacter to load for imgui when initialize imgui font
create_default_stylesFunction to create default styles

43 : m_create_default_styles(create_default_styles)
44 , m_imgui_init_glyph_range(language_glyph_range)
45{}
const ImWchar * m_imgui_init_glyph_range
Definition EmbossStyleManager.hpp:241
std::function< EmbossStyles()> m_create_default_styles
Definition EmbossStyleManager.hpp:239

References m_create_default_styles, and m_imgui_init_glyph_range.

◆ ~StyleManager()

StyleManager::~StyleManager ( )

Release imgui font and style images from GPU.

47 {
50}
void clear_imgui_font()
Definition EmbossStyleManager.cpp:335
void free_style_images()
Definition EmbossStyleManager.cpp:433

References clear_imgui_font(), and free_style_images().

Here is the call graph for this function:

Member Function Documentation

◆ add_style()

void StyleManager::add_style ( const std::string & name)

Append actual style to style list.

Parameters
nameNew name for style
142 {
143 EmbossStyle& style = m_style_cache.style;
144 style.name = name;
145 ::make_unique_name(m_styles, style.name);
146 m_style_cache.style_index = m_styles.size();
147 m_style_cache.stored_wx_font = m_style_cache.wx_font;
148 m_style_cache.truncated_name.clear();
149 m_styles.push_back({style});
150}
#define style
Definition WipeTowerDialog.cpp:101
Styles m_styles
Definition EmbossStyleManager.hpp:278
struct Slic3r::GUI::Emboss::StyleManager::StyleCache m_style_cache

References m_style_cache, m_styles, and style.

◆ clear_glyphs_cache()

void StyleManager::clear_glyphs_cache ( )
329{
330 FontFileWithCache &ff = m_style_cache.font_file;
331 if (!ff.has_value()) return;
332 ff.cache = std::make_shared<Glyphs>();
333}
std::shared_ptr< Emboss::Glyphs > cache
Definition Emboss.hpp:121
bool has_value() const
Definition Emboss.hpp:128

References Slic3r::Emboss::FontFileWithCache::cache, Slic3r::Emboss::FontFileWithCache::has_value(), and m_style_cache.

Here is the call graph for this function:

◆ clear_imgui_font()

void StyleManager::clear_imgui_font ( )
335{ m_style_cache.atlas.Clear(); }

References m_style_cache.

Referenced by ~StyleManager(), and set_wx_font().

Here is the caller graph for this function:

◆ create_imgui_font()

ImFont * StyleManager::create_imgui_font ( const std::string & text,
double scale )
461{
462 // inspiration inside of ImGuiWrapper::init_font
463 auto& ff = m_style_cache.font_file;
464 if (!ff.has_value()) return nullptr;
465 const FontFile &font_file = *ff.font_file;
466
467 ImFontGlyphRangesBuilder builder;
468 builder.AddRanges(m_imgui_init_glyph_range);
469 if (!text.empty())
470 builder.AddText(text.c_str());
471
472 ImVector<ImWchar> &ranges = m_style_cache.ranges;
473 ranges.clear();
474 builder.BuildRanges(&ranges);
475
476 m_style_cache.atlas.Flags |= ImFontAtlasFlags_NoMouseCursors |
477 ImFontAtlasFlags_NoPowerOfTwoHeight;
478
479 const FontProp &font_prop = m_style_cache.style.prop;
480 float font_size = get_imgui_font_size(font_prop, font_file, scale);
481 if (font_size < min_imgui_font_size)
482 font_size = min_imgui_font_size;
483 if (font_size > max_imgui_font_size)
484 font_size = max_imgui_font_size;
485
486 ImFontConfig font_config;
487 // TODO: start using merge mode
488 //font_config.MergeMode = true;
489 int unit_per_em = get_font_info(font_file, font_prop).unit_per_em;
490 float coef = font_size / (double) unit_per_em;
491 if (font_prop.char_gap.has_value())
492 font_config.GlyphExtraSpacing.x = coef * (*font_prop.char_gap);
493 if (font_prop.line_gap.has_value())
494 font_config.GlyphExtraSpacing.y = coef * (*font_prop.line_gap);
495
496 font_config.FontDataOwnedByAtlas = false;
497
498 const std::vector<unsigned char> &buffer = *font_file.data;
499 ImFont * font = m_style_cache.atlas.AddFontFromMemoryTTF(
500 (void *) buffer.data(), buffer.size(), font_size, &font_config, m_style_cache.ranges.Data);
501
502 unsigned char *pixels;
503 int width, height;
504 m_style_cache.atlas.GetTexDataAsRGBA32(&pixels, &width, &height);
505
506 // Upload texture to graphics system
507 GLint last_texture;
509 ScopeGuard sg([last_texture]() {
510 glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture));
511 });
512
513 GLuint font_texture;
514 glsafe(::glGenTextures(1, &font_texture));
515 glsafe(::glBindTexture(GL_TEXTURE_2D, font_texture));
521 else
522 glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
523
524 // Store our identifier
525 m_style_cache.atlas.TexID = (ImTextureID) (intptr_t) font_texture;
526 assert(!m_style_cache.atlas.Fonts.empty());
527 if (m_style_cache.atlas.Fonts.empty()) return nullptr;
528 assert(font == m_style_cache.atlas.Fonts.back());
529 if (!font->IsLoaded()) return nullptr;
530 assert(font->IsLoaded());
531 return font;
532}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
int scale(const int val)
Definition WipeTowerDialog.cpp:58
static float get_imgui_font_size(const FontProp &prop, const Slic3r::Emboss::FontFile &file, double scale)
Definition EmbossStyleManager.cpp:448
static float min_imgui_font_size
Definition EmbossStyleManager.hpp:233
static float max_imgui_font_size
Definition EmbossStyleManager.hpp:234
static bool are_compressed_textures_supported()
Definition OpenGLManager.hpp:99
#define GL_TEXTURE_MIN_FILTER
Definition gl.h:1828
#define glPixelStorei
Definition gl.h:4451
#define GL_LINEAR
Definition gl.h:930
#define glTexParameteri
Definition gl.h:4911
int GLint
Definition gl.h:2062
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
Definition gl.h:449
#define glGetIntegerv
Definition gl.h:3873
#define glTexImage2D
Definition gl.h:4895
#define GL_UNSIGNED_BYTE
Definition gl.h:1937
#define glGenTextures
Definition gl.h:3787
#define glBindTexture
Definition gl.h:3299
#define GL_RGBA
Definition gl.h:1493
unsigned int GLuint
Definition gl.h:2063
#define GL_TEXTURE_MAG_FILTER
Definition gl.h:1822
#define GL_TEXTURE_2D
Definition gl.h:1739
#define GL_TEXTURE_BINDING_2D
Definition gl.h:1749
#define GL_UNPACK_ROW_LENGTH
Definition gl.h:1931
const FontFile::Info & get_font_info(const FontFile &font, const FontProp &prop)
getter of font info by collection defined in prop
Definition Emboss.cpp:1273
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185
std::unique_ptr< std::vector< unsigned char > > data
Definition Emboss.hpp:76
int unit_per_em
Definition Emboss.hpp:84
std::optional< int > char_gap
Definition TextConfiguration.hpp:25
std::optional< int > line_gap
Definition TextConfiguration.hpp:29

References Slic3r::GUI::OpenGLManager::are_compressed_textures_supported(), Slic3r::FontProp::char_gap, Slic3r::Emboss::FontFile::data, Slic3r::Emboss::get_font_info(), get_imgui_font_size(), GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_LINEAR, GL_RGBA, GL_TEXTURE_2D, GL_TEXTURE_BINDING_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_UNPACK_ROW_LENGTH, GL_UNSIGNED_BYTE, glBindTexture, glGenTextures, glGetIntegerv, glPixelStorei, glsafe, glTexImage2D, glTexParameteri, Slic3r::FontProp::line_gap, m_imgui_init_glyph_range, m_style_cache, max_imgui_font_size, min_imgui_font_size, scale(), and Slic3r::Emboss::FontFile::Info::unit_per_em.

Here is the call graph for this function:

◆ discard_style_changes()

void StyleManager::discard_style_changes ( )

Discard changes in activ style When no activ style use last used OR first loadable.

165 {
166 if (exist_stored_style()) {
167 if (load_style(m_style_cache.style_index))
168 return; // correct reload style
169 } else {
171 return; // correct load last used style
172 }
173
174 // try to save situation by load some font
176}
void load_valid_style()
load some valid style
Definition EmbossStyleManager.cpp:201
bool exist_stored_style() const
Definition EmbossStyleManager.hpp:132
size_t m_last_style_index
Definition EmbossStyleManager.hpp:280
bool load_style(size_t font_index)
Change active font When font not loaded roll back activ font.
Definition EmbossStyleManager.cpp:233

References exist_stored_style(), load_style(), load_valid_style(), m_last_style_index, and m_style_cache.

Here is the call graph for this function:

◆ erase()

void StyleManager::erase ( size_t index)

Remove style from m_styles. Fix selected font index when index is under m_font_selected.

Parameters
indexIndex of style to be removed
178 {
179 if (index >= m_styles.size()) return;
180
181 // fix selected index
182 if (exist_stored_style()) {
183 size_t &i = m_style_cache.style_index;
184 if (index < i) --i;
185 else if (index == i) i = std::numeric_limits<size_t>::max();
186 }
187
188 m_styles.erase(m_styles.begin() + index);
189}

References exist_stored_style(), m_style_cache, and m_styles.

Here is the call graph for this function:

◆ exist_stored_style()

bool Slic3r::GUI::Emboss::StyleManager::exist_stored_style ( ) const
inline
132{ return m_style_cache.style_index != std::numeric_limits<size_t>::max(); }

References m_style_cache.

Referenced by discard_style_changes(), erase(), is_font_changed(), rename(), store_styles_to_app_config(), and swap().

Here is the caller graph for this function:

◆ free_style_images()

void StyleManager::free_style_images ( )
433 {
434 if (!m_exist_style_images) return;
435 GLuint tex_id = 0;
436 for (Style &it : m_styles) {
437 if (tex_id == 0 && it.image.has_value())
438 tex_id = (GLuint)(intptr_t) it.image->texture_id;
439 it.image.reset();
440 }
441 if (tex_id != 0)
442 glsafe(::glDeleteTextures(1, &tex_id));
443 m_exist_style_images = false;
444}
bool m_exist_style_images
Definition EmbossStyleManager.hpp:320
#define glDeleteTextures
Definition gl.h:3587
All connected with one style keep temporary data and caches for style.
Definition EmbossStyleManager.hpp:197

References glDeleteTextures, glsafe, m_exist_style_images, and m_styles.

Referenced by ~StyleManager().

Here is the caller graph for this function:

◆ get_atlas()

const ImFontAtlas & Slic3r::GUI::Emboss::StyleManager::get_atlas ( ) const
inline
122{ return m_style_cache.atlas; }

References m_style_cache.

◆ get_font_file_with_cache()

Slic3r::Emboss::FontFileWithCache & Slic3r::GUI::Emboss::StyleManager::get_font_file_with_cache ( )
inline
127{ return m_style_cache.font_file; }

References m_style_cache.

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::can_write(), anonymous_namespace{GLGizmoEmboss.cpp}::create_emboss_data_base(), and Slic3r::GUI::TextLinesModel::init().

Here is the caller graph for this function:

◆ get_font_prop() [1/2]

FontProp & Slic3r::GUI::Emboss::StyleManager::get_font_prop ( )
inline
124{ return get_style().prop; }
const Style & get_style() const
Definition EmbossStyleManager.hpp:118
FontProp prop
Definition TextConfiguration.hpp:131

References get_style(), and Slic3r::EmbossStyle::prop.

Here is the call graph for this function:

◆ get_font_prop() [2/2]

const FontProp & Slic3r::GUI::Emboss::StyleManager::get_font_prop ( ) const
inline
123{ return get_style().prop; }

References get_style(), and Slic3r::EmbossStyle::prop.

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::can_write(), and Slic3r::GUI::TextLinesModel::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_imgui_font()

ImFont * StyleManager::get_imgui_font ( )
338{
339 if (!is_active_font()) return nullptr;
340
341 ImVector<ImFont *> &fonts = m_style_cache.atlas.Fonts;
342 if (fonts.empty()) return nullptr;
343
344 // check correct index
345 int f_size = fonts.size();
346 assert(f_size == 1);
347 if (f_size != 1) return nullptr;
348 ImFont *font = fonts.front();
349 if (font == nullptr) return nullptr;
350 return font;
351}
bool is_active_font()
Definition EmbossStyleManager.cpp:320

References is_active_font(), and m_style_cache.

Here is the call graph for this function:

◆ get_imgui_font_size()

float StyleManager::get_imgui_font_size ( const FontProp & prop,
const Slic3r::Emboss::FontFile & file,
double scale )
static
449{
450 const FontFile::Info& info = get_font_info(file, prop);
451 // coeficient for convert line height to font size
452 float c1 = (info.ascent - info.descent + info.linegap) /
453 (float) info.unit_per_em;
454
455 // The point size is defined as 1/72 of the Anglo-Saxon inch (25.4 mm):
456 // It is approximately 0.0139 inch or 352.8 um.
457 return c1 * std::abs(prop.size_in_mm) / 0.3528f * scale;
458}
int linegap
Definition Emboss.hpp:81
int ascent
Definition Emboss.hpp:81
int descent
Definition Emboss.hpp:81
float size_in_mm
Definition TextConfiguration.hpp:63

References Slic3r::Emboss::FontFile::Info::ascent, Slic3r::Emboss::FontFile::Info::descent, Slic3r::Emboss::get_font_info(), Slic3r::Emboss::FontFile::Info::linegap, scale(), Slic3r::FontProp::size_in_mm, and Slic3r::Emboss::FontFile::Info::unit_per_em.

Referenced by create_imgui_font(), and Slic3r::GUI::GLGizmoEmboss::draw_text_input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_stored_style()

const StyleManager::Style * StyleManager::get_stored_style ( ) const
323{
324 if (m_style_cache.style_index >= m_styles.size()) return nullptr;
325 return &m_styles[m_style_cache.style_index];
326}

References m_style_cache, and m_styles.

Referenced by is_font_changed().

Here is the caller graph for this function:

◆ get_stored_wx_font()

const wxFont & Slic3r::GUI::Emboss::StyleManager::get_stored_wx_font ( ) const
inline
126{ return m_style_cache.stored_wx_font; }

References m_style_cache.

Referenced by is_font_changed().

Here is the caller graph for this function:

◆ get_style() [1/2]

Style & Slic3r::GUI::Emboss::StyleManager::get_style ( )
inline
119{ return m_style_cache.style; }

References m_style_cache.

◆ get_style() [2/2]

const Style & Slic3r::GUI::Emboss::StyleManager::get_style ( ) const
inline
118{ return m_style_cache.style; }

References m_style_cache.

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::create_emboss_data_base(), get_font_prop(), get_font_prop(), and is_font_changed().

Here is the caller graph for this function:

◆ get_style_index()

size_t Slic3r::GUI::Emboss::StyleManager::get_style_index ( ) const
inline
120{ return m_style_cache.style_index; }

References m_style_cache.

◆ get_styles()

const StyleManager::Styles & StyleManager::get_styles ( ) const
353{ return m_styles; }

References m_styles.

◆ get_truncated_name()

std::string & Slic3r::GUI::Emboss::StyleManager::get_truncated_name ( )
inline
121{ return m_style_cache.truncated_name; }

References m_style_cache.

◆ get_wx_font()

const wxFont & Slic3r::GUI::Emboss::StyleManager::get_wx_font ( ) const
inline
125{ return m_style_cache.wx_font; }

References m_style_cache.

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::create_emboss_data_base(), and is_font_changed().

Here is the caller graph for this function:

◆ has_collections()

bool Slic3r::GUI::Emboss::StyleManager::has_collections ( ) const
inline
128 { return m_style_cache.font_file.font_file != nullptr &&
129 m_style_cache.font_file.font_file->infos.size() > 1; }

References m_style_cache.

◆ init()

void StyleManager::init ( AppConfig * app_config)

Load font style list from config Also select actual activ font.

Parameters
app_configApplication configuration loaded from file "PrusaSlicer.ini"
  • cfg is stored to privat variable
79{
80 assert(app_config != nullptr);
81 m_app_config = app_config;
82 m_styles = ::load_styles(*app_config);
83
84 if (m_styles.empty()) {
85 // No styles loaded from ini file so use default
87 for (EmbossStyle &style : styles) {
88 ::make_unique_name(m_styles, style.name);
89 m_styles.push_back({style});
90 }
91 }
92
93 std::optional<size_t> active_index_opt = (app_config != nullptr) ?
94 ::load_style_index(*app_config) :
95 std::optional<size_t>{};
96
97 size_t active_index = 0;
98 if (active_index_opt.has_value()) active_index = *active_index_opt;
99 if (active_index >= m_styles.size()) active_index = 0;
100
101 // find valid font item
102 if (load_style(active_index))
103 return; // style is loaded
104
105 // Try to fix that style can't be loaded
106 m_styles.erase(m_styles.begin() + active_index);
107
109}
AppConfig * m_app_config
Definition EmbossStyleManager.hpp:279
std::vector< EmbossStyle > EmbossStyles
Definition TextConfiguration.hpp:168

References load_style(), load_valid_style(), m_app_config, m_create_default_styles, m_styles, and style.

Here is the call graph for this function:

◆ init_style_images()

void StyleManager::init_style_images ( const Vec2i32 & max_size,
const std::string & text )

Initialization texture with rendered font style.

Parameters
max_sizeMaximal width and height of one style texture
textText to render by style
373{
374 // check already initialized
375 if (m_exist_style_images) return;
376
377 // check is initializing
378 if (m_temp_style_images != nullptr) {
379 // is initialization finished
380 if (!m_temp_style_images->styles.empty()) {
381 assert(m_temp_style_images->images.size() ==
382 m_temp_style_images->styles.size());
383 // copy images into styles
384 for (StyleManager::StyleImage &image : m_temp_style_images->images){
385 size_t index = &image - &m_temp_style_images->images.front();
387
388 // find style in font list and copy to it
389 for (auto &it : m_styles) {
390 if (it.name != style.text ||
391 !(it.prop == style.prop))
392 continue;
393 it.image = image;
394 break;
395 }
396 }
397 m_temp_style_images = nullptr;
399 return;
400 }
401 // in process of initialization inside of job
402 return;
403 }
404
405 // create job for init images
406 m_temp_style_images = std::make_shared<StyleImagesData::StyleImages>();
408 styles.reserve(m_styles.size());
409 for (const Style &style : m_styles) {
410 std::optional<wxFont> wx_font_opt = WxFontUtils::load_wxFont(style.path);
411 if (!wx_font_opt.has_value()) continue;
412 std::unique_ptr<FontFile> font_file =
413 WxFontUtils::create_font_file(*wx_font_opt);
414 if (font_file == nullptr) continue;
415 styles.push_back({
416 FontFileWithCache(std::move(font_file)),
417 style.name,
418 style.prop
419 });
420 }
421
422 auto mf = wxGetApp().mainframe;
423 // dot per inch for monitor
424 int dpi = get_dpi_for_window(mf);
425 // pixel per millimeter
426 double ppm = dpi / GizmoObjectManipulation::in_to_mm;
427
428 auto &worker = wxGetApp().plater()->get_ui_job_worker();
429 StyleImagesData data{std::move(styles), max_size, text, m_temp_style_images, ppm};
430 queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
431}
std::shared_ptr< StyleImagesData::StyleImages > m_temp_style_images
Definition EmbossStyleManager.hpp:319
std::vector< Item > Items
Definition EmbossStyleManager.hpp:293
Keep data needed to create Font Style Images in Job.
Definition EmbossStyleManager.hpp:286
static const double in_to_mm
Definition GizmoObjectManipulation.hpp:30
static std::unique_ptr< Slic3r::Emboss::FontFile > create_font_file(const wxFont &font)
Definition WxFontUtils.cpp:93
static wxFont load_wxFont(const std::string &font_descriptor)
Definition WxFontUtils.cpp:190
int get_dpi_for_window(const wxWindow *window)
Definition GUI_Utils.cpp:234
bool queue_job(Worker &w, ProcessFn fn, FinishFn finishfn)
Definition Worker.hpp:62

References Slic3r::GUI::WxFontUtils::create_font_file(), Slic3r::GUI::get_dpi_for_window(), Slic3r::GUI::GizmoObjectManipulation::in_to_mm, Slic3r::GUI::WxFontUtils::load_wxFont(), m_exist_style_images, m_styles, m_temp_style_images, Slic3r::GUI::queue_job(), and style.

Here is the call graph for this function:

◆ init_trunc_names()

void StyleManager::init_trunc_names ( float max_width)
354 {
355 for (auto &s : m_styles)
356 if (s.truncated_name.empty()) {
357 std::string name = s.name;
359 s.truncated_name = ImGuiWrapper::trunc(name, max_width);
360 }
361}
static void escape_double_hash(std::string &text)
Escape ## in data by add space between hashes Needed when user written text is visualized by ImGui.
Definition ImGuiWrapper.cpp:2466
static std::string trunc(const std::string &text, float width, const char *tail=" ..")
Truncate text by ImGui draw function to specific width NOTE 1: ImGui must be initialized NOTE 2: Calc...
Definition ImGuiWrapper.cpp:2427

References Slic3r::GUI::ImGuiWrapper::escape_double_hash(), m_styles, and Slic3r::GUI::ImGuiWrapper::trunc().

Here is the call graph for this function:

◆ is_active_font()

bool StyleManager::is_active_font ( )
320{ return m_style_cache.font_file.has_value(); }

References m_style_cache.

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::create_emboss_data_base(), get_imgui_font(), and Slic3r::GUI::TextLinesModel::init().

Here is the caller graph for this function:

◆ is_font_changed()

bool StyleManager::is_font_changed ( ) const

check whether current style differ to selected

Returns
277{
278 const wxFont &wx_font = get_wx_font();
279 if (!wx_font.IsOk())
280 return false;
281 if (!exist_stored_style())
282 return false;
283 const EmbossStyle *stored_style = get_stored_style();
284 if (stored_style == nullptr)
285 return false;
286
287 const wxFont &wx_font_stored = get_stored_wx_font();
288 if (!wx_font_stored.IsOk())
289 return false;
290
291 const FontProp &prop = get_style().prop;
292 const FontProp &prop_stored = stored_style->prop;
293
294 // Exist change in face name?
295 if(wx_font_stored.GetFaceName() != wx_font.GetFaceName()) return true;
296
297 const std::optional<float> &skew = prop.skew;
298 bool is_italic = skew.has_value() || WxFontUtils::is_italic(wx_font);
299 const std::optional<float> &skew_stored = prop_stored.skew;
300 bool is_stored_italic = skew_stored.has_value() || WxFontUtils::is_italic(wx_font_stored);
301 // is italic changed
302 if (is_italic != is_stored_italic)
303 return true;
304
305 const std::optional<float> &boldness = prop.boldness;
306 bool is_bold = boldness.has_value() || WxFontUtils::is_bold(wx_font);
307 const std::optional<float> &boldness_stored = prop_stored.boldness;
308 bool is_stored_bold = boldness_stored.has_value() || WxFontUtils::is_bold(wx_font_stored);
309 // is bold changed
310 return is_bold != is_stored_bold;
311}
const wxFont & get_stored_wx_font() const
Definition EmbossStyleManager.hpp:126
const wxFont & get_wx_font() const
Definition EmbossStyleManager.hpp:125
const Style * get_stored_style() const
Definition EmbossStyleManager.cpp:322
static bool is_bold(const wxFont &font)
Definition WxFontUtils.cpp:304
static bool is_italic(const wxFont &font)
Definition WxFontUtils.cpp:298
bool is_italic(const FontFile &font, unsigned int font_index)
Read information from naming table of font file search for italic (or oblique), bold italic (or bold ...
Definition Emboss.cpp:1491
std::optional< float > boldness
Definition TextConfiguration.hpp:34
std::optional< float > skew
Definition TextConfiguration.hpp:39

References Slic3r::FontProp::boldness, exist_stored_style(), get_stored_style(), get_stored_wx_font(), get_style(), get_wx_font(), Slic3r::GUI::WxFontUtils::is_bold(), Slic3r::Emboss::is_italic(), Slic3r::GUI::WxFontUtils::is_italic(), Slic3r::EmbossStyle::prop, and Slic3r::FontProp::skew.

Here is the call graph for this function:

◆ is_unique_style_name()

bool StyleManager::is_unique_style_name ( const std::string & name) const
313 {
314 for (const StyleManager::Style &style : m_styles)
315 if (style.name == name)
316 return false;
317 return true;
318}

References m_styles, and style.

◆ load_style() [1/3]

bool StyleManager::load_style ( const Style & style)
243 {
245 std::unique_ptr<FontFile> font_ptr =
246 create_font_file(style.path.c_str());
247 if (font_ptr == nullptr) return false;
248 m_style_cache.wx_font = {};
249 m_style_cache.font_file =
250 FontFileWithCache(std::move(font_ptr));
251 m_style_cache.style = style; // copy
252 m_style_cache.style_index = std::numeric_limits<size_t>::max();
253 m_style_cache.stored_wx_font = {};
254 return true;
255 }
256 if (style.type != WxFontUtils::get_current_type()) return false;
257 std::optional<wxFont> wx_font_opt = WxFontUtils::load_wxFont(style.path);
258 if (!wx_font_opt.has_value()) return false;
259 return load_style(style, *wx_font_opt);
260}
static EmbossStyle::Type get_current_type()
Definition WxFontUtils.cpp:120
std::unique_ptr< FontFile > create_font_file(const char *file_path)
Load font file into buffer.
Definition Emboss.cpp:1164
@ file_path
Definition TextConfiguration.hpp:148

References Slic3r::Emboss::create_font_file(), Slic3r::EmbossStyle::file_path, Slic3r::GUI::WxFontUtils::get_current_type(), load_style(), Slic3r::GUI::WxFontUtils::load_wxFont(), m_style_cache, and style.

Here is the call graph for this function:

◆ load_style() [2/3]

bool StyleManager::load_style ( const Style & style,
const wxFont & font )
263{
264 m_style_cache.style = style; // copy
265
266 // wx font property has bigger priority to set
267 // it must be after copy of the style
268 if (!set_wx_font(font)) return false;
269
270 m_style_cache.style_index = std::numeric_limits<size_t>::max();
271 m_style_cache.stored_wx_font = {};
272 m_style_cache.truncated_name.clear();
273 return true;
274}
bool set_wx_font(const wxFont &wx_font)
Setter on wx_font when changed.
Definition EmbossStyleManager.cpp:534

References m_style_cache, set_wx_font(), and style.

Here is the call graph for this function:

◆ load_style() [3/3]

bool StyleManager::load_style ( size_t font_index)

Change active font When font not loaded roll back activ font.

Parameters
font_indexNew font index(from m_styles range)
Returns
True on succes. False on fail load font
234{
235 if (style_index >= m_styles.size()) return false;
236 if (!load_style(m_styles[style_index])) return false;
237 m_style_cache.style_index = style_index;
238 m_style_cache.stored_wx_font = m_style_cache.wx_font; // copy
239 m_last_style_index = style_index;
240 return true;
241}

References load_style(), m_last_style_index, m_style_cache, and m_styles.

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::can_write(), discard_style_changes(), init(), load_style(), load_style(), load_valid_style(), and Slic3r::GUI::GLGizmoEmboss::re_emboss().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_valid_style()

void StyleManager::load_valid_style ( )

load some valid style

202{
203 // iterate over all known styles
204 while (!m_styles.empty()) {
205 if (load_style(0))
206 return;
207 // can't load so erase it from list
208 m_styles.erase(m_styles.begin());
209 }
210
211 // no one style is loadable
212 // set up default font list
214 for (EmbossStyle &style : def_style) {
215 ::make_unique_name(m_styles, style.name);
216 m_styles.push_back({std::move(style)});
217 }
218
219 // iterate over default styles
220 // There have to be option to use build in font
221 while (!m_styles.empty()) {
222 if (load_style(0))
223 return;
224 // can't load so erase it from list
225 m_styles.erase(m_styles.begin());
226 }
227
228 // This OS doesn't have TTF as default font,
229 // find some loadable font out of default list
230 assert(false);
231}

References load_style(), m_create_default_styles, m_styles, and style.

Referenced by anonymous_namespace{GLGizmoEmboss.cpp}::create_emboss_data_base(), discard_style_changes(), and init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rename()

void StyleManager::rename ( const std::string & name)

Rename actual selected font item.

Parameters
nameNew name
191 {
192 m_style_cache.style.name = name;
193 m_style_cache.truncated_name.clear();
194 if (exist_stored_style()) {
195 Style &it = m_styles[m_style_cache.style_index];
196 it.name = name;
197 it.truncated_name.clear();
198 }
199}

References exist_stored_style(), m_style_cache, m_styles, Slic3r::EmbossStyle::name, and Slic3r::GUI::Emboss::StyleManager::Style::truncated_name.

Here is the call graph for this function:

◆ set_wx_font() [1/2]

bool StyleManager::set_wx_font ( const wxFont & wx_font)

Setter on wx_font when changed.

Parameters
wx_fontnew wx font
Returns
True on success set otherwise FALSE
534 {
535 std::unique_ptr<FontFile> font_file =
537 return set_wx_font(wx_font, std::move(font_file));
538}

References Slic3r::GUI::WxFontUtils::create_font_file(), and set_wx_font().

Referenced by load_style(), and set_wx_font().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_wx_font() [2/2]

bool StyleManager::set_wx_font ( const wxFont & wx_font,
std::unique_ptr< Slic3r::Emboss::FontFile > font_file )

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).

Parameters
wx_fontMust be source of font file
font_filefont file created by WxFontUtils::create_font_file(wx_font)
Returns
True on success otherwise false
541{
542 if (font_file == nullptr) return false;
543 m_style_cache.wx_font = wx_font; // copy
544 m_style_cache.font_file =
545 FontFileWithCache(std::move(font_file));
546
547 EmbossStyle &style = m_style_cache.style;
549 // update string path
550 style.path = WxFontUtils::store_wxFont(wx_font);
551 WxFontUtils::update_property(style.prop, wx_font);
553 return true;
554}
static std::string store_wxFont(const wxFont &font)
Definition WxFontUtils.cpp:176
static void update_property(FontProp &font_prop, const wxFont &font)
Definition WxFontUtils.cpp:273

References clear_imgui_font(), Slic3r::GUI::WxFontUtils::get_current_type(), m_style_cache, Slic3r::GUI::WxFontUtils::store_wxFont(), style, and Slic3r::GUI::WxFontUtils::update_property().

Here is the call graph for this function:

◆ store_styles_to_app_config()

bool StyleManager::store_styles_to_app_config ( bool use_modification = true,
bool store_active_index = true )

Write font list into AppConfig.

Parameters
item_to_storeConfiguration
use_modificationWhen true cache state will be used for store
use_modificationWhen true store activ index into configuration
Returns
True on succes otherwise False.
112{
113 assert(m_app_config != nullptr);
114 if (m_app_config == nullptr) return false;
115 if (use_modification) {
116 if (exist_stored_style()) {
117 // update stored item
118 m_styles[m_style_cache.style_index] = m_style_cache.style;
119 } else {
120 // add new into stored list
121 EmbossStyle &style = m_style_cache.style;
122 ::make_unique_name(m_styles, style.name);
123 m_style_cache.truncated_name.clear();
124 m_style_cache.style_index = m_styles.size();
125 m_styles.push_back({style});
126 }
127 m_style_cache.stored_wx_font = m_style_cache.wx_font;
128 }
129
130 if (store_active_index)
131 {
132 size_t style_index = exist_stored_style() ?
133 m_style_cache.style_index :
135 store_style_index(*m_app_config, style_index);
136 }
137
139 return true;
140}
void store_style_index(AppConfig &cfg, size_t index)
Definition EmbossStyleManager.cpp:764
void store_styles(AppConfig &cfg, const StyleManager::Styles &styles)
Definition EmbossStyleManager.cpp:806

References exist_stored_style(), m_app_config, m_last_style_index, m_style_cache, m_styles, and style.

Here is the call graph for this function:

◆ swap()

void StyleManager::swap ( size_t i1,
size_t i2 )

Change order of style item in m_styles. Fix selected font index when (i1 || i2) == m_font_selected.

Parameters
i1First index to m_styles
i2Second index to m_styles
152 {
153 if (i1 >= m_styles.size() ||
154 i2 >= m_styles.size()) return;
155 std::swap(m_styles[i1], m_styles[i2]);
156 // fix selected index
157 if (!exist_stored_style()) return;
158 if (m_style_cache.style_index == i1) {
159 m_style_cache.style_index = i2;
160 } else if (m_style_cache.style_index == i2) {
161 m_style_cache.style_index = i1;
162 }
163}

References exist_stored_style(), m_style_cache, and m_styles.

Here is the call graph for this function:

◆ CreateFontStyleImagesJob

friend class CreateFontStyleImagesJob
friend

References CreateFontStyleImagesJob, and style.

Referenced by CreateFontStyleImagesJob.

Member Data Documentation

◆ m_app_config

AppConfig* Slic3r::GUI::Emboss::StyleManager::m_app_config = nullptr
private

Referenced by init(), and store_styles_to_app_config().

◆ m_create_default_styles

std::function<EmbossStyles()> Slic3r::GUI::Emboss::StyleManager::m_create_default_styles
private

◆ m_exist_style_images

bool Slic3r::GUI::Emboss::StyleManager::m_exist_style_images = false
private

◆ m_imgui_init_glyph_range

const ImWchar* Slic3r::GUI::Emboss::StyleManager::m_imgui_init_glyph_range
private

Referenced by StyleManager(), and create_imgui_font().

◆ m_last_style_index

size_t Slic3r::GUI::Emboss::StyleManager::m_last_style_index = std::numeric_limits<size_t>::max()
private

◆ m_style_cache

◆ m_styles

◆ m_temp_style_images

std::shared_ptr<StyleImagesData::StyleImages> Slic3r::GUI::Emboss::StyleManager::m_temp_style_images = nullptr
private

Referenced by init_style_images().

◆ max_imgui_font_size

float StyleManager::max_imgui_font_size = 60.f
static

◆ min_imgui_font_size

float StyleManager::min_imgui_font_size = 18.f
static

The documentation for this class was generated from the following files: