diff --git a/SDL_ttf.c b/SDL_ttf.c index 3798f82c..db6cdc41 100644 --- a/SDL_ttf.c +++ b/SDL_ttf.c @@ -3128,29 +3128,23 @@ int TTF_SetFontScriptName(TTF_Font *font, const char *script) #endif } -extern DECLSPEC int SDLCALL TTF_GetScript(Uint32 ch, char* script) +extern DECLSPEC int SDLCALL TTF_GetScript(Uint32 ch, char script[5]) { #if TTF_USE_HARFBUZZ + TTF_CHECK_POINTER(script, -1); + hb_buffer_t* hb_buffer = hb_buffer_create(); - if (hb_buffer == NULL) - { + if (hb_buffer == NULL) { TTF_SetError("Cannot create harfbuzz buffer"); return -1; } - if (script == NULL || SDL_strlen(script) != 4) - { - return -1; - } - hb_unicode_funcs_t* hb_unicode_functions = hb_buffer_get_unicode_funcs(hb_buffer); - if (hb_unicode_functions == NULL) - { + if (hb_unicode_functions == NULL) { TTF_SetError("Cannot get harfbuzz unicode funcs"); - hb_buffer_destroy(hb_buffer); return -1; } @@ -3164,6 +3158,7 @@ extern DECLSPEC int SDLCALL TTF_GetScript(Uint32 ch, char* script) script[1] = (char)untagged_script[1]; script[2] = (char)untagged_script[2]; script[3] = (char)untagged_script[3]; + script[4] = '\0'; hb_buffer_destroy(hb_buffer); return 0; diff --git a/SDL_ttf.h b/SDL_ttf.h index ba2cf39f..deacc27a 100644 --- a/SDL_ttf.h +++ b/SDL_ttf.h @@ -2312,19 +2312,21 @@ extern DECLSPEC int SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction d extern DECLSPEC int SDLCALL TTF_SetFontScriptName(TTF_Font *font, const char *script); /** - * Retrieves the script to which unicode character belongs. + * Query the script to which unicode character belongs. * - * The supplied script value must be exactly four characters. + * The supplied script pointer should be able to hold four characters and + * the null-terminator. * * If SDL_ttf was not built with HarfBuzz support, this function returns -1. * - * \param ch the character code to check. - * \param script the script output string. + * \param ch the character to check. + * \param script on return, filled in with the the script as a null-terminated + * string of exactly 4 characters * \returns 0 on success, or -1 on error. * * \since This function is available since SDL_ttf ?. */ -extern DECLSPEC int SDLCALL TTF_GetScript(Uint32 ch, char* script); +extern DECLSPEC int SDLCALL TTF_GetScript(Uint32 ch, char script[5]); /* Ends C function definitions when using C++ */ #ifdef __cplusplus