From ca79932d3038e9d373e74e246a4f2a181ed5f3a1 Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Wed, 23 Feb 2022 13:55:27 +0100 Subject: [PATCH] Reduce test to use only STB calls --- tests/libslic3r/test_emboss.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/libslic3r/test_emboss.cpp b/tests/libslic3r/test_emboss.cpp index 536f3b043..7f7045ffe 100644 --- a/tests/libslic3r/test_emboss.cpp +++ b/tests/libslic3r/test_emboss.cpp @@ -94,20 +94,33 @@ Vec3d calc_hit_point(const igl::Hit &h, indexed_triangle_set &its) } } // namespace Private +#include "imgui/imstb_truetype.h" TEST_CASE("Emboss text - Times MacOs", "[Emboss]") { std::string font_path = "C:/Users/filip/Downloads/Times.ttc"; + //std::string font_path = "//System/Library/Fonts/Times.ttc"; char letter = 'C'; float flatness = 2.; - - auto font = Emboss::load_font(font_path.c_str()); - REQUIRE(font != nullptr); - - std::optional glyph = Emboss::letter2glyph(*font, letter, flatness); - REQUIRE(glyph.has_value()); - - ExPolygons shape = glyph->shape; - REQUIRE(!shape.empty()); + FILE *file = fopen(font_path.c_str(), "rb"); + REQUIRE(file != nullptr); + // find size of file + REQUIRE(fseek(file, 0L, SEEK_END) == 0); + size_t size = ftell(file); + REQUIRE(size != 0); + rewind(file); + std::vector buffer(size); + size_t count_loaded_bytes = fread((void *) &buffer.front(), 1, size, file); + REQUIRE(count_loaded_bytes == size); + int font_offset = stbtt_GetFontOffsetForIndex(buffer.data(), 0); + REQUIRE(font_offset >= 0); + stbtt_fontinfo font_info; + REQUIRE(stbtt_InitFont(&font_info, buffer.data(), font_offset) != 0); + int unicode_letter = (int) letter; + int glyph_index = stbtt_FindGlyphIndex(&font_info, unicode_letter); + REQUIRE(glyph_index != 0); + stbtt_vertex *vertices; + int num_verts = stbtt_GetGlyphShape(&font_info, glyph_index, &vertices); + CHECK(num_verts > 0); } #include