Skip to content

Commit

Permalink
Updated for the SDL3 RW -> IO changes
Browse files Browse the repository at this point in the history
Fixes #344
  • Loading branch information
slouken committed Mar 18, 2024
1 parent 4f82ac7 commit 5eb9aa9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion external/SDL
Submodule SDL updated 486 files
58 changes: 29 additions & 29 deletions include/SDL3_ttf/SDL_ttf.h
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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).
Expand Down Expand Up @@ -316,22 +316,22 @@ 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).
*
* 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.
* \param hdpi the target horizontal DPI.
Expand All @@ -342,19 +342,19 @@ 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).
*
* 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
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
58 changes: 29 additions & 29 deletions src/SDL_ttf.c
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -1757,27 +1757,27 @@ 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;
}

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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/SDL_ttf.sym
Expand Up @@ -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;
Expand Down

0 comments on commit 5eb9aa9

Please sign in to comment.