diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 5b9f2f2fdbd69..1f7b7c014c8c5 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -3921,6 +3921,28 @@ extern "C" { */ #define SDL_HINT_VIDEO_X11_XRANDR "SDL_VIDEO_X11_XRANDR" +/** + * A variable for disabling Unicode font support in the X11 toolkit. + * + * This hint should be set before creating a messagebox. + * + * \since This hint is available since SDL 3.4.0. + */ +#define SDL_HINT_VIDEO_X11_TOOLKIT_FONT_USE_LATIN "SDL_VIDEO_X11_TOOLKIT_FONT_USE_LATIN" + +/** + * A variable forcing the font for the X11 toolkit. + * + * Please note, the toolkit uses font metrics for calculating the size of UI elements. + * + * Using this hint will cause Unicode font support to be disabled. + * + * This hint should be set before creating a messagebox. + * + * \since This hint is available since SDL 3.4.0. + */ +#define SDL_HINT_VIDEO_X11_TOOLKIT_FONT "SDL_VIDEO_X11_TOOLKIT_FONT" + /** * A variable controlling whether touch should be enabled on the back panel of * the PlayStation Vita. diff --git a/src/video/x11/SDL_x11toolkit.c b/src/video/x11/SDL_x11toolkit.c index 05f78a4c749ff..8c2bc2538fc38 100644 --- a/src/video/x11/SDL_x11toolkit.c +++ b/src/video/x11/SDL_x11toolkit.c @@ -324,6 +324,22 @@ static void X11Toolkit_InitWindowPixmap(SDL_ToolkitWindowX11 *data) { static void X11Toolkit_InitWindowFonts(SDL_ToolkitWindowX11 *window) { + const char *custom_font; + + custom_font = SDL_GetHint(SDL_HINT_VIDEO_X11_TOOLKIT_FONT); + if (custom_font) { + window->utf8 = false; + window->font_set = NULL; + window->font_struct = X11_XLoadQueryFont(window->display, custom_font); + if (window->font_struct) { + return; + } + } + + if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_TOOLKIT_FONT_USE_LATIN, false)) { + goto load_font_traditional; + } + #ifdef X_HAVE_UTF8_STRING window->utf8 = true; window->font_set = NULL; @@ -372,6 +388,9 @@ static void X11Toolkit_InitWindowFonts(SDL_ToolkitWindowX11 *window) char *font; load_font_traditional: +#ifdef X_HAVE_UTF8_STRING + window->font_set = NULL; +#endif window->utf8 = false; SDL_asprintf(&font, g_ToolkitFontLatin1, G_TOOLKITFONT_SIZE * window->iscale); window->font_struct = X11_XLoadQueryFont(window->display, font);