From 5eb9aa9e0fd00bf17fde119db137a73516f10f99 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 18 Mar 2024 14:55:50 -0700 Subject: [PATCH] Updated for the SDL3 RW -> IO changes Fixes https://github.com/libsdl-org/SDL_ttf/issues/344 --- external/SDL | 2 +- include/SDL3_ttf/SDL_ttf.h | 58 +++++++++++++++++++------------------- src/SDL_ttf.c | 58 +++++++++++++++++++------------------- src/SDL_ttf.sym | 8 +++--- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/external/SDL b/external/SDL index 814a94c3..784311c2 160000 --- a/external/SDL +++ b/external/SDL @@ -1 +1 @@ -Subproject commit 814a94c34985c6d3a7fbd906885b1dfea0979925 +Subproject commit 784311c20ee71d769b14f8d500da6c60e2d2b451 diff --git a/include/SDL3_ttf/SDL_ttf.h b/include/SDL3_ttf/SDL_ttf.h index 7fed389e..f54d46a6 100644 --- a/include/SDL3_ttf/SDL_ttf.h +++ b/include/SDL3_ttf/SDL_ttf.h @@ -210,20 +210,20 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize); extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index); /** - * Create a font from an SDL_RWops, using a specified point size. + * Create a font from an SDL_IOStream, using a specified point size. * * Some .fon fonts will have several sizes embedded in the file, so the point * size becomes the index of choosing which size. If the value is too high, * the last indexed size will be the default. * - * If `freesrc` is SDL_TRUE, the RWops will be automatically closed once the - * font is closed. Otherwise you should close the RWops yourself after closing + * If `closeio` is SDL_TRUE, `src` will be automatically closed once the + * font is closed. Otherwise you should close `src` yourself after closing * the font. * * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. * - * \param src an SDL_RWops to provide a font file's data. - * \param freesrc SDL_TRUE to close the RWops when the font is closed, + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio SDL_TRUE to close `src` when the font is closed, * SDL_FALSE to leave it open. * \param ptsize point size to use for the newly-opened font. * \returns a valid TTF_Font, or NULL on error. @@ -232,17 +232,17 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsiz * * \sa TTF_CloseFont */ -extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, SDL_bool freesrc, int ptsize); +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIO(SDL_IOStream *src, SDL_bool closeio, int ptsize); /** - * Create a font from an SDL_RWops, using a specified face index. + * Create a font from an SDL_IOStream, using a specified face index. * * Some .fon fonts will have several sizes embedded in the file, so the point * size becomes the index of choosing which size. If the value is too high, * the last indexed size will be the default. * - * If `freesrc` is SDL_TRUE the RWops will be automatically closed once the - * font is closed. Otherwise you should close the RWops yourself after closing + * If `closeio` is SDL_TRUE `src` will be automatically closed once the + * font is closed. Otherwise you should close `src` yourself after closing * the font. * * Some fonts have multiple "faces" included. The index specifies which face @@ -251,8 +251,8 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, SDL_bool frees * * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. * - * \param src an SDL_RWops to provide a font file's data. - * \param freesrc SDL_TRUE to close the RWops when the font is closed, + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio SDL_TRUE to close `src` when the font is closed, * SDL_FALSE to leave it open. * \param ptsize point size to use for the newly-opened font. * \param index index of the face in the font file. @@ -262,7 +262,7 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, SDL_bool frees * * \sa TTF_CloseFont */ -extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, long index); +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexIO(SDL_IOStream *src, SDL_bool closeio, int ptsize, long index); /** * Create a font from a file, using target resolutions (in DPI). @@ -316,7 +316,7 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPI(const char *file, int ptsize, extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPI(const char *file, int ptsize, long index, unsigned int hdpi, unsigned int vdpi); /** - * Opens a font from an SDL_RWops with target resolutions (in DPI). + * Opens a font from an SDL_IOStream with target resolutions (in DPI). * * DPI scaling only applies to scalable fonts (e.g. TrueType). * @@ -324,14 +324,14 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPI(const char *file, int pt * size becomes the index of choosing which size. If the value is too high, * the last indexed size will be the default. * - * If `freesrc` is SDL_TRUE the RWops will be automatically closed once the - * font is closed. Otherwise you should close the RWops yourself after closing + * If `closeio` is SDL_TRUE `src` will be automatically closed once the + * font is closed. Otherwise you should close `src` yourself after closing * the font. * * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. * - * \param src an SDL_RWops to provide a font file's data. - * \param freesrc SDL_TRUE to close the RWops when the font is closed, + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio SDL_TRUE to close `src` when the font is closed, * SDL_FALSE to leave it open. * \param ptsize point size to use for the newly-opened font. * \param hdpi the target horizontal DPI. @@ -342,10 +342,10 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPI(const char *file, int pt * * \sa TTF_CloseFont */ -extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, unsigned int hdpi, unsigned int vdpi); +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize, unsigned int hdpi, unsigned int vdpi); /** - * Opens a font from an SDL_RWops with target resolutions (in DPI). + * Opens a font from an SDL_IOStream with target resolutions (in DPI). * * DPI scaling only applies to scalable fonts (e.g. TrueType). * @@ -353,8 +353,8 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPIRW(SDL_RWops *src, SDL_bool fr * size becomes the index of choosing which size. If the value is too high, * the last indexed size will be the default. * - * If `freesrc` is SDL_TRUE the RWops will be automatically closed once the - * font is closed. Otherwise you should close the RWops yourself after closing + * If `closeio` is SDL_TRUE `src` will be automatically closed once the + * font is closed. Otherwise you should close `src` yourself after closing * the font. * * Some fonts have multiple "faces" included. The index specifies which face @@ -363,8 +363,8 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPIRW(SDL_RWops *src, SDL_bool fr * * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. * - * \param src an SDL_RWops to provide a font file's data. - * \param freesrc SDL_TRUE to close the RWops when the font is closed, + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio SDL_TRUE to close `src` when the font is closed, * SDL_FALSE to leave it open. * \param ptsize point size to use for the newly-opened font. * \param index index of the face in the font file. @@ -376,7 +376,7 @@ extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontDPIRW(SDL_RWops *src, SDL_bool fr * * \sa TTF_CloseFont */ -extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, long index, unsigned int hdpi, unsigned int vdpi); +extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize, long index, unsigned int hdpi, unsigned int vdpi); /** * Set a font's size dynamically. @@ -2030,14 +2030,14 @@ extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph32_LCD(TTF_Font *font, * \since This function is available since SDL_ttf 3.0.0. * * \sa TTF_OpenFont - * \sa TTF_OpenFontIndexDPIRW - * \sa TTF_OpenFontRW + * \sa TTF_OpenFontIndexDPIIO + * \sa TTF_OpenFontIO * \sa TTF_OpenFontDPI - * \sa TTF_OpenFontDPIRW + * \sa TTF_OpenFontDPIIO * \sa TTF_OpenFontIndex * \sa TTF_OpenFontIndexDPI - * \sa TTF_OpenFontIndexDPIRW - * \sa TTF_OpenFontIndexRW + * \sa TTF_OpenFontIndexDPIIO + * \sa TTF_OpenFontIndexIO */ extern DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font); diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c index f504a7e2..8312d606 100644 --- a/src/SDL_ttf.c +++ b/src/SDL_ttf.c @@ -250,8 +250,8 @@ struct _TTF_Font { FT_UInt cache_index[128]; /* We are responsible for closing the font stream */ - SDL_RWops *src; - SDL_bool freesrc; + SDL_IOStream *src; + SDL_bool closeio; FT_Open_Args args; /* Internal buffer to store positions computed by TTF_Size_Internal() @@ -1719,21 +1719,21 @@ void TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch) } } -static unsigned long RWread( +static unsigned long IOread( FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count ) { - SDL_RWops *src; + SDL_IOStream *src; - src = (SDL_RWops *)stream->descriptor.pointer; - SDL_RWseek(src, offset, SDL_RW_SEEK_SET); - return SDL_RWread(src, buffer, count); + src = (SDL_IOStream *)stream->descriptor.pointer; + SDL_SeekIO(src, offset, SDL_IO_SEEK_SET); + return SDL_ReadIO(src, buffer, count); } -TTF_Font* TTF_OpenFontIndexDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, long index, unsigned int hdpi, unsigned int vdpi) +TTF_Font* TTF_OpenFontIndexDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize, long index, unsigned int hdpi, unsigned int vdpi) { TTF_Font *font; FT_Error error; @@ -1745,8 +1745,8 @@ TTF_Font* TTF_OpenFontIndexDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, l if (!TTF_initialized) { TTF_SetError("Library not initialized"); - if (src && freesrc) { - SDL_RWclose(src); + if (src && closeio) { + SDL_CloseIO(src); } return NULL; } @@ -1757,11 +1757,11 @@ TTF_Font* TTF_OpenFontIndexDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, l } /* Check to make sure we can seek in this stream */ - position = SDL_RWtell(src); + position = SDL_TellIO(src); if (position < 0) { TTF_SetError("Can't seek in stream"); - if (freesrc) { - SDL_RWclose(src); + if (closeio) { + SDL_CloseIO(src); } return NULL; } @@ -1769,15 +1769,15 @@ TTF_Font* TTF_OpenFontIndexDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, l font = (TTF_Font *)SDL_malloc(sizeof (*font)); if (font == NULL) { TTF_SetError("Out of memory"); - if (freesrc) { - SDL_RWclose(src); + if (closeio) { + SDL_CloseIO(src); } return NULL; } SDL_memset(font, 0, sizeof (*font)); font->src = src; - font->freesrc = freesrc; + font->closeio = closeio; stream = (FT_Stream)SDL_malloc(sizeof (*stream)); if (stream == NULL) { @@ -1787,10 +1787,10 @@ TTF_Font* TTF_OpenFontIndexDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, l } SDL_memset(stream, 0, sizeof (*stream)); - stream->read = RWread; + stream->read = IOread; stream->descriptor.pointer = src; stream->pos = (unsigned long)position; - stream->size = (unsigned long)(SDL_RWsize(src) - position); + stream->size = (unsigned long)(SDL_GetIOSize(src) - position); font->args.flags = FT_OPEN_STREAM; font->args.stream = stream; @@ -2007,28 +2007,28 @@ static int TTF_initFontMetrics(TTF_Font *font) return 0; } -TTF_Font* TTF_OpenFontDPIRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, unsigned int hdpi, unsigned int vdpi) +TTF_Font* TTF_OpenFontDPIIO(SDL_IOStream *src, SDL_bool closeio, int ptsize, unsigned int hdpi, unsigned int vdpi) { - return TTF_OpenFontIndexDPIRW(src, freesrc, ptsize, 0, hdpi, vdpi); + return TTF_OpenFontIndexDPIIO(src, closeio, ptsize, 0, hdpi, vdpi); } -TTF_Font* TTF_OpenFontIndexRW(SDL_RWops *src, SDL_bool freesrc, int ptsize, long index) +TTF_Font* TTF_OpenFontIndexIO(SDL_IOStream *src, SDL_bool closeio, int ptsize, long index) { - return TTF_OpenFontIndexDPIRW(src, freesrc, ptsize, index, 0, 0); + return TTF_OpenFontIndexDPIIO(src, closeio, ptsize, index, 0, 0); } TTF_Font* TTF_OpenFontIndexDPI(const char *file, int ptsize, long index, unsigned int hdpi, unsigned int vdpi) { - SDL_RWops *rw = SDL_RWFromFile(file, "rb"); + SDL_IOStream *rw = SDL_IOFromFile(file, "rb"); if ( rw == NULL ) { return NULL; } - return TTF_OpenFontIndexDPIRW(rw, 1, ptsize, index, hdpi, vdpi); + return TTF_OpenFontIndexDPIIO(rw, 1, ptsize, index, hdpi, vdpi); } -TTF_Font* TTF_OpenFontRW(SDL_RWops *src, SDL_bool freesrc, int ptsize) +TTF_Font* TTF_OpenFontIO(SDL_IOStream *src, SDL_bool closeio, int ptsize) { - return TTF_OpenFontIndexRW(src, freesrc, ptsize, 0); + return TTF_OpenFontIndexIO(src, closeio, ptsize, 0); } TTF_Font* TTF_OpenFontDPI(const char *file, int ptsize, unsigned int hdpi, unsigned int vdpi) @@ -2729,8 +2729,8 @@ void TTF_CloseFont(TTF_Font *font) if (font->args.stream) { SDL_free(font->args.stream); } - if (font->freesrc) { - SDL_RWclose(font->src); + if (font->closeio) { + SDL_CloseIO(font->src); } if (font->pos_buf) { SDL_free(font->pos_buf); @@ -3226,7 +3226,7 @@ static int TTF_Size_Internal(TTF_Font *font, /* Layout the text */ hb_buffer_add_utf8(hb_buffer, text, -1, 0, -1); - + hb_feature_t userfeatures[1]; userfeatures[0].tag = HB_TAG('k','e','r','n'); userfeatures[0].value = font->use_kerning; diff --git a/src/SDL_ttf.sym b/src/SDL_ttf.sym index f278e89e..d08df528 100644 --- a/src/SDL_ttf.sym +++ b/src/SDL_ttf.sym @@ -32,12 +32,12 @@ SDL3_ttf_0.0.0 { TTF_MeasureUTF8; TTF_OpenFont; TTF_OpenFontDPI; - TTF_OpenFontDPIRW; + TTF_OpenFontDPIIO; TTF_OpenFontIndex; TTF_OpenFontIndexDPI; - TTF_OpenFontIndexDPIRW; - TTF_OpenFontIndexRW; - TTF_OpenFontRW; + TTF_OpenFontIndexDPIIO; + TTF_OpenFontIndexIO; + TTF_OpenFontIO; TTF_Quit; TTF_RenderGlyph32_Blended; TTF_RenderGlyph32_LCD;