Reduce test to use only STB calls

This commit is contained in:
Filip Sykala 2022-02-23 13:55:27 +01:00
parent 482e510d7f
commit ca79932d30

View File

@ -94,20 +94,33 @@ Vec3d calc_hit_point(const igl::Hit &h, indexed_triangle_set &its)
} }
} // namespace Private } // namespace Private
#include "imgui/imstb_truetype.h"
TEST_CASE("Emboss text - Times MacOs", "[Emboss]") { TEST_CASE("Emboss text - Times MacOs", "[Emboss]") {
std::string font_path = "C:/Users/filip/Downloads/Times.ttc"; std::string font_path = "C:/Users/filip/Downloads/Times.ttc";
//std::string font_path = "//System/Library/Fonts/Times.ttc";
char letter = 'C'; char letter = 'C';
float flatness = 2.; float flatness = 2.;
FILE *file = fopen(font_path.c_str(), "rb");
auto font = Emboss::load_font(font_path.c_str()); REQUIRE(file != nullptr);
REQUIRE(font != nullptr); // find size of file
REQUIRE(fseek(file, 0L, SEEK_END) == 0);
std::optional<Emboss::Glyph> glyph = Emboss::letter2glyph(*font, letter, flatness); size_t size = ftell(file);
REQUIRE(glyph.has_value()); REQUIRE(size != 0);
rewind(file);
ExPolygons shape = glyph->shape; std::vector<unsigned char> buffer(size);
REQUIRE(!shape.empty()); 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 <libslic3r/Utils.hpp> #include <libslic3r/Utils.hpp>