From 249d47c5f7b59c70d990e2530445d3c6cba7aa12 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 24 May 2021 22:13:37 -0400 Subject: initial font stuff --- platform.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 platform.cpp (limited to 'platform.cpp') diff --git a/platform.cpp b/platform.cpp new file mode 100644 index 0000000..179e0ab --- /dev/null +++ b/platform.cpp @@ -0,0 +1,59 @@ +#include "platform.hpp" +#include +#include + +#if defined(_WIN32) && defined(_MSC_VER) + #include + #include + #include + #include + #include + #pragma comment(lib, "Shlwapi.lib") +bool Platform::SetupFonts() { + using namespace std::string_literals; + + char buf[MAX_PATH] { 0 }; + GetCurrentDirectoryA(MAX_PATH, buf); + { + // thanks @WorkingRobot for da help :^)) + + std::ifstream template_stream(buf + "\\fonts\\fonts.template.conf"s); + std::ofstream conf_stream(buf + "\\fonts\\fonts.conf"s); + if (!template_stream.good()) { + printf("can't open fonts/fonts.template.conf\n"); + return false; + } + if (!conf_stream.good()) { + printf("can't open write to fonts.conf\n"); + return false; + } + + std::string line; + while (std::getline(template_stream, line)) { + if (line == "") + conf_stream << "" << (buf + "\\fonts\\conf.d"s) << ""; + else + conf_stream << line; + conf_stream << '\n'; + } + } + + auto fc = FcConfigCreate(); + FcConfigSetCurrent(fc); + FcConfigParseAndLoad(fc, const_cast(reinterpret_cast((buf + "\\fonts\\fonts.conf"s).c_str())), true); + FcConfigAppFontAddDir(fc, const_cast(reinterpret_cast((buf + "\\fonts"s).c_str()))); + + char fonts_path[MAX_PATH]; + if (SHGetFolderPathA(NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, fonts_path) == S_OK) { + FcConfigAppFontAddDir(fc, reinterpret_cast(fonts_path)); + } + + auto map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT); + pango_fc_font_map_set_config(reinterpret_cast(map), fc); + pango_cairo_font_map_set_default(reinterpret_cast(map)); + + return true; +} +#else +bool Platform::SetupFonts() {} +#endif -- cgit v1.2.3