SDL_ttf: Cleared up glyph vs codepoint

From 1750feddf39c3ccb00d4605a18494499f6dadbb1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 28 Sep 2024 07:33:37 -0700
Subject: [PATCH] Cleared up glyph vs codepoint

Also reorganized the code a bit to keep related APIs together.
---
 include/SDL3_ttf/SDL_ttf.h | 434 ++++++++++++-----------
 src/SDL_ttf.c              | 686 ++++++++++++++++++-------------------
 2 files changed, 557 insertions(+), 563 deletions(-)

diff --git a/include/SDL3_ttf/SDL_ttf.h b/include/SDL3_ttf/SDL_ttf.h
index f08a54e9..da9d30c4 100644
--- a/include/SDL3_ttf/SDL_ttf.h
+++ b/include/SDL3_ttf/SDL_ttf.h
@@ -27,11 +27,6 @@
  *
  *  This library is a wrapper around the excellent FreeType 2.0 library,
  *  available at: https://www.freetype.org/
- *
- *  Note: In many places, SDL_ttf will say "glyph" when it means "code point."
- *  Unicode is hard, we learn as we go, and we apologize for adding to the
- *  confusion.
- *
  */
 #ifndef SDL_TTF_H_
 #define SDL_TTF_H_
@@ -300,32 +295,10 @@ extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, float ptsize
 #define TTF_STYLE_UNDERLINE     0x04
 #define TTF_STYLE_STRIKETHROUGH 0x08
 
-/**
- * Query a font's current style.
- *
- * The font styles are a set of bit flags, OR'd together:
- *
- * - `TTF_STYLE_NORMAL` (is zero)
- * - `TTF_STYLE_BOLD`
- * - `TTF_STYLE_ITALIC`
- * - `TTF_STYLE_UNDERLINE`
- * - `TTF_STYLE_STRIKETHROUGH`
- *
- * \param font the font to query.
- * \returns the current font style, as a set of bit flags.
- *
- * \threadsafety It is safe to call this function from any thread.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- *
- * \sa TTF_SetFontStyle
- */
-extern SDL_DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font);
-
 /**
  * Set a font's current style.
  *
- * Setting the style clears already-generated glyphs, if any, from the cache.
+ * This clears already-generated glyphs, if any, from the cache.
  *
  * The font styles are a set of bit flags, OR'd together:
  *
@@ -348,18 +321,26 @@ extern SDL_DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font);
 extern SDL_DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style);
 
 /**
- * Query a font's current outline.
+ * Query a font's current style.
+ *
+ * The font styles are a set of bit flags, OR'd together:
+ *
+ * - `TTF_STYLE_NORMAL` (is zero)
+ * - `TTF_STYLE_BOLD`
+ * - `TTF_STYLE_ITALIC`
+ * - `TTF_STYLE_UNDERLINE`
+ * - `TTF_STYLE_STRIKETHROUGH`
  *
  * \param font the font to query.
- * \returns the font's current outline value.
+ * \returns the current font style, as a set of bit flags.
  *
  * \threadsafety It is safe to call this function from any thread.
  *
  * \since This function is available since SDL_ttf 3.0.0.
  *
- * \sa TTF_SetFontOutline
+ * \sa TTF_SetFontStyle
  */
-extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font);
+extern SDL_DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font);
 
 /**
  * Set a font's current outline.
@@ -378,6 +359,19 @@ extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font);
  */
 extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline);
 
