From 558b40b66e169990ad0265fd75e4b7f91a3da3e9 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Sun, 27 Oct 2024 16:07:57 +0100 Subject: [PATCH] Add option IMGUI_ENABLE_FREETYPE_PLUTOSVG (ON by default) --- CMakeLists.txt | 1 + hello_imgui_cmake/hello_imgui_build_lib.cmake | 77 +++++++++++++------ .../hello_imgui_demodocking.main.cpp | 2 +- 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fbbbdbe..2ac3d700 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ if(ANDROID OR MINGW) endif() # Note: to reduce wasm size, you may want to disable freetype on emscripten. option(HELLOIMGUI_USE_FREETYPE "Use freetype for text rendering" ${freetype_default}) +option(IMGUI_ENABLE_FREETYPE_PLUTOSVG "Enable freetype and plutosvg for text rendering (if OFF, LunaSvg will be used)" ON) #------------------------------------------------------------------------------ # # do not remove this line (used by the script that generates the documentation) diff --git a/hello_imgui_cmake/hello_imgui_build_lib.cmake b/hello_imgui_cmake/hello_imgui_build_lib.cmake index 5ddd9651..a6d5b9a8 100644 --- a/hello_imgui_cmake/hello_imgui_build_lib.cmake +++ b/hello_imgui_cmake/hello_imgui_build_lib.cmake @@ -449,31 +449,59 @@ function(_him_add_freetype_to_imgui) # 2. Build lunasvg (static) # # Fetch and build lunasvg - if(NOT TARGET lunasvg) - # Try using lunasvg unofficial package from vcpkg - find_package(unofficial-lunasvg CONFIG QUIET) - if(unofficial-lunasvg_FOUND) - target_link_libraries(imgui PRIVATE unofficial::lunasvg::lunasvg) - elseif(NOT HELLOIMGUI_FETCH_FORBIDDEN) - set(backup_shared_lib ${BUILD_SHARED_LIBS}) - set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) - include(FetchContent) - FetchContent_Declare(lunasvg - GIT_REPOSITORY https://github.com/sammycage/lunasvg - GIT_TAG v2.3.9 - GIT_PROGRESS TRUE - ) - FetchContent_MakeAvailable(lunasvg) - set(BUILD_SHARED_LIBS ${backup_shared_lib} CACHE BOOL "" FORCE) - target_link_libraries(imgui PUBLIC lunasvg) - get_target_property(lunasvg_include_dirs lunasvg INTERFACE_INCLUDE_DIRECTORIES) - # Patch lunasvg include dir, for installable version (CMake install shenanigans) - set_target_properties(lunasvg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES $) - get_target_property(lunasvg_include_dirs lunasvg INTERFACE_INCLUDE_DIRECTORIES) - - him_add_installable_dependency(lunasvg) - hello_imgui_msvc_target_set_folder(lunasvg ${HELLOIMGUI_SOLUTIONFOLDER}/external) + if (IMGUI_ENABLE_FREETYPE_PLUTOSVG) + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE IMGUI_ENABLE_FREETYPE_PLUTOSVG) + + set(backup_shared_lib ${BUILD_SHARED_LIBS}) + + set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) + include(FetchContent) + FetchContent_Declare(plutovg + GIT_REPOSITORY https://github.com/sammycage/plutovg + GIT_TAG v0.0.8 + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(plutovg) + + set(PLUTOSVG_ENABLE_FREETYPE ON CACHE BOOL "" FORCE) + FetchContent_Declare(plutosvg + GIT_REPOSITORY https://github.com/sammycage/plutosvg + GIT_TAG v0.0.2 + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(plutosvg) + + target_link_libraries(imgui PUBLIC plutosvg) + set(BUILD_SHARED_LIBS ${backup_shared_lib} CACHE BOOL "" FORCE) + + else() # if not IMGUI_ENABLE_FREETYPE_PLUTOSVG -> use lunasvg + if(NOT TARGET lunasvg) + # Try using lunasvg unofficial package from vcpkg + find_package(unofficial-lunasvg CONFIG QUIET) + if(unofficial-lunasvg_FOUND) + target_link_libraries(imgui PRIVATE unofficial::lunasvg::lunasvg) + elseif(NOT HELLOIMGUI_FETCH_FORBIDDEN) + set(backup_shared_lib ${BUILD_SHARED_LIBS}) + set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) + include(FetchContent) + FetchContent_Declare(lunasvg + GIT_REPOSITORY https://github.com/sammycage/lunasvg + GIT_TAG v2.3.9 + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(lunasvg) + set(BUILD_SHARED_LIBS ${backup_shared_lib} CACHE BOOL "" FORCE) + target_link_libraries(imgui PUBLIC lunasvg) + get_target_property(lunasvg_include_dirs lunasvg INTERFACE_INCLUDE_DIRECTORIES) + # Patch lunasvg include dir, for installable version (CMake install shenanigans) + set_target_properties(lunasvg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES $) + get_target_property(lunasvg_include_dirs lunasvg INTERFACE_INCLUDE_DIRECTORIES) + + him_add_installable_dependency(lunasvg) + hello_imgui_msvc_target_set_folder(lunasvg ${HELLOIMGUI_SOLUTIONFOLDER}/external) + endif() endif() + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE IMGUI_ENABLE_FREETYPE_LUNASVG) endif() # @@ -482,7 +510,6 @@ function(_him_add_freetype_to_imgui) target_sources(imgui PRIVATE ${HELLOIMGUI_IMGUI_SOURCE_DIR}/misc/freetype/imgui_freetype.cpp ${HELLOIMGUI_IMGUI_SOURCE_DIR}/misc/freetype/imgui_freetype.h) - target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE IMGUI_ENABLE_FREETYPE_LUNASVG) target_compile_definitions(imgui PUBLIC IMGUI_USE_WCHAR32) endfunction() diff --git a/src/hello_imgui_demos/hello_imgui_demodocking/hello_imgui_demodocking.main.cpp b/src/hello_imgui_demos/hello_imgui_demodocking/hello_imgui_demodocking.main.cpp index dabfc781..24c792b4 100644 --- a/src/hello_imgui_demos/hello_imgui_demodocking/hello_imgui_demodocking.main.cpp +++ b/src/hello_imgui_demos/hello_imgui_demodocking/hello_imgui_demodocking.main.cpp @@ -497,7 +497,7 @@ void DemoFonts(AppState& appState) #ifdef IMGUI_ENABLE_FREETYPE ImGui::Text("Colored Fonts"); ImGui::PushFont(appState.ColorFont->font); - ImGui::Text("C O L O R !"); + ImGui::Text("COLOR!"); ImGui::PopFont(); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Example with Playbox-FREE.otf font");