From b7682107971d1cc0648bbfbe40556402bf714cdf Mon Sep 17 00:00:00 2001 From: Hoe Hao Cheng Date: Thu, 3 Aug 2023 22:02:24 +0800 Subject: [PATCH] ci: use pkgconfig as a fallback for finding SDL2_ttf --- .github/workflows/build.yml | 2 +- CMakeLists.txt | 18 +++++++++++++++--- Common/Render/Text/draw_text_sdl.cpp | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f250d9bd3a..76718c975d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -331,7 +331,7 @@ jobs: run: | sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse" sudo apt-get update -y -qq - sudo apt-get install libsdl2-dev libgl1-mesa-dev libglu1-mesa-dev + sudo apt-get install libsdl2-dev libgl1-mesa-dev libglu1-mesa-dev libsdl2-ttf-dev libfontconfig1-dev - name: Install macOS dependencies if: runner.os == 'macOS' diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d6033eada..ed3904de81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,6 +259,14 @@ if(NOT LIBRETRO AND NOT IOS AND NOT MACOSX) find_package(SDL2) find_package(SDL2_ttf) find_package(Fontconfig) + + # TODO: this can be removed once CI supports newer SDL2_ttf + if (NOT SDL2_ttf_FOUND) + find_package(PkgConfig) + if(PkgConfig_FOUND) + pkg_check_modules(SDL2_ttf_PKGCONFIG IMPORTED_TARGET SDL2_ttf) + endif() + endif() endif() if(MACOSX AND NOT IOS) @@ -1315,15 +1323,19 @@ else() SDL/SDLVulkanGraphicsContext.cpp ) endif() - if(SDL2_ttf_FOUND) + if(SDL2_ttf_FOUND OR SDL2_ttf_PKGCONFIG_FOUND) add_definitions(-DUSE_SDL2_TTF) - set(nativeExtraLibs ${nativeExtraLibs} SDL2_ttf::SDL2_ttf) - if(FONTCONFIG_FOUND) add_definitions(-DUSE_SDL2_TTF_FONTCONFIG) set(nativeExtraLibs ${nativeExtraLibs} Fontconfig::Fontconfig) endif() endif() + if(SDL2_ttf_FOUND) + set(nativeExtraLibs ${nativeExtraLibs} SDL2_ttf::SDL2_ttf) + elseif(SDL2_ttf_PKGCONFIG_FOUND) + add_definitions(-DUSE_SDL2_TTF_PKGCONFIG) + set(nativeExtraLibs ${nativeExtraLibs} PkgConfig::SDL2_ttf_PKGCONFIG) + endif() if(APPLE) set(nativeExtra ${nativeExtra} SDL/SDLMain.h diff --git a/Common/Render/Text/draw_text_sdl.cpp b/Common/Render/Text/draw_text_sdl.cpp index df32f9fb6c..272e3a0ab9 100644 --- a/Common/Render/Text/draw_text_sdl.cpp +++ b/Common/Render/Text/draw_text_sdl.cpp @@ -374,12 +374,14 @@ void TextDrawerSDL::DrawStringBitmap(std::vector &bitmapData, TextStrin font = fallbackFonts_[0]; } +#ifndef USE_SDL2_TTF_PKGCONFIG if (align & ALIGN_HCENTER) TTF_SetFontWrappedAlign(font, TTF_WRAPPED_ALIGN_CENTER); else if (align & ALIGN_RIGHT) TTF_SetFontWrappedAlign(font, TTF_WRAPPED_ALIGN_RIGHT); else TTF_SetFontWrappedAlign(font, TTF_WRAPPED_ALIGN_LEFT); +#endif SDL_Color fgColor = { 0xFF, 0xFF, 0xFF, 0xFF }; SDL_Surface *text = TTF_RenderUTF8_Blended_Wrapped(font, processedStr.c_str(), fgColor, 0);