add is italic check for font file

This commit is contained in:
Filip Sykala 2022-01-06 11:29:16 +01:00
parent 82ee1c5e4a
commit b1b8eee3c9
4 changed files with 82 additions and 81 deletions

View file

@ -177,4 +177,31 @@ TEST_CASE("triangle intersection", "[]")
Vec2d i = Private::get_intersection(point, dir, triangle);
CHECK(abs(i.x()) < std::numeric_limits<double>::epsilon());
CHECK(abs(i.y() - 1.) < std::numeric_limits<double>::epsilon());
}
#include <string>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
TEST_CASE("Italic check", "[]")
{
//std::string s1 = "italic";
//std::string s2 = "italic";
//auto pos = s1.find(s2);
//std::cout << ((pos != std::string::npos) ? "good" : "bad");
std::string dir_path = "C:/Windows/Fonts";
for (const auto &entry : fs::directory_iterator(dir_path)) {
if (entry.is_directory()) continue;
const fs::path& act_path = entry.path();
std::string ext = act_path.extension().u8string();
std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c) { return std::tolower(c); });
if (ext != ".ttf") continue;
std::string path_str = act_path.u8string();
auto font_opt = Emboss::load_font(path_str.c_str());
if (!font_opt.has_value()) continue;
std::cout << ((Emboss::is_italic(*font_opt)) ? "[yes] " : "[no ] ")
<< entry.path() << std::endl;
}
}