feat: Add TrueType font rendering with new graphics (#1595)

Co-authored-by: LIBERGOD <37589902+libergod@users.noreply.github.com>
This commit is contained in:
Sherrat 2026-01-25 07:20:40 -03:00 committed by GitHub
parent 26e21018ee
commit 95e6240a94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
118 changed files with 1333 additions and 95 deletions

2
.gitignore vendored
View file

@ -58,6 +58,8 @@ vc17/
*.exp
*.lib
*.bak
*.code-workspace
# Protobuf generated files
*.pb.cc

View file

@ -70,9 +70,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten"
OR _OTCLIENT_EMSCRIPTEN_COMPILER
OR WASM)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
# Add threading and atomics support for WebAssembly builds
# This fixes linker issues with --shared-memory flag when using pthreads
# Using add_compile_options ensures flags are applied to all targets including dependencies
add_compile_options(-pthread -matomics -mbulk-memory)
add_link_options(-pthread -matomics -mbulk-memory)
endif()
# *****************************************************************************

View file

@ -34,7 +34,7 @@ ENV VCPKG_ROOT=/opt/vcpkg
COPY vcpkg.json /tmp/vcpkg.json
RUN git clone --filter=blob:none https://github.com/microsoft/vcpkg.git ${VCPKG_ROOT} \
&& cd ${VCPKG_ROOT} \
&& git checkout "$(grep '.builtin-baseline' /tmp/vcpkg.json | awk -F: '{print $2}' | tr -d ',\" ')" \
&& git checkout "$(grep 'builtin-baseline' /tmp/vcpkg.json | cut -d'"' -f4)" \
&& ./bootstrap-vcpkg.sh
WORKDIR /workspace
@ -44,12 +44,16 @@ COPY . /workspace
ARG BUILD_TYPE=Release
ENV BUILD_DIR=/workspace/build-emscripten
RUN mkdir -p ${BUILD_DIR}
# Force complete rebuild by clearing all vcpkg and emscripten caches
RUN source /opt/emsdk/emsdk_env.sh \
&& rm -rf ${VCPKG_ROOT}/buildtrees ${VCPKG_ROOT}/packages ${BUILD_DIR}/vcpkg_installed \
&& rm -rf /opt/emsdk/upstream/emscripten/cache \
&& cmake -G Ninja -S /workspace -B ${BUILD_DIR} \
-DWASM=ON \
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/opt/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake \
-DVCPKG_TARGET_TRIPLET=wasm32-emscripten \
-DVCPKG_TARGET_TRIPLET=wasm32-emscripten-pthread \
-DVCPKG_OVERLAY_TRIPLETS=/workspace/browser/triplets \
-DVCPKG_OVERLAY_PORTS=/workspace/browser/overlay-ports \
-DVCPKG_BUILD_TYPE=${BUILD_TYPE} \
-DWASM_USE_WASM_EXCEPTIONS=OFF \
@ -58,8 +62,9 @@ RUN source /opt/emsdk/emsdk_env.sh \
-DTOGGLE_BOT_PROTECTION=OFF \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_FLAGS="-fno-lto -std=c++20 -D_LIBCPP_DISABLE_AVAILABILITY -fexperimental-library" \
-DCMAKE_EXE_LINKER_FLAGS="-s ALLOW_MEMORY_GROWTH=1 -s USE_PTHREADS=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -fno-lto" \
-DCMAKE_C_FLAGS="-pthread -matomics -mbulk-memory -fno-lto" \
-DCMAKE_CXX_FLAGS="-pthread -matomics -mbulk-memory -fno-lto -std=c++20 -D_LIBCPP_DISABLE_AVAILABILITY -fexperimental-library" \
-DCMAKE_EXE_LINKER_FLAGS="-pthread -matomics -mbulk-memory -s ALLOW_MEMORY_GROWTH=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s WASM=1 -s NO_EXIT_RUNTIME=1 -fno-lto" \
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG -fno-lto" \
-DCMAKE_CXX_FLAGS_DEBUG="-O0 -g -fno-lto" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \

View file

@ -0,0 +1,53 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO freetype/freetype
REF VER-2-13-3
SHA512 be4411f0e1cd55ccabf0ffe20c7197d24f366e389ad3de440d2a79de5e50e0f9a1b4f46f28e5ebf0d76f3c71fe50c80d43d0b68d0f5ae9ba11b039b73cccfd9e
HEAD_REF master
)
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
brotli FT_REQUIRE_BROTLI
bzip2 FT_REQUIRE_BZIP2
error-strings FT_ENABLE_ERROR_STRINGS
png FT_REQUIRE_PNG
zlib FT_REQUIRE_ZLIB
)
# Force pthread flags for all C/C++ compilations in Emscripten
set(EXTRA_C_FLAGS "")
set(EXTRA_CXX_FLAGS "")
if(VCPKG_TARGET_TRIPLET MATCHES "emscripten" OR VCPKG_TARGET_TRIPLET MATCHES "wasm")
# Add atomics and bulk-memory support for shared memory/threading
# Append to existing VCPKG flags to preserve triplet settings
set(EXTRA_C_FLAGS "${VCPKG_C_FLAGS} -pthread -matomics -mbulk-memory")
set(EXTRA_CXX_FLAGS "${VCPKG_CXX_FLAGS} -pthread -matomics -mbulk-memory")
endif()
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
-DFT_DISABLE_HARFBUZZ=ON
OPTIONS_DEBUG
"-DCMAKE_C_FLAGS_DEBUG=${EXTRA_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}"
"-DCMAKE_CXX_FLAGS_DEBUG=${EXTRA_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}"
OPTIONS_RELEASE
"-DCMAKE_C_FLAGS_RELEASE=${EXTRA_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}"
"-DCMAKE_CXX_FLAGS_RELEASE=${EXTRA_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}"
)
vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/freetype)
vcpkg_fixup_pkgconfig()
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
# Cleanup
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
file(INSTALL "${SOURCE_PATH}/LICENSE.TXT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)

View file

@ -0,0 +1,18 @@
set(VCPKG_TARGET_ARCHITECTURE wasm32)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Emscripten)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "$ENV{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake")
# Force pthread support with atomics and bulk-memory for all packages
# These flags are required for shared memory support in WebAssembly
set(VCPKG_C_FLAGS "-pthread -matomics -mbulk-memory")
set(VCPKG_CXX_FLAGS "-pthread -matomics -mbulk-memory")
set(VCPKG_LINKER_FLAGS "-pthread -matomics -mbulk-memory")
# Also set as CMAKE_*_FLAGS to ensure they're applied universally
set(VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DCMAKE_C_FLAGS=-pthread -matomics -mbulk-memory"
"-DCMAKE_CXX_FLAGS=-pthread -matomics -mbulk-memory"
)