+/**
+ * Query a font's current outline.
+ *
+ * \param font the font to query.
+ * \returns the font's current outline value.
+ *
+ * \threadsafety It is safe to call this function from any thread.
+ *
+ * \since This function is available since SDL_ttf 3.0.0.
+ *
+ * \sa TTF_SetFontOutline
+ */
+extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font);
 
 /**
  * Hinting flags
@@ -388,6 +382,31 @@ extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline)
 #define TTF_HINTING_NONE            3
 #define TTF_HINTING_LIGHT_SUBPIXEL  4
 
+/**
+ * Set a font's current hinter setting.
+ *
+ * This clears already-generated glyphs, if any, from the cache.
+ *
+ * The hinter setting is a single value:
+ *
+ * - `TTF_HINTING_NORMAL`
+ * - `TTF_HINTING_LIGHT`
+ * - `TTF_HINTING_MONO`
+ * - `TTF_HINTING_NONE`
+ * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later)
+ *
+ * \param font the font to set a new hinter setting on.
+ * \param hinting the new hinter setting.
+ *
+ * \threadsafety This function should be called on the thread that created the
+ *               font.
+ *
+ * \since This function is available since SDL_ttf 3.0.0.
+ *
+ * \sa TTF_GetFontHinting
+ */
+extern SDL_DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, int hinting);
+
 /**
  * Query a font's current FreeType hinter setting.
  *
@@ -411,29 +430,40 @@ extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline)
 extern SDL_DECLSPEC int SDLCALL TTF_GetFontHinting(const TTF_Font *font);
 
 /**
- * Set a font's current hinter setting.
+ * Enable Signed Distance Field rendering for a font.
  *
- * Setting it clears already-generated glyphs, if any, from the cache.
+ * This works with the Blended APIs. SDF is a technique that
+ * helps fonts look sharp even when scaling and rotating.
  *
- * The hinter setting is a single value:
+ * This clears already-generated glyphs, if any, from the cache.
  *
- * - `TTF_HINTING_NORMAL`
- * - `TTF_HINTING_LIGHT`
- * - `TTF_HINTING_MONO`
- * - `TTF_HINTING_NONE`
- * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later)
+ * \param font the font to set SDF support on.
+ * \param enabled true to enable SDF, false to disable.
+ * \returns true on success or false on failure; call SDL_GetError()
+ *          for more information.
  *
- * \param font the font to set a new hinter setting on.
- * \param hinting the new hinter setting.
+ * \threadsafety This function should be called on the thread that created the font.
  *
- * \threadsafety This function should be called on the thread that created the
- *               font.
+ * \since This function is available since SDL_ttf 3.0.0.
+ *
+ * \sa TTF_GetFontSDF
+ */
+extern SDL_DECLSPEC bool TTF_SetFontSDF(TTF_Font *font, bool enabled);
+
+/**
+ * Query whether Signed Distance Field rendering is enabled for a font.
+ *
+ * \param font the font to query
+ *
+ * \returns true if enabled, false otherwise.
+ *
+ * \threadsafety It is safe to call this function from any thread.
  *
  * \since This function is available since SDL_ttf 3.0.0.
  *
- * \sa TTF_GetFontHinting
+ * \sa TTF_SetFontSDF
  */
-extern SDL_DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, int hinting);
+extern SDL_DECLSPEC bool TTF_GetFontSDF(const TTF_Font *font);
 
 /**
  * The horizontal alignment used when rendering wrapped text.
@@ -449,33 +479,33 @@ typedef enum TTF_HorizontalAlignment
 } TTF_HorizontalAlignment;
 
 /**
- * Query a font's current wrap alignment option.
+ * Set a font's current wrap alignment option.
  *
- * \param font the font to query.
- * \returns the font's current wrap alignment option.
+ * \param font the font to set a new wrap alignment option on.
+ * \param align the new wrap alignment option.
  *
- * \threadsafety It is safe to call this function from any thread.
+ * \threadsafety This function should be called on the thread that created the
+ *               font.
  *
  * \since This function is available since SDL_ttf 3.0.0.
  *
- * \sa TTF_SetFontWrapAlignment
+ * \sa TTF_GetFontWrapAlignment
  */
-extern SDL_DECLSPEC TTF_HorizontalAlignment SDLCALL TTF_GetFontWrapAlignment(const TTF_Font *font);
+extern SDL_DECLSPEC void SDLCALL TTF_SetFontWrapAlignment(TTF_Font *font, TTF_HorizontalAlignment align);
 
 /**
- * Set a font's current wrap alignment option.
+ * Query a font's current wrap alignment option.
  *
- * \param font the font to set a new wrap alignment option on.
- * \param align the new wrap alignment option.
+ * \param font the font to query.
+ * \returns the font's current wrap alignment option.
  *
- * \threadsafety This function should be called on the thread that created the
- *               font.
+ * \threadsafety It is safe to call this function from any thread.
  *
  * \since This function is available since SDL_ttf 3.0.0.
  *
- * \sa TTF_GetFontWrapAlignment
+ * \sa TTF_SetFontWrapAlignment
  */
