diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ac3d700..6693e255 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,7 +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) +option(HELLOIMGUI_USE_FREETYPE_PLUTOSVG "Use plutosvg to load svg fonts" ON) #------------------------------------------------------------------------------ # # do not remove this line (used by the script that generates the documentation) @@ -257,7 +257,7 @@ mark_as_advanced(HELLO_IMGUI_IMGUI_SHARED) # ----------------------------------------------------------------------------- # By default, hello_imgui will download and build the required libraries automatically, # if they cannot be found via cmake's find_package: -# glfw3, lunasvg, freetype +# glfw3, plutosvg, freetype # To build offline, you can for example pre-install the required libraries with vcpkg, # but you can also install them via a system package manager, or add them manually as targets. # @@ -268,13 +268,13 @@ mark_as_advanced(HELLO_IMGUI_IMGUI_SHARED) # # git clone https://github.com/microsoft/vcpkg # ./vcpkg/bootstrap-vcpkg.sh -# ./vcpkg/vcpkg install glfw3 freetype lunasvg +# ./vcpkg/vcpkg install glfw3 freetype # export CMAKE_TOOLCHAIN_FILE=$(pwd)/vcpkg/scripts/buildsystems/vcpkg.cmake # mkdir build && cd build # cmake .. # # Note: under windows, you could specify a static triplet (x64-windows-static): -# ./vcpkg/vcpkg install freetype:x64-windows-static glfw3:x64-windows-static lunasvg:x64-windows-static +# ./vcpkg/vcpkg install freetype:x64-windows-static glfw3:x64-windows-static # # ----------------------------------------------------------------------------- # How to use ImGui package from vcpkg (*not* recommended) @@ -288,9 +288,9 @@ mark_as_advanced(HELLO_IMGUI_IMGUI_SHARED) # # git clone https://github.com/microsoft/vcpkg # ./vcpkg/bootstrap-vcpkg.sh -# ./vcpkg/vcpkg install glfw3 freetype lunasvg +# ./vcpkg/vcpkg install glfw3 freetype # # install imgui from vcpkg, with the correct options -# ./vcpkg/vcpkg install "imgui[docking-experimental,freetype-lunasvg,glfw-binding,opengl3-binding]" +# ./vcpkg/vcpkg install "imgui[docking-experimental,glfw-binding,opengl3-binding]" # # export CMAKE_TOOLCHAIN_FILE=$(pwd)/vcpkg/scripts/buildsystems/vcpkg.cmake # mkdir build && cd build diff --git a/README.md b/README.md index a838003d..4a209da4 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ How to use the theme tweaking utilities provided by Hello ImGui Hello ImGui is based on [Dear ImGui](https://github.com/ocornut/imgui) (MIT License), by Omar Cornut. Portions use [ImGui Test Engine](https://github.com/ocornut/imgui_test_engine), which is governed by a [specific license](https://github.com/ocornut/imgui_test_engine/blob/main/imgui_test_engine/LICENSE.txt) -Portions of this software use the [FreeType Project](https://www.freetype.org), [lunasvg](https://github.com/sammycage/lunasvg) (MIT License), [GLFW](https://www.glfw.org/) (zlib/libpng license), [SDL](https://www.libsdl.org/) (zlib license). +Portions of this software use the [FreeType Project](https://www.freetype.org), [plutosvg](https://github.com/sammycage/plutosvg) (MIT License), [GLFW](https://www.glfw.org/) (zlib/libpng license), [SDL](https://www.libsdl.org/) (zlib license). ### License diff --git a/docs_src/intro.md b/docs_src/intro.md index ec9e0473..7ba86079 100644 --- a/docs_src/intro.md +++ b/docs_src/intro.md @@ -113,7 +113,7 @@ How to use the theme tweaking utilities provided by Hello ImGui Hello ImGui is based on [Dear ImGui](https://github.com/ocornut/imgui) (MIT License), by Omar Cornut. Portions use [ImGui Test Engine](https://github.com/ocornut/imgui_test_engine), which is governed by a [specific license](https://github.com/ocornut/imgui_test_engine/blob/main/imgui_test_engine/LICENSE.txt) -Portions of this software use the [FreeType Project](https://www.freetype.org), [lunasvg](https://github.com/sammycage/lunasvg) (MIT License), [GLFW](https://www.glfw.org/) (zlib/libpng license), [SDL](https://www.libsdl.org/) (zlib license). +Portions of this software use the [FreeType Project](https://www.freetype.org), [plutosvg](https://github.com/sammycage/plutosvg) (MIT License), [GLFW](https://www.glfw.org/) (zlib/libpng license), [SDL](https://www.libsdl.org/) (zlib license). ### License diff --git a/hello_imgui_cmake/hello_imgui_build_lib.cmake b/hello_imgui_cmake/hello_imgui_build_lib.cmake index d10f4f25..6863191b 100644 --- a/hello_imgui_cmake/hello_imgui_build_lib.cmake +++ b/hello_imgui_cmake/hello_imgui_build_lib.cmake @@ -279,6 +279,9 @@ function(him_build_imgui) if (HELLOIMGUI_USE_FREETYPE) _him_add_freetype_to_imgui() endif() + if (HELLOIMGUI_USE_FREETYPE_PLUTOSVG) + _him_add_freetype_plutosvg_to_imgui() + endif() endif() endfunction() @@ -359,15 +362,15 @@ function(_him_do_build_imgui) endfunction() function(_him_add_freetype_to_imgui) - # Add freetype + lunasvg to imgui + # Add freetype + plutosvg to imgui # This is especially useful to support emojis (possibly colored) in imgui # See doc: # https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#using-colorful-glyphsemojis # We have to # - add imgui_freetype.cpp and imgui_freetype.h to imgui # - enable freetype in imgui via IMGUI_ENABLE_FREETYPE - # - enable lunasvg or plutosvg in imgui via IMGUI_ENABLE_FREETYPE_LUNASVG or IMGUI_ENABLE_FREETYPE_PLUTOSVG - # - add lunasvg or plutosvg to imgui + # - enable plutosvg in imgui via IMGUI_ENABLE_FREETYPE_PLUTOSVG + # - add plutosvg + plutovg to imgui # - define IMGUI_USE_WCHAR32 in imgui # Note: also change add_imgui.cmake in bundle! @@ -377,7 +380,7 @@ function(_him_add_freetype_to_imgui) # if(TARGET freetype) message(STATUS "HelloImGui: using freetype target") - set(freetype_linked_library freetype) + set(HIM_FREETYPE_LINKED_LIBRARY freetype CACHE STRING "" FORCE) else() set(download_freetype OFF) if (HELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED AND NOT HELLOIMGUI_FETCH_FORBIDDEN) @@ -417,7 +420,7 @@ function(_him_add_freetype_to_imgui) GIT_PROGRESS TRUE ) FetchContent_MakeAvailable(freetype) - set(freetype_linked_library freetype) + set(HIM_FREETYPE_LINKED_LIBRARY freetype CACHE STRING "" FORCE) hello_imgui_msvc_target_set_folder(freetype ${HELLOIMGUI_SOLUTIONFOLDER}/external) set(BUILD_SHARED_LIBS ${backup_shared_lib} CACHE BOOL "" FORCE) @@ -431,12 +434,20 @@ function(_him_add_freetype_to_imgui) ") endif() find_package(Freetype 2.12 REQUIRED) - set(freetype_linked_library Freetype::Freetype) + set(HIM_FREETYPE_LINKED_LIBRARY Freetype::Freetype CACHE STRING "" FORCE) endif() endif() - target_link_libraries(imgui PUBLIC ${freetype_linked_library}) + target_link_libraries(imgui PUBLIC ${HIM_FREETYPE_LINKED_LIBRARY}) + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE) + + # 2. Add support for wchar32 (for emojis, and other unicode characters) + 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_USE_WCHAR32) + # 3. Prepare Log info if(TARGET freetype) set(HELLOIMGUI_FREETYPE_SELECTED_INFO "Use target freetype" CACHE INTERNAL "" FORCE) elseif(download_freetype) @@ -444,77 +455,41 @@ function(_him_add_freetype_to_imgui) else() set(HELLOIMGUI_FREETYPE_SELECTED_INFO "Use system Library" CACHE INTERNAL "" FORCE) endif() +endfunction() - # - # 2. Build lunasvg (static) - # - # Fetch and build lunasvg - if (IMGUI_ENABLE_FREETYPE_PLUTOSVG) - set(backup_shared_lib ${BUILD_SHARED_LIBS}) - - include(FetchContent) - # Fetch plutovg & MakeAvailable - FetchContent_Declare(plutovg - GIT_REPOSITORY https://github.com/sammycage/plutovg - GIT_TAG v0.0.8 - GIT_PROGRESS TRUE - ) - FetchContent_MakeAvailable(plutovg) - - # Fetch plutosvg and compile manually (the stock CMakeLists of plutosvg is not compatible with a custom install of freetype) - FetchContent_Declare( - plutosvg - GIT_REPOSITORY https://github.com/sammycage/plutosvg - GIT_TAG v0.0.2 - GIT_PROGRESS TRUE - ) - FetchContent_GetProperties(plutosvg) - add_library(plutosvg ${plutosvg_SOURCE_DIR}/source/plutosvg.c) - target_include_directories(plutosvg PUBLIC $) - target_compile_definitions(plutosvg PUBLIC PLUTOSVG_HAS_FREETYPE) - target_link_libraries(plutosvg PUBLIC ${freetype_linked_library} plutovg) - him_add_installable_dependency(plutosvg) - - target_link_libraries(imgui PUBLIC plutosvg) - 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) +function(_him_add_freetype_plutosvg_to_imgui) + if (HELLOIMGUI_FETCH_FORBIDDEN OR NOT HELLOIMGUI_DOWNLOAD_FREETYPE_IF_NEEDED) + message(WARNING "Cannot add plutosvg because fetching is forbidden") + return() endif() + # Fetch & build plutovg at configure time + include(FetchContent) + FetchContent_Declare(plutovg + GIT_REPOSITORY https://github.com/sammycage/plutovg + GIT_TAG v0.0.8 + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(plutovg) + + # Fetch plutosvg at configure time, then compile manually at build time + # (the stock CMakeLists of plutosvg is not compatible with a custom install of freetype) + FetchContent_Populate( + plutosvg + GIT_REPOSITORY https://github.com/sammycage/plutosvg + GIT_TAG v0.0.2 + ) + add_library(plutosvg ${plutosvg_SOURCE_DIR}/source/plutosvg.c) + target_include_directories(plutosvg PUBLIC $) + target_compile_definitions(plutosvg PUBLIC PLUTOSVG_HAS_FREETYPE) + target_link_libraries(plutosvg PUBLIC ${HIM_FREETYPE_LINKED_LIBRARY} plutovg) + him_add_installable_dependency(plutosvg) - # - # 3. Add freetype and LunaSvg support to imgui - # with support for wchar32 (for emojis, and other unicode characters) - 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_USE_WCHAR32) + target_link_libraries(imgui PUBLIC plutosvg) + target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE_PLUTOSVG) + + # Prepare Log info + set(HELLOIMGUI_FREETYPE_SELECTED_INFO "${HELLOIMGUI_FREETYPE_SELECTED_INFO} - downloaded plutosvg" CACHE INTERNAL "" FORCE) endfunction()