From d1d7ecbae75532f294b205fca2a9b719f3d8f6c4 Mon Sep 17 00:00:00 2001 From: Nik Date: Sun, 21 Jul 2024 20:22:42 +0200 Subject: [PATCH] Style fixes --- main/gui/CMakeLists.txt | 2 +- main/gui/source/window/linux_window.cpp | 60 +++++++++++++------------ 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/main/gui/CMakeLists.txt b/main/gui/CMakeLists.txt index 8effe48a32d9e..d2f8a835f3eb0 100644 --- a/main/gui/CMakeLists.txt +++ b/main/gui/CMakeLists.txt @@ -69,7 +69,7 @@ else () if (TARGET Fontconfig::Fontconfig) message(STATUS "Using Fontconfig version: ${Fontconfig_VERSION}") target_link_libraries(main PRIVATE Fontconfig::Fontconfig) - target_compile_definitions(main PRIVATE USE_FONTCONFIG) + target_compile_definitions(main PRIVATE IMHEX_HAS_FONTCONFIG) endif () endif () endif () diff --git a/main/gui/source/window/linux_window.cpp b/main/gui/source/window/linux_window.cpp index 5d30e3d3ca0e1..d28326062b10e 100644 --- a/main/gui/source/window/linux_window.cpp +++ b/main/gui/source/window/linux_window.cpp @@ -22,8 +22,8 @@ #include #include - #ifdef USE_FONTCONFIG - #include + #if defined(IMHEX_HAS_FONTCONFIG) + #include #endif namespace hex { @@ -52,38 +52,42 @@ namespace hex { } // Hopefully one of these commands is installed } -#ifdef USE_FONTCONFIG - static bool enumerateFontConfig() { - if (!FcInit()) - return false; + #if defined(IMHEX_HAS_FONTCONFIG) + static bool enumerateFontConfig() { + if (!FcInit()) + return false; - auto fonts = FcConfigGetFonts(nullptr, FcSetSystem); - if (!fonts) - return false; + ON_SCOPE_EXIT { FcFini(); }; - for (auto i = 0; i < fonts->nfont; ++i) { - auto font = fonts->fonts[i]; - FcChar8 *file, *fullName; - if (FcPatternGetString(font, FC_FILE, 0, &file) != FcResultMatch) { - continue; - } - if (FcPatternGetString(font, FC_FULLNAME, 0, &fullName) != FcResultMatch - && FcPatternGetString(font, FC_FAMILY, 0, &fullName) != FcResultMatch) { - continue; + auto fonts = FcConfigGetFonts(nullptr, FcSetSystem); + if (fonts == nullptr) + return false; + + for (u32 i = 0; i < fonts->nfont; ++i) { + auto font = fonts->fonts[i]; + FcChar8 *file, *fullName; + + if (FcPatternGetString(font, FC_FILE, 0, &file) != FcResultMatch) { + continue; + } + + if (FcPatternGetString(font, FC_FULLNAME, 0, &fullName) != FcResultMatch + && FcPatternGetString(font, FC_FAMILY, 0, &fullName) != FcResultMatch) { + continue; + } + + registerFont(reinterpret_cast(fullName), reinterpret_cast(file)); } - registerFont(reinterpret_cast(fullName), reinterpret_cast(file)); - } - FcFini(); - return true; - } -#endif + return true; + } + #endif void enumerateFonts() { -#ifdef USE_FONTCONFIG - if (enumerateFontConfig()) - return; -#endif + #if defined(IMHEX_HAS_FONTCONFIG) + if (enumerateFontConfig()) + return; + #endif const std::array FontDirectories = { "/usr/share/fonts",