-extern SDL_DECLSPEC void SDLCALL TTF_SetFontWrapAlignment(TTF_Font *font, TTF_HorizontalAlignment align);
+extern SDL_DECLSPEC TTF_HorizontalAlignment SDLCALL TTF_GetFontWrapAlignment(const TTF_Font *font);
 
 /**
  * Query the total height of a font.
@@ -646,10 +676,109 @@ extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontFamilyName(const TTF_Font *f
 extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontStyleName(const TTF_Font *font);
 
 /**
- * Check whether a glyph is provided by the font for a 32-bit codepoint.
+ * Direction flags
+ *
+ * \since This enum is available since SDL_ttf 3.0.0.
+ *
+ * \sa TTF_SetFontDirection
+ */
+typedef enum TTF_Direction
+{
+  TTF_DIRECTION_LTR = 0,    /* Left to Right */
+  TTF_DIRECTION_RTL,        /* Right to Left */
+  TTF_DIRECTION_TTB,        /* Top to Bottom */
+  TTF_DIRECTION_BTT         /* Bottom to Top */
+} TTF_Direction;
+
+/**
+ * Set direction to be used for text shaping by a font.
+ *
+ * Possible direction values are:
+ *
+ * - `TTF_DIRECTION_LTR` (Left to Right)
+ * - `TTF_DIRECTION_RTL` (Right to Left)
+ * - `TTF_DIRECTION_TTB` (Top to Bottom)
+ * - `TTF_DIRECTION_BTT` (Bottom to Top)
+ *
+ * If SDL_ttf was not built with HarfBuzz support, this function returns
+ * false.
+ *
+ * \param font the font to specify a direction for.
+ * \param direction the new direction for text to flow.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ *          information.
+ *
+ * \threadsafety This function should be called on the thread that created the
+ *               font.
+ *
+ * \since This function is available since SDL_ttf 3.0.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction);
+
+/**
+ * Set script to be used for text shaping by a font.
+ *
+ * The supplied script value must be a null-terminated string of exactly four
+ * characters.
+ *
+ * If SDL_ttf was not built with HarfBuzz support, this function returns
+ * false.
+ *
+ * \param font the font to specify a script name for.
+ * \param script null-terminated string of exactly 4 characters.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ *          information.
+ *
+ * \threadsafety This function is not thread-safe.
+ *
+ * \since This function is available since SDL_ttf 3.0.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL TTF_SetFontScript(TTF_Font *font, const char *script);
+
+/**
+ * Get the script used by a 32-bit codepoint.
+ *
+ * The supplied script value will be a null-terminated string of exactly four
+ * characters.
+ *
+ * If SDL_ttf was not built with HarfBuzz support, this function returns
+ * false.
  *
- * \param font the font to query.
  * \param ch the character code to check.
+ * \param script a pointer filled in with the script used by `ch`.
+ * \param script_size the size of the script buffer, which must be at least 5
+ *                    characters.
+ * \returns true on success or false on failure; call SDL_GetError() for more
+ *          information.
+ *
+ * \threadsafety This function should be called on the thread that created the
+ *               font.
+ *
+ * \since This function is available since SDL_ttf 3.0.0.
+ */
+extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphScript(Uint32 ch, char *script, size_t script_size);
+
+/**
+ * Set language to be used for text shaping by a font.
+ *
+ * If SDL_ttf was not built with HarfBuzz support, this function returns false.
+ *
+ * \param font the font to specify a language for.
+ * \param language_bcp47 a null-terminated string containing the desired language's BCP47 code. Or null to reset the value.
+ * \returns true on success or false on failure; call SDL_GetError()
+ *          for more information.
+ *
+ * \threadsafety This function should be called on the thread that created the font.
+ *
+ * \since This function is available since SDL_ttf 3.0.0.
+ */
+extern SDL_DECLSPEC bool TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47);
+
+/**
+ * Check whether a glyph is provided by the font for a UNICODE codepoint.
+ *
+ * \param font the font to query.
+ * \param ch the codepoint to check.
  * \returns true if font provides a glyph for this character, false if not.
  *
  * \threadsafety This function should be called on the thread that created the
@@ -660,14 +789,14 @@ extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontStyleName(const TTF_Font *fo
 extern SDL_DECLSPEC bool SDLCALL TTF_FontHasGlyph(TTF_Font *font, Uint32 ch);
 
 /**
- * Query the metrics (dimensions) of a font's 32-bit glyph.
+ * Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint.
  *
  * To understand what these metrics mean, here is a useful link:
  *
  * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
  *
  * \param font the font to query.
- * \param ch the character code to check.
+ * \param ch the codepoint to check.
  * \param minx a pointer filled in with the minimum x coordinate of the glyph
  *             from the left edge of its bounding box. This value may be
  *             negative.
@@ -690,6 +819,22 @@ extern SDL_DECLSPEC bool SDLCALL TTF_FontHasGlyph(TTF_Font *font, Uint32 ch);
  */
 extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphMetrics(TTF_Font *font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance);
 
