From 913458f721e98844eaf57138b09894da4e629c81 Mon Sep 17 00:00:00 2001 From: Stephen Molloy Date: Thu, 28 Dec 2023 00:16:25 +0100 Subject: [PATCH] Added the new function --- src/raylib.h | 1 + src/rtext.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index 2ab3f3041..35e22274e 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1427,6 +1427,7 @@ RLAPI int GetPixelDataSize(int width, int height, int format); // G RLAPI Font GetFontDefault(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set +RLAPI void AddNewCharsToFontEx(Font *font, const char *fileName, int fontSize, char *newChars); // Reload the font after adding the new characters to the list of desired characters RLAPI Font LoadFontFromImage(Image image, Color key, int firstChar); // Load font from Image (XNA style) RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *codepoints, int codepointCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf' RLAPI bool IsFontReady(Font font); // Check if a font is ready diff --git a/src/rtext.c b/src/rtext.c index 2a6aa1273..8012b2a0d 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -378,6 +378,33 @@ Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepoi return font; } +// Reload the font after adding the new characters to the list of desired characters +// Passing NULL to the newChars variable results in a reset to the default of LoadFontEx +void AddNewCharsToFontEx(Font *font, const char *fileName, int fontSize, char *newChars) +{ + if (newChars == NULL) { + *font = LoadFontEx(fileName, fontSize, NULL, 0); + return; + } + + int codepointCount = 0; + int *codepoints = LoadCodepoints(newChars, &codepointCount); + + int newCount = font->glyphCount + codepointCount; + + int *newCodepoints = MemAlloc(newCount * sizeof(int)); + for (int i=0; iglyphCount; i++) { + newCodepoints[i] = font->glyphs[i].value; + } + for (int i=font->glyphCount; iglyphCount]; + } + + *font = LoadFontEx(fileName, fontSize, newCodepoints, newCount); + + MemFree(newCodepoints); +} + // Load an Image font file (XNA style) Font LoadFontFromImage(Image image, Color key, int firstChar) {