From e4fad3787eabb765d1a04f6fee78b85bebe8a6be Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 5 Jan 2022 22:33:32 +0300
Subject: [PATCH] added TTF_GetFreeTypeVersion and TTF_GetHarfBuzzVersion
---
SDL_ttf.c | 18 +++++++++++++++++-
SDL_ttf.h | 6 ++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/SDL_ttf.c b/SDL_ttf.c
index 5359737..cc4264a 100644
--- a/SDL_ttf.c
+++ b/SDL_ttf.c
@@ -279,7 +279,7 @@ struct _TTF_Font {
#define TTF_STYLE_NO_GLYPH_CHANGE (TTF_STYLE_UNDERLINE | TTF_STYLE_STRIKETHROUGH)
/* The FreeType font engine/library */
-static FT_Library library;
+static FT_Library library = NULL;
static int TTF_initialized = 0;
static SDL_bool TTF_byteswapped = SDL_FALSE;
@@ -1544,6 +1544,21 @@ int TTF_Init(void)
return status;
}
+SDL_COMPILE_TIME_ASSERT(FT_Int, sizeof(int) == sizeof(FT_Int)); /* just in case. */
+void TTF_GetFreeTypeVersion(int *major, int *minor, int *patch)
+{
+ FT_Library_Version(library, major, minor, patch);
+}
+
+void TTF_GetHarfBuzzVersion(unsigned int *major, unsigned int *minor, unsigned int *patch)
+{
+#if TTF_USE_HARFBUZZ
+ hb_version(major, minor, patch);
+#else
+ *major = *minor = *patch = 0;
+#endif
+}
+
static unsigned long RWread(
FT_Stream stream,
unsigned long offset,
@@ -3742,6 +3757,7 @@ void TTF_Quit(void)
if (TTF_initialized) {
if (--TTF_initialized == 0) {
FT_Done_FreeType(library);
+ library = NULL;
}
}
}
diff --git a/SDL_ttf.h b/SDL_ttf.h
index 7bba393..9fcef20 100644
--- a/SDL_ttf.h
+++ b/SDL_ttf.h
@@ -84,6 +84,12 @@ extern "C" {
*/
extern DECLSPEC const SDL_version * SDLCALL TTF_Linked_Version(void);
+/* This function stores the version of the FreeType2 library in use.
+ TTF_Init() should be called before using.
+ */
+extern DECLSPEC void SDLCALL TTF_GetFreeTypeVersion(int *major, int *minor, int *patch);
+extern DECLSPEC void SDLCALL TTF_GetHarfBuzzVersion(unsigned int *major, unsigned int *minor, unsigned int *patch);
+
/* ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) */
#define UNICODE_BOM_NATIVE 0xFEFF
#define UNICODE_BOM_SWAPPED 0xFFFE