From 08c6e4faecda20c3ccabe62c151604a009c96420 Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Fri, 25 Mar 2022 11:06:58 +0100 Subject: [PATCH] Add emboss text test (created mainly to profile conversion) --- src/slic3r/GUI/Jobs/EmbossJob.cpp | 10 +++++----- tests/libslic3r/test_emboss.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 36d920b2a..9bc578c57 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -73,11 +73,10 @@ void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &) GUI_App & app = wxGetApp(); // may be move to input Plater * plater = app.plater(); - ObjectList * obj_list = app.obj_list(); GLCanvas3D * canvas = plater->canvas3D(); - GLGizmosManager &manager = canvas->get_gizmos_manager(); // Check emboss gizmo is still open + GLGizmosManager &manager = canvas->get_gizmos_manager(); if (manager.get_current_type() != GLGizmosManager::Emboss) return; std::string snap_name = GUI::format(_L("Text: %1%"), m_input.text_configuration.text); @@ -110,15 +109,16 @@ void EmbossUpdateJob::finalize(bool canceled, std::exception_ptr &) *selection.get_volume_idxs().begin()); int object_idx = gl_volume->object_idx(); int volume_idx = gl_volume->volume_idx(); + ObjectList *obj_list = app.obj_list(); obj_list->update_name_in_list(object_idx, volume_idx); // update printable state on canvas if (volume->type() == ModelVolumeType::MODEL_PART) - canvas->update_instance_printable_state_for_object( - (size_t) object_idx); + canvas->update_instance_printable_state_for_object((size_t) object_idx); // redraw scene - canvas->reload_scene(true); + bool refresh_immediately = false; + canvas->reload_scene(refresh_immediately); } diff --git a/tests/libslic3r/test_emboss.cpp b/tests/libslic3r/test_emboss.cpp index 88c81d02c..0a3d95bf7 100644 --- a/tests/libslic3r/test_emboss.cpp +++ b/tests/libslic3r/test_emboss.cpp @@ -154,6 +154,33 @@ TEST_CASE("Convert glyph % to model", "[Emboss]") CHECK(!its.indices.empty()); } +TEST_CASE("Convert text with glyph cache to model", "[Emboss]") +{ + std::string font_path = get_font_filepath(); + std::string text = +"Because Ford never learned to say his original name, \n\ +his father eventually died of shame, which is still \r\n\ +a terminal disease in some parts of the Galaxy.\n\r\ +The other kids at school nicknamed him Ix,\n\ +which in the language of Betelgeuse Five translates as\t\n\ +\"boy who is not able satisfactorily to explain what a Hrung is,\n\ +nor why it should choose to collapse on Betelgeuse Seven\"."; + float line_height = 10.f, depth = 2.f; + + auto font = Emboss::create_font_file(font_path.c_str()); + REQUIRE(font != nullptr); + + Emboss::FontFileWithCache ffwc(std::move(font)); + FontProp fp{line_height, depth}; + ExPolygons shapes = Emboss::text2shapes(ffwc, text.c_str(), fp); + REQUIRE(!shapes.empty()); + + Emboss::ProjectZ projection(depth); + indexed_triangle_set its = Emboss::polygons2model(shapes, projection); + CHECK(!its.indices.empty()); + //its_write_obj(its, "C:/data/temp/text.obj"); +} + TEST_CASE("Test hit point", "[AABBTreeIndirect]") { indexed_triangle_set its;