Skip to content

Canvas Freetype #1514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: CanvasTest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ FetchContent_Declare(OpenXR-SDK
FetchContent_Declare(SPIRV-Cross
GIT_REPOSITORY https://github.com/BabylonJS/SPIRV-Cross.git
GIT_TAG 578a291759db6fe7c3f4735d3512c0526ad18efc)
FetchContent_Declare(FreeType
GIT_REPOSITORY https://github.com/freetype/freetype.git
GIT_TAG 2d1abd3bbb4d2396ed63b3e5accd66724cf62307)
# --------------------------------------------------

FetchContent_MakeAvailable(CMakeExtensions)
Expand Down
11 changes: 10 additions & 1 deletion Polyfills/Canvas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,21 @@ set(SOURCES

file(GLOB SHADERS "Source/Shaders/*.sc" "Source/Shaders/*.sh")

option(BABYLON_NATIVE_CANVAS_FREETYPE "Use Freetype2 instead of stb_ttf" OFF)

add_library(Canvas ${SOURCES} ${SHADERS})

target_include_directories(Canvas
PUBLIC "Include"
PRIVATE "Source"
PRIVATE "${BGFX_DIR}/3rdparty")

if(BABYLON_NATIVE_CANVAS_FREETYPE)
target_compile_definitions(Canvas PRIVATE FONS_USE_FREETYPE)
set(EXTERNAL_FONT_LIBRARY freetype)
FetchContent_MakeAvailable_With_Message(FreeType)
endif()

target_link_libraries(Canvas
PUBLIC napi
PRIVATE bgfx
Expand All @@ -138,7 +146,8 @@ target_link_libraries(Canvas
PRIVATE JsRuntimeInternal
PRIVATE GraphicsDeviceContext
PRIVATE UrlLib
PRIVATE base-n)
PRIVATE base-n
PRIVATE ${EXTERNAL_FONT_LIBRARY})

if(BGFX_BUILD_TOOLS AND BGFX_BUILD_TOOLS_SHADER)
if(NOT IOS AND NOT VISIONOS AND NOT ANDROID)
Expand Down
2 changes: 2 additions & 0 deletions Polyfills/Canvas/Source/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#pragma GCC diagnostic pop
#endif

#ifndef FONS_USE_FREETYPE
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb/stb_truetype.h"
#undef STB_TRUETYPE_IMPLEMENTATION
#endif

#include "Canvas.h"
#include "Context.h"
Expand Down