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..3f5baa59 100644 --- a/hello_imgui_cmake/hello_imgui_build_lib.cmake +++ b/hello_imgui_cmake/hello_imgui_build_lib.cmake @@ -366,8 +366,8 @@ function(_him_add_freetype_to_imgui) # We have to # - add imgui_freetype.cpp and imgui_freetype.h to imgui # - enable freetype in imgui via IMGUI_ENABLE_FREETYPE - # - enable lunasvg in imgui via IMGUI_ENABLE_FREETYPE_LUNASVG - # - add lunasvg to imgui + # - enable lunasvg or plutosvg in imgui via IMGUI_ENABLE_FREETYPE_LUNASVG or IMGUI_ENABLE_FREETYPE_PLUTOSVG + # - add lunasvg or plutosvg to imgui # - define IMGUI_USE_WCHAR32 in imgui # Note: also change add_imgui.cmake in bundle! @@ -449,31 +449,58 @@ 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) + 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) + + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE IMGUI_ENABLE_FREETYPE_PLUTOSVG) + 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 +509,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");