View file

@ -2,14 +2,20 @@
; This section can also expose options intended for modding, including font customization.
[graphics]
; ===== Atlas configuration =====
; maxAtlasSize: hard cap for atlas textures (in pixels).
maxAtlasSize = 8192
; Atlas sizes (in pixels):
; 0 = auto-detect based on the maximum texture size supported by the GPU
; -1 = disable the atlas
mapAtlasSize = 0
foregroundAtlasSize = 2048
; ===============================
; ===============================
; You can use TTF fonts directly with stroke support:
; Format: path|size|stroke-width|stroke-color
[font]
widget = verdana-bold|10|0|black
static-text = verdana-11px-rounded
animated-text = verdana-11px-rounded
creature-text = verdana-11px-rounded

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 474 B

After

Width:  |  Height:  |  Size: 474 B

Before After
Before After

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
data/fonts/ttf/Verdana.ttf Normal file

Binary file not shown.

BIN
data/fonts/ttf/arial.ttf Normal file

Binary file not shown.

BIN
data/fonts/ttf/arialb.ttf Normal file

Binary file not shown.

BIN
data/fonts/ttf/banita.ttf Normal file

Binary file not shown.

BIN
data/fonts/ttf/martel.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -13,16 +13,24 @@ ShowOffWidget < UIWidget
UITextEdit
id: description
size: 476 0
size: 465 0
ttf-font: verdana-bold
ttf-font-size: 10
anchors.left: image.right
anchors.top: parent.top
anchors.bottom: parent.bottom
margin-top: 2
margin-left: 10
margin-left: 2
color: #c0c0c0ff
multiline: true
text-wrap: true
text-auto-resize: true
editable: false
selectable: true
focusable: false
cursor-visible: false
change-cursor-image: false
selection-color: #f4f4f4ff
selection-background-color: #808080ff
Panel
id: bottomMenu
@ -31,19 +39,20 @@ Panel
anchors.horizontalCenter: parent.horizontalCenter
image-source: /images/ui/panel_top
UIWidget
Label
phantom: true
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
text-align: center
text-auto-resize: true
color: #e98d02
color: #c0c0c0ff
margin-bottom: 110
text: OTClient Redemption
font: verdana-11px-rounded
font-scale: 4
ttf-font: martel
ttf-font-size: 90
stroke: 2 black
shader: Map - Party
MiniQtScrollableWindow
id: showOffWindow
anchors.bottom: parent.bottom

View file

@ -1,13 +1,17 @@
local resourceLoaders = {
["otui"] = g_ui.importStyle,
["otfont"] = g_fonts.importFont,
["ttf"] = g_fonts.importFont,
["otf"] = g_fonts.importFont,
["otps"] = g_particles.importParticle,
}
function init()
local device = g_platform.getDevice()
importResources("styles", "otui", device)
importResources("fonts", "otfont", device)
importResources("fonts/otfont", "otfont", device)
importResources("fonts//ttf", "ttf", device)
importResources("fonts/ttf", "otf", device)
importResources("particles", "otps", device)
g_mouse.loadCursors('/cursors/cursors')

View file

@ -133,6 +133,7 @@ find_package(httplib CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(utf8cpp REQUIRED)
find_package(unofficial-inih CONFIG REQUIRED)
find_package(Freetype REQUIRED)
find_path(CPPCODEC_INCLUDE_DIRS "cppcodec/base32_crockford.hpp")
@ -328,6 +329,7 @@ if (TOGGLE_FRAMEWORK_GRAPHICS)
framework/graphics/drawpool.cpp
framework/graphics/drawpoolmanager.cpp
framework/graphics/fontmanager.cpp
framework/graphics/ttfloader.cpp
framework/graphics/framebuffer.cpp
framework/graphics/graphics.cpp
framework/graphics/image.cpp
@ -557,6 +559,7 @@ if(MSVC)
pugixml::pugixml
fmt::fmt-header-only
utf8cpp::utf8cpp
Freetype::Freetype
)
elseif(ANDROID)
target_include_directories(otclient_core
@ -674,6 +677,7 @@ elseif(WASM)
Ogg::ogg
Vorbis::vorbisfile
Vorbis::vorbis
Freetype::Freetype
)
@ -790,6 +794,7 @@ else() # Linux
Ogg::ogg
Vorbis::vorbisfile
Vorbis::vorbis
Freetype::Freetype
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")

Some files were not shown because too many files have changed in this diff Show more