Skip to content

Commit

Permalink
Add option IMGUI_ENABLE_FREETYPE_PLUTOSVG (ON by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Oct 27, 2024
1 parent fdcf514 commit 558b40b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#------------------------------------------------------------------------------
# <Dependencies> # do not remove this line (used by the script that generates the documentation)
Expand Down
77 changes: 52 additions & 25 deletions hello_imgui_cmake/hello_imgui_build_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/_deps/lunasvg-src/include>)
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 $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/_deps/lunasvg-src/include>)
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()

#
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 558b40b

Please sign in to comment.