mirror of
				https://github.com/lov3b/Pong.git
				synced 2025-11-04 07:10:16 +01:00 
			
		
		
		
	lookup linux font on runtime
This commit is contained in:
		@@ -3,30 +3,35 @@
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
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)
 | 
			
		||||
    for (const char *font: fonts)
 | 
			
		||||
        if (std::filesystem::exists(font))
 | 
			
		||||
            return font;
 | 
			
		||||
 | 
			
		||||
    return nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char *getDefaultFontPath() {
 | 
			
		||||
#if defined(_WIN32) || defined(_WIN64)
 | 
			
		||||
const char* defaultFontPath = "C:\\Windows\\Fonts\\Arial.ttf";
 | 
			
		||||
    return "C:\\Windows\\Fonts\\Arial.ttf";
 | 
			
		||||
#elif defined(__linux__)
 | 
			
		||||
const char *defaultFontPath = getLinuxFilePath();
 | 
			
		||||
    return getLinuxFilePath();
 | 
			
		||||
#elif defined(__APPLE__) || defined(__MACH__)
 | 
			
		||||
const char *defaultFontPath = "/System/Library/Fonts/Supplemental/Arial.ttf";
 | 
			
		||||
    return "/System/Library/Fonts/Supplemental/Arial.ttf";
 | 
			
		||||
#else
 | 
			
		||||
const char* defaultFontPath = nullptr;
 | 
			
		||||
    return nullptr;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,7 @@ public:
 | 
			
		||||
     */
 | 
			
		||||
    TextScreen(const std::string &text, SDL_Point *screenSize, std::optional<SDL_Point> basePosition) : hasUpdated(
 | 
			
		||||
            false), screenSize(screenSize), basePosition(basePosition) {
 | 
			
		||||
        const char *defaultFontPath = getDefaultFontPath();
 | 
			
		||||
        if (defaultFontPath == nullptr) {
 | 
			
		||||
            std::cerr << "Font path is not set for this platform (null)" << std::endl;
 | 
			
		||||
            exit(-1);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user