Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv authored Jul 21, 2024
1 parent c32f007 commit d1d7ecb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion main/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
60 changes: 32 additions & 28 deletions main/gui/source/window/linux_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <string.h>
#include <ranges>

#ifdef USE_FONTCONFIG
#include <fontconfig/fontconfig.h>
#if defined(IMHEX_HAS_FONTCONFIG)
#include <fontconfig/fontconfig.h>
#endif

namespace hex {
Expand Down Expand Up @@ -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<const char *>(fullName), reinterpret_cast<const char *>(file));
}
registerFont(reinterpret_cast<const char *>(fullName), reinterpret_cast<const char *>(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",
Expand Down

0 comments on commit d1d7ecb

Please sign in to comment.