This commit is contained in:
Love 2024-08-03 10:50:29 +02:00
parent 21aeaab088
commit cf7a9a1f1a
3 changed files with 36 additions and 0 deletions

View File

@ -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

31
src/default_font.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "default_font.hpp"
#ifdef __linux__
#include <filesystem>
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
}

3
src/default_font.hpp Normal file
View File

@ -0,0 +1,3 @@
#pragma once
const char *getDefaultFontPath();