optionally use freetype and plutosvg for color fonts

This commit is contained in:
Green Sky 2025-03-15 00:27:59 +01:00
parent 74f2de81e8
commit 7ef29c9f04
No known key found for this signature in database
GPG Key ID: DBE05085D874AB4A
7 changed files with 96 additions and 1 deletions

View File

@ -17,6 +17,8 @@ add_subdirectory(./solanaceae_toxcore)
add_subdirectory(./solanaceae_tox)
add_subdirectory(./sdl)
add_subdirectory(./freetype)
add_subdirectory(./plutosvg)
add_subdirectory(./imgui)
add_subdirectory(./implot)

29
external/freetype/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
include(FetchContent)
if (NOT TARGET Freetype::Freetype)
find_package(Freetype 2.12 CONFIG GLOBAL QUIET)
if (NOT TARGET Freetype::Freetype)
find_package(Freetype 2.12 GLOBAL QUIET)
endif()
#if (NOT TARGET Freetype::Freetype)
# find_package(PkgConfig)
# if (PKG_CONFIG_FOUND)
# pkg_check_modules(freetype_PKG IMPORTED_TARGET freetype)
# if (TARGET PkgConfig::freetype_PKG)
# add_library(Freetype::Freetype ALIAS PkgConfig::freetype_PKG)
# endif()
# endif()
#endif()
if (TARGET Freetype::Freetype)
message(STATUS "found freetype")
else()
message(STATUS "freetype not found")
endif()
endif()

View File

@ -21,6 +21,22 @@ add_library(imgui
target_compile_definitions(imgui PUBLIC IMGUI_USE_WCHAR32)
target_compile_features(imgui PUBLIC cxx_std_11)
if (TARGET Freetype::Freetype)
message(STATUS "Freetype detected, enabling support in imgui")
target_sources(imgui PUBLIC
imgui/misc/freetype/imgui_freetype.h
imgui/misc/freetype/imgui_freetype.cpp
)
target_link_libraries(imgui PUBLIC Freetype::Freetype) # public in case of static
target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE)
if (TARGET plutosvg::plutosvg)
message(STATUS "plutosvg detected, enabling support in imgui")
target_link_libraries(imgui PUBLIC plutosvg::plutosvg) # public in case of static
target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE_PLUTOSVG)
endif()
endif()
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(imgui PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/imgui") # im sad

16
external/plutosvg/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
include(FetchContent)
#makes no sense without freetype
if (NOT TARGET plutosvg::plutosvg AND TARGET Freetype::Freetype)
set(PLUTOSVG_ENABLE_FREETYPE ON CACHE INTERNAL "")
set(PLUTOSVG_BUILD_EXAMPLES OFF CACHE INTERNAL "")
FetchContent_Declare(plutosvg
GIT_REPOSITORY https://github.com/sammycage/plutosvg.git
GIT_TAG v0.0.6
FIND_PACKAGE_ARGS # for the future
)
FetchContent_MakeAvailable(plutosvg)
endif()

20
flake.lock generated
View File

@ -68,12 +68,32 @@
"type": "github"
}
},
"plutosvg": {
"flake": false,
"locked": {
"lastModified": 1740306654,
"narHash": "sha256-radjL0bP+JPDk7FQ/qSOIxlokhwQ78fO52/S5V6rAmk=",
"ref": "refs/tags/v0.0.6",
"rev": "c5388fa96feca1f1376a3d0485d5e35159452707",
"revCount": 111,
"submodules": true,
"type": "git",
"url": "https://github.com/sammycage/plutosvg"
},
"original": {
"ref": "refs/tags/v0.0.6",
"submodules": true,
"type": "git",
"url": "https://github.com/sammycage/plutosvg"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"implot": "implot",
"nixpkgs": "nixpkgs",
"nlohmann-json": "nlohmann-json",
"plutosvg": "plutosvg",
"sdl3": "sdl3",
"sdl3_image": "sdl3_image"
}

View File

@ -20,13 +20,17 @@
url = "github:libsdl-org/SDL_image/4ff27afa450eabd2a827e49ed86fab9e3bf826c5";
flake = false;
};
plutosvg = {
url = "git+https://github.com/sammycage/plutosvg?submodules=1&ref=refs/tags/v0.0.6";
flake = false;
};
implot = {
url = "github:epezent/implot/193b9d8f92c4a437e84182b171f1ae266e72321f";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, nlohmann-json, sdl3, sdl3_image, implot }:
outputs = { self, nixpkgs, flake-utils, nlohmann-json, sdl3, sdl3_image, plutosvg, implot }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
@ -85,6 +89,8 @@
libsodium
libopus
libvpx
freetype
] ++ self.packages.${system}.default.dlopenBuildInputs;
cmakeFlags = [
@ -102,6 +108,7 @@
"-DFETCHCONTENT_SOURCE_DIR_SDL3=${sdl3}"
"-DFETCHCONTENT_SOURCE_DIR_SDL3_IMAGE=${sdl3_image}"
"-DSDLIMAGE_JXL=ON"
"-DFETCHCONTENT_SOURCE_DIR_PLUTOSVG=${plutosvg}" # not in pkgs
"-DFETCHCONTENT_SOURCE_DIR_IMPLOT=${implot}" # could use pkgs.implot.src for outdated version
];

View File

@ -7,6 +7,7 @@
#include <nlohmann/json.hpp>
#include <imgui/imgui.h>
#include <imgui/misc/freetype/imgui_freetype.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <cctype>
@ -105,6 +106,10 @@ StartScreen::StartScreen(const std::vector<std::string_view>& args, SDL_Renderer
fontcfg.OversampleH = 2;
fontcfg.OversampleV = 1;
fontcfg.MergeMode = false;
#if defined(IMGUI_ENABLE_FREETYPE) && defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG)
std::cout << "Font: enabling freetype color loading\n";
fontcfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;
#endif
for (const auto [font_path, should_load] : _conf.entries_bool("ImGuiFonts", "fonts")) {
if (!should_load) {