+/**
+ * Query the kerning size between the glyphs of two UNICODE codepoints.
+ *
+ * \param font the font to query.
+ * \param previous_ch the previous codepoint.
+ * \param ch the current codepoint.
+ * \param kerning a pointer filled in with the kerning size between the two glyphs, in pixels, may be NULL.
+ * \returns true on success or false on failure; call SDL_GetError()
+ *          for more information.
+ *
+ * \threadsafety This function should be called on the thread that created the font.
+ *
+ * \since This function is available since SDL_ttf 3.0.0.
+ */
+extern SDL_DECLSPEC bool TTF_GetGlyphKerning(TTF_Font *font, Uint32 previous_ch, Uint32 ch, int *kerning);
+
 /**
  * Calculate the dimensions of a rendered string of UTF-8 text.
  *
@@ -835,7 +980,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font,
 extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrapLength);
 
 /**
- * Render a single 32-bit glyph at high quality to a new 8-bit surface.
+ * Render a single UNICODE codepoint at high quality to a new 8-bit surface.
  *
  * This function will allocate a new 8-bit, palettized surface. The surface's
  * 0 pixel will be the specified background color, while other pixels have
@@ -846,7 +991,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font
  * and aligned normally in the Y direction.
  *
  * \param font the font to render with.
- * \param ch the character to render.
+ * \param ch the codepoint to render.
  * \param fg the foreground color for the text.
  * \param bg the background color for the text.
  * \returns a new 8-bit, palettized surface, or NULL if there was an error.
@@ -926,7 +1071,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font,
 extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrapLength);
 
 /**
- * Render a single 32-bit glyph at high quality to a new ARGB surface.
+ * Render a single UNICODE codepoint at high quality to a new ARGB surface.
  *
  * This function will allocate a new 32-bit, ARGB surface, using alpha
  * blending to dither the font with the given color. This function returns the
@@ -936,7 +1081,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Fon
  * and aligned normally in the Y direction.
  *
  * \param font the font to render with.
- * \param ch the character to render.
+ * \param ch the codepoint to render.
  * \param fg the foreground color for the text.
  * \returns a new 32-bit, ARGB surface, or NULL if there was an error.
  *
@@ -1018,7 +1163,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD(TTF_Font *font, con
 extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrapLength);
 
 /**
- * Render a single 32-bit glyph at LCD subpixel quality to a new ARGB surface.
+ * Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB surface.
  *
  * This function will allocate a new 32-bit, ARGB surface, and render
  * alpha-blended text using FreeType's LCD subpixel rendering. This function
@@ -1028,7 +1173,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *f
  * and aligned normally in the Y direction.
  *
  * \param font the font to render with.
- * \param ch the character to render.
+ * \param ch the codepoint to render.
  * \param fg the foreground color for the text.
  * \param bg the background color for the text.
  * \returns a new 32-bit, ARGB surface, or NULL if there was an error.
@@ -1121,157 +1266,6 @@ extern SDL_DECLSPEC void SDLCALL TTF_Quit(void);
  */
 extern SDL_DECLSPEC int SDLCALL TTF_WasInit(void);
 
