From f86cb207e71a270c4cd07eb516d077075b691022 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 27 Aug 2024 19:50:29 -0700
Subject: [PATCH] Use SDL_bool instead an int return code in the SDL API
Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool.
Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test:
@ bool_return_type @
identifier func =~ "^(TTF_GlyphMetrics|TTF_GlyphMetrics32|TTF_Init|TTF_MeasureText|TTF_MeasureUNICODE|TTF_MeasureUTF8|TTF_SetFontDirection|TTF_SetFontLanguage|TTF_SetFontScriptName|TTF_SetFontSDF|TTF_SetFontSize|TTF_SetFontSizeDPI|TTF_SizeText|TTF_SizeUNICODE|TTF_SizeUTF8)$";
@@
(
func(
...
)
- == 0
|
- func(
+ !func(
...
)
- < 0
|
- func(
+ !func(
...
)
- != 0
|
- func(
+ !func(
...
)
- == -1
)
---
cmake/test/main.c | 4 +-
examples/glfont.c | 2 +-
examples/showfont.c | 2 +-
examples/testapp.c | 4 +-
external/SDL | 2 +-
include/SDL3_ttf/SDL_ttf.h | 116 +++++++++++-----------
src/SDL_ttf.c | 197 ++++++++++++++++++-------------------
7 files changed, 160 insertions(+), 167 deletions(-)
diff --git a/cmake/test/main.c b/cmake/test/main.c
index f8d7ac1a..6647948c 100644
--- a/cmake/test/main.c
+++ b/cmake/test/main.c
@@ -10,8 +10,8 @@ int main(int argc, char *argv[])
SDL_Log("SDL_Init: could not initialize SDL: %s", SDL_GetError());
return 1;
}
- if (TTF_Init() == -1) {
- SDL_Log("TTF_Init: %s", TTF_GetError());
+ if (!TTF_Init()) {
+ SDL_Log("TTF_Init: %s", SDL_GetError());
}
TTF_Quit();
SDL_Quit();
diff --git a/examples/glfont.c b/examples/glfont.c
index 9e0f7eb8..4d1aa8eb 100644
--- a/examples/glfont.c
+++ b/examples/glfont.c
@@ -266,7 +266,7 @@ int main(int argc, char *argv[])
}
/* Initialize the TTF library */
- if (TTF_Init() < 0) {
+ if (!TTF_Init()) {
fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
SDL_Quit();
return(2);
diff --git a/examples/showfont.c b/examples/showfont.c
index 4665298e..65ff5c7b 100644
--- a/examples/showfont.c
+++ b/examples/showfont.c
@@ -198,7 +198,7 @@ int main(int argc, char *argv[])
}
/* Initialize the TTF library */
- if (TTF_Init() < 0) {
+ if (!TTF_Init()) {
SDL_Log("Couldn't initialize TTF: %s\n",SDL_GetError());
SDL_Quit();
return(2);
diff --git a/examples/testapp.c b/examples/testapp.c
index 339df150..802be532 100644
--- a/examples/testapp.c
+++ b/examples/testapp.c
@@ -635,7 +635,7 @@ int main(void)
quit("SDL init failed");
}
- if (TTF_Init() < 0) {
+ if (!TTF_Init()) {
SDL_Quit();
quit("SDL_ttf init failed");
}
@@ -898,7 +898,7 @@ int main(void)
}
}
#endif
- if (TTF_SizeUTF8(font, text, &w, &h) < 0) {
+ if (!TTF_SizeUTF8(font, text, &w, &h)) {
SDL_Log("size failed");
}
if (w == 0) {
diff --git a/external/SDL b/external/SDL
index 85bbc602..36a091cc 160000
--- a/external/SDL
+++ b/external/SDL
@@ -1 +1 @@
-Subproject commit 85bbc6028ad36e2c1daa8fac60ae07562077b17e
+Subproject commit 36a091cc43067c62e581d2d1d20b928ca2514519
diff --git a/include/SDL3_ttf/SDL_ttf.h b/include/SDL3_ttf/SDL_ttf.h
index 291d540b..13c50e3b 100644
--- a/include/SDL3_ttf/SDL_ttf.h
+++ b/include/SDL3_ttf/SDL_ttf.h
@@ -132,7 +132,7 @@ typedef struct TTF_Font TTF_Font;
*
* You must successfully call this function before it is safe to call any
* other function in this library, with one exception: a human-readable error
- * message can be retrieved from TTF_GetError() if this function fails.
+ * message can be retrieved from SDL_GetError() if this function fails.
*
* SDL must be initialized before calls to functions in this library, because
* this library uses utility functions from the SDL library.
@@ -141,13 +141,14 @@ typedef struct TTF_Font TTF_Font;
* calls, and decrements it on each call to TTF_Quit, so you must pair your
* init and quit calls.
*
- * \returns 0 on success, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
* \sa TTF_Quit
*/
-extern SDL_DECLSPEC int SDLCALL TTF_Init(void);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_Init(void);
/**
* Create a font from a file, using a specified point size.
@@ -368,11 +369,12 @@ extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPIIO(SDL_IOStream *src,
*
* \param font the font to resize.
* \param ptsize the new point size.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_SetFontSize(TTF_Font *font, int ptsize);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_SetFontSize(TTF_Font *font, int ptsize);
/**
* Set font size dynamically with target resolutions (in DPI).
@@ -383,11 +385,12 @@ extern SDL_DECLSPEC int SDLCALL TTF_SetFontSize(TTF_Font *font, int ptsize);
* \param ptsize the new point size.
* \param hdpi the target horizontal DPI.
* \param vdpi the target vertical DPI.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned int vdpi);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned int vdpi);
/**
* Font style flags
@@ -606,17 +609,17 @@ extern SDL_DECLSPEC int SDLCALL TTF_FontDescent(const TTF_Font *font);
extern SDL_DECLSPEC int SDLCALL TTF_FontLineSkip(const TTF_Font *font);
/**
- * Query whether or not kerning is allowed for a font.
+ * Query whether or not kerning is enabled for a font.
*
* \param font the font to query.
- * \returns non-zero if kerning is enabled, zero otherwise.
+ * \returns SDL_TRUE if kerning is enabled, SDL_FALSE otherwise.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_GetFontKerning(const TTF_Font *font);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_GetFontKerning(const TTF_Font *font);
/**
- * Set if kerning is allowed for a font.
+ * Set if kerning is enabled for a font.
*
* Newly-opened fonts default to allowing kerning. This is generally a good
* policy unless you have a strong reason to disable it, as it tends to
@@ -624,11 +627,11 @@ extern SDL_DECLSPEC int SDLCALL TTF_GetFontKerning(const TTF_Font *font);
* the word `kerning` as something that looks like `keming` for example).
*
* \param font the font to set kerning on.
- * \param allowed non-zero to allow kerning, zero to disallow.
+ * \param enabled SDL_TRUE to enable kerning, SDL_FALSE to disable.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, int allowed);
+extern SDL_DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, SDL_bool enabled);
/**
* Query the number of faces of a font.
@@ -650,11 +653,11 @@ extern SDL_DECLSPEC long SDLCALL TTF_FontFaces(const TTF_Font *font);
* are more likely to not be fixed-width in most cases.
*
* \param font the font to query.
- * \returns non-zero if fixed-width, zero if not.
+ * \returns SDL_TRUE if fixed-width, SDL_FALSE if not.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(const TTF_Font *font);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_FontFaceIsFixedWidth(const TTF_Font *font);
/**
* Query a font's family name.
@@ -702,13 +705,13 @@ extern SDL_DECLSPEC const char * SDLCALL TTF_FontFaceStyleName(const TTF_Font *f
*
* \param font the font to query.
* \param ch the character code to check.
- * \returns non-zero if font provides a glyph for this character, zero if not.
+ * \returns SDL_TRUE if font provides a glyph for this character, SDL_FALSE if not.
*
* \since This function is available since SDL_ttf 3.0.0.
*
* \sa TTF_GlyphIsProvided32
*/
-extern SDL_DECLSPEC int SDLCALL TTF_GlyphIsProvided(TTF_Font *font, Uint16 ch);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_GlyphIsProvided(TTF_Font *font, Uint16 ch);
/**
* Check whether a glyph is provided by the font for a 32-bit codepoint.
@@ -720,11 +723,11 @@ extern SDL_DECLSPEC int SDLCALL TTF_GlyphIsProvided(TTF_Font *font, Uint16 ch);
*
* \param font the font to query.
* \param ch the character code to check.
- * \returns non-zero if font provides a glyph for this character, zero if not.
+ * \returns SDL_TRUE if font provides a glyph for this character, SDL_FALSE if not.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_GlyphIsProvided32(TTF_Font *font, Uint32 ch);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_GlyphIsProvided32(TTF_Font *font, Uint32 ch);
/**
* Query the metrics (dimensions) of a font's 16-bit glyph.
@@ -744,12 +747,14 @@ extern SDL_DECLSPEC int SDLCALL TTF_GlyphIsProvided32(TTF_Font *font, Uint32 ch)
*
* \param font the font to query.
* \param ch the character code to check.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
* \sa TTF_GlyphMetrics32
*/
-extern SDL_DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
int *minx, int *maxx,
int *miny, int *maxy, int *advance);
@@ -767,10 +772,12 @@ extern SDL_DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
*
* \param font the font to query.
* \param ch the character code to check.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch,
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch,
int *minx, int *maxx,
int *miny, int *maxy, int *advance);
@@ -791,14 +798,15 @@ extern SDL_DECLSPEC int SDLCALL TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch,
* \param text text to calculate, in Latin1 encoding.
* \param w will be filled with width, in pixels, on return.
* \param h will be filled with height, in pixels, on return.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
* \sa TTF_SizeUTF8
* \sa TTF_SizeUNICODE
*/
-extern SDL_DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h);
/**
* Calculate the dimensions of a rendered string of UTF-8 text.
@@ -812,13 +820,14 @@ extern SDL_DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, i
* \param text text to calculate, in UTF-8 encoding.
* \param w will be filled with width, in pixels, on return.
* \param h will be filled with height, in pixels, on return.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
* \sa TTF_SizeUNICODE
*/
-extern SDL_DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h);
/**
* Calculate the dimensions of a rendered string of UCS-2 text.
@@ -837,13 +846,14 @@ extern SDL_DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, const char *text, i
* \param text text to calculate, in UCS-2 encoding.
* \param w will be filled with width, in pixels, on return.
* \param h will be filled with height, in pixels, on return.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
* \sa TTF_SizeUTF8
*/
-extern SDL_DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *text, int *w, int *h);
/**
* Calculate how much of a Latin1 string will fit in a given width.
@@ -864,7 +874,8 @@ extern SDL_DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *te
* \param extent on return, filled with latest calculated width.
* \param count on return, filled with number of characters that can be
* rendered.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
@@ -872,7 +883,7 @@ extern SDL_DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, const Uint16 *te
* \sa TTF_MeasureUTF8
* \sa TTF_MeasureUNICODE
*/
-extern SDL_DECLSPEC int SDLCALL TTF_MeasureText(TTF_Font *font, const char *text, int measure_width, int *extent, int *count);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_MeasureText(TTF_Font *font, const char *text, int measure_width, int *extent, int *count);
/**
* Calculate how much of a UTF-8 string will fit in a given width.
@@ -888,7 +899,8 @@ extern SDL_DECLSPEC int SDLCALL TTF_MeasureText(TTF_Font *font, const char *text
* \param extent on return, filled with latest calculated width.
* \param count on return, filled with number of characters that can be
* rendered.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
@@ -896,7 +908,7 @@ extern SDL_DECLSPEC int SDLCALL TTF_MeasureText(TTF_Font *font, const char *text
* \sa TTF_MeasureUTF8
* \sa TTF_MeasureUNICODE
*/
-extern SDL_DECLSPEC int SDLCALL TTF_MeasureUTF8(TTF_Font *font, const char *text, int measure_width, int *extent, int *count);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_MeasureUTF8(TTF_Font *font, const char *text, int measure_width, int *extent, int *count);
/**
* Calculate how much of a UCS-2 string will fit in a given width.
@@ -917,7 +929,8 @@ extern SDL_DECLSPEC int SDLCALL TTF_MeasureUTF8(TTF_Font *font, const char *text
* \param extent on return, filled with latest calculated width.
* \param count on return, filled with number of characters that can be
* rendered.
- * \returns 0 if successful, -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
@@ -925,7 +938,7 @@ extern SDL_DECLSPEC int SDLCALL TTF_MeasureUTF8(TTF_Font *font, const char *text
* \sa TTF_MeasureUTF8
* \sa TTF_MeasureUNICODE
*/
-extern SDL_DECLSPEC int SDLCALL TTF_MeasureUNICODE(TTF_Font *font, const Uint16 *text, int measure_width, int *extent, int *count);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_MeasureUNICODE(TTF_Font *font, const Uint16 *text, int measure_width, int *extent, int *count);
/**
* Render Latin1 text at fast quality to a new 8-bit surface.
@@ -2115,15 +2128,15 @@ extern SDL_DECLSPEC int TTF_GetFontKerningSizeGlyphs32(TTF_Font *font, Uint32 pr
* This clears already-generated glyphs, if any, from the cache.
*
* \param font the font to set SDF support on.
- * \param on_off SDL_TRUE to enable SDF, SDL_FALSE to disable.
- *
- * \returns 0 on success, -1 on error.
+ * \param enabled SDL_TRUE to enable SDF, SDL_FALSE to disable.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*
* \sa TTF_GetFontSDF
*/
-extern SDL_DECLSPEC int TTF_SetFontSDF(TTF_Font *font, SDL_bool on_off);
+extern SDL_DECLSPEC SDL_bool TTF_SetFontSDF(TTF_Font *font, SDL_bool enabled);
/**
* Query whether Signed Distance Field rendering is enabled for a font.
@@ -2138,20 +2151,6 @@ extern SDL_DECLSPEC int TTF_SetFontSDF(TTF_Font *font, SDL_bool on_off);
*/
extern SDL_DECLSPEC SDL_bool TTF_GetFontSDF(const TTF_Font *font);
-/**
- * Report SDL_ttf errors
- *
- * \sa TTF_GetError
- */
-#define TTF_SetError SDL_SetError
-
-/**
- * Get last SDL_ttf error
- *
- * \sa TTF_SetError
- */
-#define TTF_GetError SDL_GetError
-
/**
* Direction flags
*
@@ -2179,11 +2178,12 @@ typedef enum TTF_Direction
*
* \param font the font to specify a direction for.
* \param direction the new direction for text to flow.
- * \returns 0 on success, or -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction);
/**
* Set script to be used for text shaping by a font.
@@ -2195,11 +2195,12 @@ extern SDL_DECLSPEC int SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Directi
*
* \param font the font to specify a script name for.
* \param script null-terminated string of exactly 4 characters.
- * \returns 0 on success, or -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL TTF_SetFontScriptName(TTF_Font *font, const char *script);
+extern SDL_DECLSPEC SDL_bool SDLCALL TTF_SetFontScriptName(TTF_Font *font, const char *script);
/**
* Set language to be used for text shaping by a font.
@@ -2208,11 +2209,12 @@ extern SDL_DECLSPEC int SDLCALL TTF_SetFontScriptName(TTF_Font *font, const char
*
* \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 0 on success, or -1 on error.
+ * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
+ * for more information.
*
* \since This function is available since SDL_ttf 3.0.0.
*/
-extern SDL_DECLSPEC int TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47);
+extern SDL_DECLSPEC SDL_bool TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47);
/**
* Query whether a font is scalable or not.
diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index d469fa91..4e6354c8 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -228,9 +228,9 @@ struct TTF_Font {
int outline_val;
/* Whether kerning is desired */
- int allow_kerning;
+ SDL_bool enable_kerning;
#if !TTF_USE_HARFBUZZ
- int use_kerning;
+ SDL_bool use_kerning;
#endif
/* Extra width in glyph bounds for text styles */
@@ -267,7 +267,7 @@ struct TTF_Font {
hb_direction_t hb_direction;
hb_language_t hb_language;
#endif
- int render_sdf;
+ SDL_bool render_sdf;
/* Extra layout setting for wrapped text */
int horizontal_align;
@@ -289,13 +289,13 @@ static SDL_bool TTF_byteswapped = SDL_FALSE;
#define TTF_CHECK_INITIALIZED(errval) \
if (!TTF_initialized) { \
- TTF_SetError("Library not initialized"); \
+ SDL_SetError("Library not initialized"); \
return errval; \
}
#define TTF_CHECK_POINTER(p, errval) \
if (!(p)) { \
- TTF_SetError("Passed a NULL pointer"); \
+ SDL_SetError("Passed a NULL pointer"); \
return errval; \
}
@@ -314,7 +314,7 @@ typedef enum {
static int TTF_initFontMetrics(TTF_Font *font);
-static int TTF_Size_Internal(TTF_Font *font, const char *text, str_type_t str_type,
+static SDL_bool TTF_Size_Internal(TTF_Font *font, const char *text, str_type_t str_type,
int *w, int *h, int *xstart, int *ystart, int measure_width, int *extent, int *count);
#define NO_MEASUREMENT \
@@ -1617,7 +1617,7 @@ void TTF_ByteSwappedUNICODE(SDL_bool swapped)
}
#if defined(USE_FREETYPE_ERRORS)
-static void TTF_SetFTError(const char *msg, FT_Error error)
+static SDL_bool TTF_SetFTError(const char *msg, FT_Error error)
{
#undef FTERRORS_H_
#define FT_ERRORDEF(e, v, s) { e, s },
@@ -1642,15 +1642,15 @@ static void TTF_SetFTError(const char *msg, FT_Error error)
if (!err_msg) {
err_msg = "unknown FreeType error";
}
- TTF_SetError("%s: %s", msg, err_msg);
+ return SDL_SetError("%s: %s", msg, err_msg);
}
#else
-#define TTF_SetFTError(msg, error) TTF_SetError(msg)
+#define TTF_SetFTError(msg, error) SDL_SetError(msg)
#endif /* USE_FREETYPE_ERRORS */
-int TTF_Init(void)
+SDL_bool TTF_Init(void)
{
- int status = 0;
+ SDL_bool result = SDL_TRUE;
/* Some debug to know how it gets compiled */
#if 0
@@ -1675,11 +1675,10 @@ int TTF_Init(void)
if (!TTF_initialized) {
FT_Error error = FT_Init_FreeType(&library);
if (error) {
- TTF_SetFTError("Couldn't init FreeType engine", error);
- status = -1;
+ result = TTF_SetFTError("Couldn't init FreeType engine", error);
}
}
- if (status == 0) {
+ if (result) {
++TTF_initialized;
#if TTF_USE_SDF
# if 0
@@ -1692,7 +1691,7 @@ int TTF_Init(void)
# endif
#endif
}
- return status;
+ return result;
}
SDL_COMPILE_TIME_ASSERT(FT_Int, sizeof(int) == sizeof(FT_Int)); /* just in case. */
@@ -1746,7 +1745,7 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
int i;
if (!TTF_initialized) {
- TTF_SetError("Library not initialized");
+ SDL_SetError("Library not initialized");
if (src && closeio) {
SDL_CloseIO(src);
}
@@ -1754,14 +1753,14 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
}
if (!src) {
- TTF_SetError("Passed a NULL font source");
+ SDL_SetError("Passed a NULL font source");
return NULL;
}
/* Check to make sure we can seek in this stream */
position = SDL_TellIO(src);
if (position < 0) {
- TTF_SetError("Can't seek in stream");
+ SDL_SetError("Can't seek in stream");
if (closeio) {
SDL_CloseIO(src);
}
@@ -1770,7 +1769,7 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
font = (TTF_Font *)SDL_malloc(sizeof (*font));
if (font == NULL) {
- TTF_SetError("Out of memory");
+ SDL_SetError("Out of memory");
if (closeio) {
SDL_CloseIO(src);
}
@@ -1783,7 +1782,7 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
stream = (FT_Stream)SDL_malloc(sizeof (*stream));
if (stream == NULL) {
- TTF_SetError("Out of memory");
+ SDL_SetError("Out of memory");
TTF_CloseFont(font);
return NULL;
}
@@ -1848,8 +1847,8 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
font->pos_len = 0;
font->pos_max = 16;
font->pos_buf = (PosBuf_t *)SDL_malloc(font->pos_max * sizeof (font->pos_buf[0]));
- if (! font->pos_buf) {
- TTF_SetError("Out of memory");
+ if (!font->pos_buf) {
+ SDL_SetError("Out of memory");
TTF_CloseFont(font);
return NULL;
}
@@ -1857,7 +1856,7 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
#if TTF_USE_HARFBUZZ
font->hb_font = hb_ft_font_create(face, NULL);
if (font->hb_font == NULL) {
- TTF_SetError("Cannot create harfbuzz font");
+ SDL_SetError("Cannot create harfbuzz font");
TTF_CloseFont(font);
return NULL;
}
@@ -1873,7 +1872,7 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
font->hb_language = hb_language_from_string("", -1);
#endif
- if (TTF_SetFontSizeDPI(font, ptsize, hdpi, vdpi) < 0) {
+ if (!TTF_SetFontSizeDPI(font, ptsize, hdpi, vdpi)) {
TTF_SetFTError("Couldn't set font size", error);
TTF_CloseFont(font);
return NULL;
@@ -1881,7 +1880,7 @@ TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize
return font;
}
-int TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned int vdpi)
+SDL_bool TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned int vdpi)
{
FT_Face face = font->face;
FT_Error error;
@@ -1893,16 +1892,14 @@ int TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned i
* are zero, then Freetype's default 72 DPI will be used. */
error = FT_Set_Char_Size(face, 0, ptsize * 64, hdpi, vdpi);
if (error) {
- TTF_SetFTError("Couldn't set font size", error);
- return -1;
+ 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) {
- TTF_SetError("Couldn't select size : no num_fixed_sizes");
- return -1;
+ return SDL_SetError("Couldn't select size : no num_fixed_sizes");
}
/* within [0; num_fixed_sizes - 1] */
@@ -1911,14 +1908,12 @@ int TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned i
error = FT_Select_Size(face, ptsize);
if (error) {
- TTF_SetFTError("Couldn't select size", error);
- return -1;
+ return TTF_SetFTError("Couldn't select size", error);
}
}
if (TTF_initFontMetrics(font) < 0) {
- TTF_SetError("Cannot initialize metrics");
- return -1;
+ return SDL_SetError("Cannot initialize metrics");
}
Flush_Cache(font);
@@ -1928,10 +1923,10 @@ int TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned i
hb_ft_font_changed(font->hb_font);
#endif
- return 0;
+ return SDL_TRUE;
}
-int TTF_SetFontSize(TTF_Font *font, int ptsize)
+SDL_bool TTF_SetFontSize(TTF_Font *font, int ptsize)
{
return TTF_SetFontSizeDPI(font, ptsize, 0, 0);
}
@@ -2099,7 +2094,7 @@ static FT_Error Load_Glyph(TTF_Font *font, c_glyph *cached, int want, int transl
if (want & CACHED_LCD) {
if (slot->format == FT_GLYPH_FORMAT_BITMAP) {
- TTF_SetError("LCD mode not possible with bitmap font");
+ SDL_SetError("LCD mode not possible with bitmap font");
return -1;
}
}
@@ -2863,7 +2858,7 @@ static SDL_bool Char_to_UTF8(Uint32 ch, Uint8 *dst)
*dst++ = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
*dst++ = 0x80 | (Uint8) (ch & 0x3F);
} else {
- TTF_SetError("Invalid character");
+ SDL_SetError("Invalid character");
return SDL_FALSE;
}
*dst = '\0';
@@ -2986,18 +2981,18 @@ int TTF_FontLineSkip(const TTF_Font *font)
return font->lineskip;
}
-int TTF_GetFontKerning(const TTF_Font *font)
+SDL_bool TTF_GetFontKerning(const TTF_Font *font)
{
- return font->allow_kerning;
+ return font->enable_kerning;
}
-void TTF_SetFontKerning(TTF_Font *font, int allowed)
+void TTF_SetFontKerning(TTF_Font *font, SDL_bool enabled)
{
- font->allow_kerning = allowed;
+ font->enable_kerning = enabled;
#if TTF_USE_HARFBUZZ
/* Harfbuzz can do kerning positioning even if the font hasn't the data */
#else
- font->use_kerning = allowed && FT_HAS_KERNING(font->face);
+ font->use_kerning = enabled && FT_HAS_KERNING(font->face);
#endif
}
@@ -3006,7 +3001,7 @@ long TTF_FontFaces(const TTF_Font *font)
return font->face->num_faces;
}
-int TTF_FontFaceIsFixedWidth(const TTF_Font *font)
+SDL_bool TTF_FontFaceIsFixedWidth(const TTF_Font *font)
{
return FT_IS_FIXED_WIDTH(font->face);
}
@@ -3023,31 +3018,31 @@ TTF_FontFaceStyleName(const TTF_Font *font)
return font->face->style_name;
}
-int TTF_GlyphIsProvided(TTF_Font *font, Uint16 ch)
+SDL_bool TTF_GlyphIsProvided(TTF_Font *font, Uint16 ch)
{
- return (int)get_char_index(font, ch);
+ return (get_char_index(font, ch) > 0);
}
-int TTF_GlyphIsProvided32(TTF_Font *font, Uint32 ch)
+SDL_bool TTF_GlyphIsProvided32(TTF_Font *font, Uint32 ch)
{
- return (int)get_char_index(font, ch);
+ return (get_char_index(font, ch) > 0);
}
-int TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
+SDL_bool TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
int *minx, int *maxx, int *miny, int *maxy, int *advance)
{
return TTF_GlyphMetrics32(font, ch, minx, maxx, miny, maxy, advance);
}
-int TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch,
+SDL_bool TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch,
int *minx, int *maxx, int *miny, int *maxy, int *advance)
{
c_glyph *glyph;
- TTF_CHECK_POINTER(font, -1);
+ TTF_CHECK_POINTER(font, SDL_FALSE);
if (Find_GlyphMetrics(font, ch, &glyph) < 0) {
- return -1;
+ return SDL_FALSE;
}
if (minx) {
@@ -3067,10 +3062,10 @@ int TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch,
if (advance) {
*advance = FT_CEIL(glyph->advance);
}
- return 0;
+ return SDL_TRUE;
}
-int TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction)
+SDL_bool TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction)
{
#if TTF_USE_HARFBUZZ
hb_direction_t dir;
@@ -3083,25 +3078,25 @@ int TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction)
} else if (direction == TTF_DIRECTION_BTT) {
dir = HB_DIRECTION_TTB;
} else {
- return -1;
+ return SDL_FALSE;
}
font->hb_direction = dir;
- return 0;
+ return SDL_TRUE;
#else
(void) font;
(void) direction;
- return -1;
+ return SDL_FALSE;
#endif
}
-int TTF_SetFontScriptName(TTF_Font *font, const char *script)
+SDL_bool TTF_SetFontScriptName(TTF_Font *font, const char *script)
{
#if TTF_USE_HARFBUZZ
Uint8 a, b, c, d;
hb_script_t scr;
if (script == NULL || SDL_strlen(script) != 4) {
- return -1;
+ return SDL_FALSE;
}
a = script[0];
@@ -3111,33 +3106,33 @@ int TTF_SetFontScriptName(TTF_Font *font, const char *script)
scr = HB_TAG(a, b,
(Patch may be truncated, please check the link at the top of this post.)