diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index ce32efd7e..c21052a0c 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -485,8 +485,11 @@ std::optional Emboss::letter2glyph(const Font &font, Polygons Emboss::text2polygons(const Font & font, const char * text, const FontProp &font_prop, - Glyphs & cache) + Glyphs * cache) { + Glyphs tmp; + if (cache == nullptr) cache = &tmp; + std::optional font_info_opt; Point cursor(0, 0); @@ -501,8 +504,8 @@ Polygons Emboss::text2polygons(const Font & font, } int unicode = static_cast(wc); std::optional glyph_opt; - auto glyph_item = cache.find(unicode); - if (glyph_item != cache.end()) glyph_opt = glyph_item->second; + auto glyph_item = cache->find(unicode); + if (glyph_item != cache->end()) glyph_opt = glyph_item->second; else { if (!font_info_opt.has_value()) { font_info_opt = Privat::load_font_info(font); @@ -513,7 +516,7 @@ Polygons Emboss::text2polygons(const Font & font, font_prop.flatness); // has definition inside of font? if (!glyph_opt.has_value()) continue; - cache[unicode] = *glyph_opt; + cache->operator[](unicode) = *glyph_opt; } // move glyph to cursor position diff --git a/src/libslic3r/Emboss.hpp b/src/libslic3r/Emboss.hpp index 9082ccce0..aa13fe6d6 100644 --- a/src/libslic3r/Emboss.hpp +++ b/src/libslic3r/Emboss.hpp @@ -117,7 +117,7 @@ public: static Polygons text2polygons(const Font & font, const char * text, const FontProp &font_prop, - Glyphs & cache = Glyphs()); + Glyphs * cache = nullptr); /// /// Project 2d point into space diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 91c36c4ed..ae1e390d2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -275,8 +275,8 @@ bool GLGizmoEmboss::gizmo_event(SLAGizmoEventType action, void GLGizmoEmboss::process() { if (!m_font.has_value()) return; - Polygons polygons = Emboss::text2polygons(*m_font, m_text.get(), m_font_prop, m_font_glyph_cache); - if (polygons.empty()) return; + Polygons polygons = Emboss::text2polygons(*m_font, m_text.get(), m_font_prop, &m_font_glyph_cache); + if (polygons.empty()) return; auto project = std::make_unique( std::make_unique(m_emboss/m_scale), m_scale);