From cf7a9a1f1a8ee608acefee03c09489b975b0ce94 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Sat, 3 Aug 2024 10:50:29 +0200 Subject: [PATCH] font --- CMakeLists.txt | 2 ++ src/default_font.cpp | 31 +++++++++++++++++++++++++++++++ src/default_font.hpp | 3 +++ 3 files changed, 36 insertions(+) create mode 100644 src/default_font.cpp create mode 100644 src/default_font.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b08d61..3f33e0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ add_executable(hang_man src/main.cpp src/utils.hpp src/GuessCorrector.cpp src/GuessCorrector.hpp + src/default_font.cpp + src/default_font.hpp ) target_link_libraries(hang_man PRIVATE diff --git a/src/default_font.cpp b/src/default_font.cpp new file mode 100644 index 0000000..14a9e80 --- /dev/null +++ b/src/default_font.cpp @@ -0,0 +1,31 @@ +#include "default_font.hpp" + +#ifdef __linux__ +#include + +constexpr const char *getLinuxFilePath() { + const char *fonts[] = {"/usr/share/fonts/truetype/DejaVuSans-Bold.ttf", // openSUSE + "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", // Debian + "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", // Arch + "/usr/share/fonts/dejavu-sans-fonts/DejaVuSans-Bold.ttf", // Fedora + }; + for (const char *font: fonts) + if (std::filesystem::exists(font)) + return font; + + return nullptr; +} +#endif + + +const char *getDefaultFontPath() { +#if defined(_WIN32) || defined(_WIN64) + return R"(C:\Windows\Fonts\Arial.ttf)"; +#elifdef __linux__ + return getLinuxFilePath(); +#elif defined(__APPLE__) || defined(__MACH__) + return "/System/Library/Fonts/Supplemental/Arial.ttf"; +#else + return nullptr; +#endif +} diff --git a/src/default_font.hpp b/src/default_font.hpp new file mode 100644 index 0000000..7944cca --- /dev/null +++ b/src/default_font.hpp @@ -0,0 +1,3 @@ +#pragma once + +const char *getDefaultFontPath(); \ No newline at end of file