-/**
- * Query the kerning size of two 32-bit glyphs.
- *
- * \param font the font to query.
- * \param previous_ch the previous character's code, 32 bits.
- * \param ch the current character's code, 32 bits.
- * \param kerning a pointer filled in with the kerning size between the two specified characters, in pixels, may be NULL.
- * \returns true on success or false on failure; call SDL_GetError()
- *          for more information.
- *
- * \threadsafety This function should be called on the thread that created the font.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- */
-extern SDL_DECLSPEC bool TTF_GetGlyphKerning(TTF_Font *font, Uint32 previous_ch, Uint32 ch, int *kerning);
-
-/**
- * Enable Signed Distance Field rendering for a font.
- *
- * This works with the Blended APIs. SDF is a technique that
- * helps fonts look sharp even when scaling and rotating.
- *
- * This clears already-generated glyphs, if any, from the cache.
- *
- * \param font the font to set SDF support on.
- * \param enabled true to enable SDF, false to disable.
- * \returns true on success or false on failure; call SDL_GetError()
- *          for more information.
- *
- * \threadsafety This function should be called on the thread that created the font.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- *
- * \sa TTF_GetFontSDF
- */
-extern SDL_DECLSPEC bool TTF_SetFontSDF(TTF_Font *font, bool enabled);
-
-/**
- * Query whether Signed Distance Field rendering is enabled for a font.
- *
- * \param font the font to query
- *
- * \returns true if enabled, false otherwise.
- *
- * \threadsafety It is safe to call this function from any thread.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- *
- * \sa TTF_SetFontSDF
- */
-extern SDL_DECLSPEC bool TTF_GetFontSDF(const TTF_Font *font);
-
-/**
- * Direction flags
- *
- * \since This enum is available since SDL_ttf 3.0.0.
- *
- * \sa TTF_SetFontDirection
- */
-typedef enum TTF_Direction
-{
-  TTF_DIRECTION_LTR = 0,    /* Left to Right */
-  TTF_DIRECTION_RTL,        /* Right to Left */
-  TTF_DIRECTION_TTB,        /* Top to Bottom */
-  TTF_DIRECTION_BTT         /* Bottom to Top */
-} TTF_Direction;
-
-/**
- * Set direction to be used for text shaping by a font.
- *
- * Possible direction values are:
- *
- * - `TTF_DIRECTION_LTR` (Left to Right)
- * - `TTF_DIRECTION_RTL` (Right to Left)
- * - `TTF_DIRECTION_TTB` (Top to Bottom)
- * - `TTF_DIRECTION_BTT` (Bottom to Top)
- *
- * If SDL_ttf was not built with HarfBuzz support, this function returns
- * false.
- *
- * \param font the font to specify a direction for.
- * \param direction the new direction for text to flow.
- * \returns true on success or false on failure; call SDL_GetError() for more
- *          information.
- *
- * \threadsafety This function should be called on the thread that created the
- *               font.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- */
-extern SDL_DECLSPEC bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction);
-
-/**
- * Set script to be used for text shaping by a font.
- *
- * The supplied script value must be a null-terminated string of exactly four
- * characters.
- *
- * If SDL_ttf was not built with HarfBuzz support, this function returns
- * false.
- *
- * \param font the font to specify a script name for.
- * \param script null-terminated string of exactly 4 characters.
- * \returns true on success or false on failure; call SDL_GetError() for more
- *          information.
- *
- * \threadsafety This function is not thread-safe.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- */
-extern SDL_DECLSPEC bool SDLCALL TTF_SetFontScript(TTF_Font *font, const char *script);
-
-/**
- * Get the script used by a 32-bit codepoint.
- *
- * The supplied script value will be a null-terminated string of exactly four
- * characters.
- *
- * If SDL_ttf was not built with HarfBuzz support, this function returns
- * false.
- *
- * \param ch the character code to check.
- * \param script a pointer filled in with the script used by `ch`.
- * \param script_size the size of the script buffer, which must be at least 5
- *                    characters.
- * \returns true on success or false on failure; call SDL_GetError() for more
- *          information.
- *
- * \threadsafety This function should be called on the thread that created the
- *               font.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- */
-extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphScript(Uint32 ch, char *script, size_t script_size);
-
-/**
- * Set language to be used for text shaping by a font.
- *
- * If SDL_ttf was not built with HarfBuzz support, this function returns false.
- *
- * \param font the font to specify a language for.
- * \param language_bcp47 a null-terminated string containing the desired language's BCP47 code. Or null to reset the value.
- * \returns true on success or false on failure; call SDL_GetError()
- *          for more information.
- *
- * \threadsafety This function should be called on the thread that created the font.
- *
- * \since This function is available since SDL_ttf 3.0.0.
- */
-extern SDL_DECLSPEC bool TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47);
-
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
 }
diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index cea17dde..a23c64ba 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -263,8 +263,8 @@ struct TTF_Font {
     /* Internal buffer to store positions computed by TTF_Size_Internal()
      * for rendered string by Render_Line() */
     PosBuf_t *pos_buf;
-    Uint32 pos_len;
-    Uint32 pos_max;
+    int pos_len;
+    int pos_max;
 
     /* Hinting modes */
     int ft_load_target;
@@ -329,7 +329,7 @@ typedef enum {
     RENDER_LCD
 } render_mode_t;
 
-static int TTF_initFontMetrics(TTF_Font *font);
+static int TTF_InitFontMetrics(TTF_Font *font);
 
 static bool TTF_Size_Internal(TTF_Font *font, const char *text, size_t length, int *w, int *h, int *xstart, int *ystart, int measure_width, int *extent, int *count);
 
@@ -1118,11 +1118,11 @@ static int Get_Alignment(void)
 #endif
 #define BUILD_RENDER_LINE(NAME, IS_BLENDED, IS_BLENDED_OPAQUE, IS_LCD, WP_WC, WS, BLIT_GLYPH_BLENDED_OPAQUE_OPTIM, BLIT_GLYPH_BLENDED_OPTIM, BLIT_GLYPH_OPTIM) \
                                                                                                                         \
-static int Render_Line_##NAME(TTF_Font *font, SDL_Surface *textbuf, int xstart, int ystart, SDL_Color *fg)              \
+static bool Render_Line_##NAME(TTF_Font *font, SDL_Surface *textbuf, int xstart, int ystart, SDL_Color *fg)              \
 {                                                                                                                       \
     const int alignment = Get_Alignment() - 1;                                                                          \
     const int bpp = ((IS_BLENDED || IS_LCD) ? 4 : 1);                                                                   \
-    unsigned int i;                                                                                                     \
+    int i;                                                                                                              \
     Uint8 fg_alpha = (fg ? fg->a : 0);                                                                                  \
     for (i = 0; i < font->pos_len; i++) {                                                                               \
         FT_UInt idx = font->pos_buf[i].index;                                                                           \
@@ -1130,7 +1130,7 @@ static int Render_Line_##NAME(TTF_Font *font, SDL_Surface *textbuf, int xstart,
         int y       = font->pos_buf[i].y;                                                                               \
         TTF_Image *image;                                                                                               \
                                                                                                                         \
-        if (Find_GlyphByIndex(font, idx, WP_WC, WS, x & 63, NULL, &image)) {                                    \
+        if (Find_GlyphByIndex(font, idx, WP_WC, WS, x & 63, NULL, &image)) {                                            \
             int above_w, above_h;                                                                                       \
             Uint32 dstskip;                                                                                             \
             Sint32 srcskip; /* Can be negative */                                                                       \
@@ -1218,11 +1218,11 @@ static int Render_Line_##NAME(TTF_Font *font, SDL_Surface *textbuf, int xstart,
             }                                                                                                           \
             image->buffer = saved_buffer;                                                                               \
         } else {                                                                                                        \
-            return -1;                                                                                                  \
+            return false;                                                                                                  \
         }                                                                                                               \
     }                                                                                                                   \
                                                                                                                         \
-    return 0;                                                                                                           \
+    return true;                                                                                                           \
 }                                                                                                                       \
                                                                                                                         \
 
@@ -1301,7 +1301,7 @@ static int (*Render_Line_SDF_LCD_SP)(TTF_Font *font, SDL_Surface *textbuf, int x
 #pragma GCC diagnostic pop
 #endif
 
-static int Render_Line(const render_mode_t render_mode, int subpixel, TTF_Font *font, SDL_Surface *textbuf, int xstart, int ystart, SDL_Color fg)
+static bool Render_Line(const render_mode_t render_mode, int subpixel, TTF_Font *font, SDL_Surface *textbuf, int xstart, int ystart, SDL_Color fg)
 {
     /* Render line (pos_buf) to textbuf at (xstart, ystart) */
 
@@ -1924,60 +1924,8 @@ SDL_PropertiesID TTF_GetFontProperties(TTF_Font *font)
     return font->props;
 }
 
-bool TTF_SetFontSizeDPI(TTF_Font *font, float ptsize, unsigned int hdpi, unsigned int vdpi)
-{
-    FT_Face face = font->face;
-    FT_Error error;
-
-    /* Make sure that our font face is scalable (global metrics) */
-    if (FT_IS_SCALABLE(face)) {
-        /* Set the character size using the provided DPI.  If a zero DPI
-         * is provided, then the other DPI setting will be used.  If both
-         * are zero, then Freetype's default 72 DPI will be used.  */
-        error = FT_Set_Char_Size(face, 0, (int)SDL_roundf(ptsize * 64), hdpi, vdpi);
-        if (error) {
-            return TTF_SetFTError("Couldn't set font size", error);
-        }
-    } else {
-        /* Non-scalable font case.  ptsize determines which family
-         * or series of fonts to grab from the non-scalable format.
-         * It is not the point size of the font.  */
-        if (face->num_fixed_sizes <= 0) {
-            return SDL_SetError("Couldn't select size : no num_fixed_sizes");
-        }
-
-        /* within [0; num_fixed_sizes - 1] */
-        int index = (int)ptsize;
-        index = SDL_max(index, 0);
-        index = SDL_min(index, face->num_fixed_sizes - 1);
-
-        error = FT_Select_Size(face, index);
-        if (error) {
-            return TTF_SetFTError("Couldn't select size", error);
-        }
-    }
-
-    if (TTF_initFontMetrics(font) < 0) {
-        return SDL_SetError("Cannot initialize metrics");
-    }
-
-    Flush_Cache(font);
-
-#if TTF_USE_HARFBUZZ
-    /* Call when size or variations settings on underlying FT_Face change. */
-    hb_ft_font_changed(font->hb_font);
-#endif
-
-    return true;
-}
-
-bool TTF_SetFontSize(TTF_Font *font, float ptsize)
-{
-    return TTF_SetFontSizeDPI(font, ptsize, 0, 0);
-}
-
 /* Update font parameter depending on a style change */
-static int TTF_initFontMetrics(TTF_Font *font)
+static int TTF_InitFontMetrics(TTF_Font *font)
 {
     FT_Face face = font->face;
     int underline_offset;
@@ -2652,117 +2600,6 @@ static bool Find_GlyphMetrics(TTF_Font *font, Uint32 ch, c_glyph **out_glyph)
     return Find_GlyphByIndex(font, idx, 0, 0, 0, 0, 0, out_glyph, NULL);
 }
 
-void TTF_CloseFont(TTF_Font *font)
-{
-    if (font) {
-#if TTF_USE_HARFBUZZ
-        hb_font_destroy(font->hb_font);
-#endif
-        Flush_Cache(font);
-        if (font->props) {
-            SDL_DestroyProperties(font->props);
-        }
-        if (font->face) {
-            FT_Done_Face(font->face);
-        }
-        if (font->stroker) {
-            FT_Stroker_Done(font->stroker);
-        }
-        if (font->args.stream) {
-            SDL_free(font->args.stream);
-        }
-        if (font->closeio) {
-            SDL_CloseIO(font->src);
-        }
-        if (font->pos_buf) {
-            SDL_free(font->pos_buf);
-        }
-        SDL_free(font);
-    }
-}
-
-int TTF_GetFontHeight(const TTF_Font *font)
-{
-    TTF_CHECK_FONT(font, 0);
-
-    return font->height;
-}
-
-int TTF_GetFontAscent(const TTF_Font *font)
-{
-    TTF_CHECK_FONT(font, 0);
-
-    return font->ascent + 2 * font->outline_val;
-}
-
-int TTF_GetFontDescent(const TTF_Font *font)
-{
-    TTF_CHECK_FONT(font, 0);
-
-    return font->descent;
-}
-
-int TTF_GetFontLineSkip(const TTF_Font *font)
-{
-    TTF_CHECK_FONT(font, 0);
-
-    return font->lineskip;
-}
-
-void TTF_SetFontLineSkip(TTF_Font *font, int lineskip)
-{

(Patch may be truncated, please check the link at the top of this post.)