Skip to content

Commit

Permalink
plutosvg / manual
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Oct 28, 2024
1 parent 2f8f8d7 commit b541fab
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 78 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#------------------------------------------------------------------------------
# <Dependencies> # do not remove this line (used by the script that generates the documentation)
Expand Down Expand Up @@ -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.
#
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs_src/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
115 changes: 45 additions & 70 deletions hello_imgui_cmake/hello_imgui_build_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -436,85 +439,57 @@ function(_him_add_freetype_to_imgui)
endif()

target_link_libraries(imgui PUBLIC ${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)
set(HELLOIMGUI_FREETYPE_SELECTED_INFO "Downloaded VER-2-13-2" CACHE INTERNAL "" FORCE)
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 $<BUILD_INTERFACE:${plutosvg_SOURCE_DIR}/source>)
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 $<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)
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 $<BUILD_INTERFACE:${plutosvg_SOURCE_DIR}/source>)
target_compile_definitions(plutosvg PUBLIC PLUTOSVG_HAS_FREETYPE)
target_link_libraries(plutosvg PUBLIC ${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()


Expand Down

0 comments on commit b541fab

Please sign in to comment.