diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 1f8788327..ef357c4ff 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -651,9 +651,10 @@ std::optional Emboss::letter2glyph(const FontFile &font, return Private::get_glyph(*font_info_opt, letter, flatness); } -ExPolygons Emboss::text2shapes(FontFileWithCache &font_with_cache, - const char * text, - const FontProp &font_prop) +ExPolygons Emboss::text2shapes(FontFileWithCache &font_with_cache, + const char *text, + const FontProp &font_prop, + std::function was_canceled) { assert(font_with_cache.has_value()); std::optional font_info_opt; @@ -688,7 +689,11 @@ ExPolygons Emboss::text2shapes(FontFileWithCache &font_with_cache, if (wc == '\r') continue; int unicode = static_cast(wc); - const Glyph* glyph_ptr = Private::get_glyph(unicode, font, font_prop, cache, font_info_opt); + // check cancelation only before unknown symbol - loading of symbol could be timeconsuming on slow computer and dificult fonts + auto it = cache.find(unicode); + if (it == cache.end() && was_canceled != nullptr && was_canceled()) return {}; + const Glyph *glyph_ptr = (it != cache.end())? &it->second : + Private::get_glyph(unicode, font, font_prop, cache, font_info_opt); if (glyph_ptr == nullptr) continue; // move glyph to cursor position diff --git a/src/libslic3r/Emboss.hpp b/src/libslic3r/Emboss.hpp index e11dfb7a7..9747186a3 100644 --- a/src/libslic3r/Emboss.hpp +++ b/src/libslic3r/Emboss.hpp @@ -152,8 +152,9 @@ public: /// Define fonts + cache, which could extend /// Characters to convert /// User defined property of the font + /// Way to interupt processing /// Inner polygon cw(outer ccw) - static ExPolygons text2shapes(FontFileWithCache &font, const char *text, const FontProp &font_prop); + static ExPolygons text2shapes(FontFileWithCache &font, const char *text, const FontProp &font_prop, std::function was_canceled = nullptr); /// /// Fix intersections and self intersections in polygons glyph shape diff --git a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp index 98dc3121a..94879f6cc 100644 --- a/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp +++ b/src/slic3r/GUI/Jobs/CreateFontNameImageJob.cpp @@ -45,8 +45,8 @@ void CreateFontImageJob::process(Ctl &ctl) text = text.substr(0, enter_pos); } - ExPolygons shapes = Emboss::text2shapes(font_file_with_cache, - text.c_str(), fp); + std::function was_canceled = [&ctl]() -> bool { return ctl.was_canceled(); }; + ExPolygons shapes = Emboss::text2shapes(font_file_with_cache, text.c_str(), fp, was_canceled); // normalize height of font BoundingBox bounding_box; for (ExPolygon &shape : shapes) diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index c05c2357d..17d90f98e 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -521,7 +521,7 @@ TriangleMesh priv::try_create_mesh(const EmbossDataBase &input, Emboss::FontFile assert(font.has_value()); if (!font.has_value()) return {}; - ExPolygons shapes = Emboss::text2shapes(font, text, prop); + ExPolygons shapes = Emboss::text2shapes(font, text, prop, was_canceled); if (shapes.empty()) return {}; if (was_canceled()) return {};