feat(text): optional vendored stb_truetype backend for runtime external fonts

This commit is contained in:
Martino Ferrari committed 2026-09-28 16:07:27 +02:00
1 parent daff60e3f0
commit 14d664a246
12 files changed
+6511 -19

No files matched your search

+36 -1
View File
@@ -43,6 +43,33 @@ target_compile_features(plot_core PUBLIC cxx_std_20)
target_link_libraries(plot_core PRIVATE ${CMAKE_DL_LIBS})
plot_apply_warnings(plot_core)
# The optional runtime-font backend: plot::text::TrueTypeFont, which bakes a real
# TrueType/OpenType file into a fixed-cell atlas at run time (see
# include/plot/text/true_type_font.hpp). It is the one target that compiles the
# vendored third_party/stb_truetype.h, so it is opt-in and separable -- the core
# library, its public headers and its tests build without it -- and its default
# follows the vendored header's presence: a tree that has the file wants the
# feature, and one that does not cannot have it. Asking for it explicitly without
# the header is an error rather than a silent downgrade, because the option is
# then the only thing that would have said so.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/stb_truetype.h")
set(PLOT_VENDORED_STB_TRUETYPE TRUE)
else()
set(PLOT_VENDORED_STB_TRUETYPE FALSE)
endif()
option(PLOT_BUILD_TTF_FONT
"Build the optional plot::text::TrueTypeFont backend (vendored stb_truetype)"
${PLOT_VENDORED_STB_TRUETYPE})
if(PLOT_BUILD_TTF_FONT AND NOT PLOT_VENDORED_STB_TRUETYPE)
message(FATAL_ERROR
"plot: PLOT_BUILD_TTF_FONT=ON needs third_party/stb_truetype.h, which this tree does "
"not have. Restore it -- include/plot/text/true_type_font.hpp records the version and "
"the source URL it came from -- or configure with -DPLOT_BUILD_TTF_FONT=OFF.")
endif()
if(PLOT_BUILD_TTF_FONT)
add_subdirectory(src/text)
endif()
# Adapters own the surface and translate their host's events; examples link the
# adapter they demo. Both are opt-in, so the core library and its tests still build
# on a bare toolchain.
@@ -120,7 +147,15 @@ if(PLOT_INSTALL)
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(DIRECTORY include/plot DESTINATION include)
# The optional backend's header goes in only when that backend was built: an
# installed header with no library behind it is a promise the prefix cannot keep,
# and which configuration a prefix came from is not something a consumer can see.
if(PLOT_BUILD_TTF_FONT)
install(DIRECTORY include/plot DESTINATION include)
else()
install(DIRECTORY include/plot DESTINATION include
PATTERN "true_type_font.hpp" EXCLUDE)
endif()
install(EXPORT plotTargets
NAMESPACE plot::