From f48069cf82b6ab36259197a523efb68fe7f838e0 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 18 Sep 2026 23:08:32 -0400 Subject: [PATCH] Add LoadCodepoints bindings --- include/Font.hpp | 5 +++++ include/FontUnmanaged.hpp | 19 +++++++++++++++++++ include/Functions.hpp | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/Font.hpp b/include/Font.hpp index b60ce546..0fa4f09c 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -61,6 +61,11 @@ class Font : public FontUnmanaged { FontUnmanaged::Load(fileName, fontSize, codepoints, codepointCount); } + void Load(const std::string& fileName, int fontSize, const std::vector& codepoints) { + Unload(); + FontUnmanaged::Load(fileName, fontSize, codepoints); + } + void Load(const ::Image& image, ::Color key, int firstChar) { Unload(); FontUnmanaged::Load(image, key, firstChar); diff --git a/include/FontUnmanaged.hpp b/include/FontUnmanaged.hpp index 9012bbeb..5918fd21 100644 --- a/include/FontUnmanaged.hpp +++ b/include/FontUnmanaged.hpp @@ -2,6 +2,7 @@ #define RAYLIB_CPP_INCLUDE_FONTUNMANAGED_HPP_ #include +#include #include "./RaylibException.hpp" #include "./TextureUnmanaged.hpp" @@ -55,6 +56,15 @@ class FontUnmanaged : public ::Font { Load(fileName, fontSize, codepoints, codepointCount); } + /** + * Loads a Font from the given file, with the given codepoints. + * + * @throws raylib::RaylibException Throws if the given font failed to initialize. + */ + FontUnmanaged(const std::string& fileName, int fontSize, const std::vector& codepoints) { + Load(fileName, fontSize, codepoints); + } + /** * Loads a Font from the given image with a color key. * @@ -123,6 +133,15 @@ class FontUnmanaged : public ::Font { } } + /** + * Loads a font from a given file, with the given codepoints. + * + * @throws raylib::RaylibException Throws if the given font failed to initialize. + */ + void Load(const std::string& fileName, int fontSize, const std::vector& codepoints) { + Load(fileName, fontSize, codepoints.data(), static_cast(codepoints.size())); + } + /** * Loads a font from an image with a color key. * diff --git a/include/Functions.hpp b/include/Functions.hpp index d7e74afb..8c167c58 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -445,6 +445,24 @@ RLCPP_MAYBEUNUSED RLCPPAPI inline std::string TextToCamel(const std::string& tex return ::TextToCamel(text.c_str()); } +/** + * Load all codepoints from a UTF-8 text string + */ +RLCPP_MAYBEUNUSED RLCPPAPI std::vector LoadCodepoints(const std::string& text) { + int count = 0; + int* codepoints = ::LoadCodepoints(text.c_str(), &count); + std::vector output(codepoints, codepoints + count); + ::UnloadCodepoints(codepoints); + return output; +} + +/** + * Get total number of codepoints in a UTF-8 encoded string + */ +RLCPP_MAYBEUNUSED RLCPPAPI inline int GetCodepointCount(const std::string& text) { + return ::GetCodepointCount(text.c_str()); +} + /** * Get integer value from text (negative values not supported) */