engine: fix UTF-8 sequence input

Fixes: 2e0fc3e4c1 ("engine: client: do not repeatedly check cl_charset value, use generic Con_UtfProcessChar")
This commit is contained in:
Alibek Omarov 2024-06-07 22:16:25 +03:00
parent 929dfd2c71
commit 32d4bdb80f
4 changed files with 25 additions and 16 deletions

View file

@ -632,6 +632,9 @@ typedef struct
int extensions;
netadr_t serveradr;
// do we accept utf8 as input
qboolean accept_utf8;
} client_static_t;
#ifdef __cplusplus

View file

@ -35,7 +35,6 @@ static CVAR_DEFINE_AUTO( scr_drawversion, "1", FCVAR_ARCHIVE, "draw version in m
static CVAR_DEFINE_AUTO( con_oldfont, "0", 0, "use legacy font from gfx.wad, might be missing or broken" );
static int g_codepage = 0;
static qboolean g_utf8 = false;
static qboolean g_messagemode_privileged = true;
@ -635,10 +634,13 @@ int Con_UtfProcessCharForce( int in )
int GAME_EXPORT Con_UtfProcessChar( int in )
{
if( !g_utf8 )
if( !cls.accept_utf8 ) // incoming character is not a UTF-8 sequence
return in;
// otherwise, decode it and convert to selected codepage
return Con_UtfProcessCharForce( in );
}
/*
=================
Con_UtfMoveLeft
@ -652,7 +654,7 @@ int Con_UtfMoveLeft( char *str, int pos )
int k = 0;
int i;
if( !g_utf8 )
if( !cls.accept_utf8 ) // incoming character is not a UTF-8 sequence
return pos - 1;
if( pos == 1 )
@ -679,7 +681,7 @@ int Con_UtfMoveRight( char *str, int pos, int length )
utfstate_t state = { 0 };
int i;
if( !g_utf8 )
if( !cls.accept_utf8 ) // incoming character is not a UTF-8 sequence
return pos + 1;
for( i = pos; i <= length; i++ )
@ -2097,7 +2099,7 @@ void Con_RunConsole( void )
g_codepage = 1252;
}
g_utf8 = !Q_stricmp( cl_charset.string, "utf-8" );
cls.accept_utf8 = !Q_stricmp( cl_charset.string, "utf-8" );
Con_InvalidateFonts();
Con_LoadConchars();
ClearBits( con_charset.flags, FCVAR_CHANGED );

View file

@ -1055,15 +1055,16 @@ static qboolean OSK_KeyEvent( int key, int down )
break;
}
ch = Con_UtfProcessChar((byte)osk.curbutton.val );
ch = (byte)osk.curbutton.val;
// do not pass UTF-8 sequence into the engine, convert it here
if( !cls.accept_utf8 )
ch = Con_UtfProcessCharForce( ch );
if( !ch )
break;
Con_CharEvent( ch );
if( cls.key_dest == key_menu )
UI_CharEvent ( ch );
CL_CharEvent( ch );
break;
}
}
@ -1118,7 +1119,6 @@ static void OSK_EnableTextInput( qboolean enable, qboolean force )
{
osk.curlayout = 0;
osk.curbutton.val = osk_keylayout[osk.curlayout][osk.curbutton.y][osk.curbutton.x];
}
}

View file

@ -357,13 +357,17 @@ SDLash_InputEvent
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
static void SDLash_InputEvent( SDL_TextInputEvent input )
{
char *text;
const char *text;
VGui_ReportTextInput( input.text );
for( text = input.text; *text; text++ )
{
int ch;
int ch = (byte)*text;
ch = Con_UtfProcessChar((byte)*text );
// do not pass UTF-8 sequence into the engine, convert it here
if( !cls.accept_utf8 )
ch = Con_UtfProcessCharForce( ch );
if( !ch )
continue;
@ -453,7 +457,7 @@ SDLash_EventFilter
=============
*/
static void SDLash_EventFilter( SDL_Event *event )
static void SDLash_EventHandler( SDL_Event *event )
{
switch ( event->type )
{
@ -684,7 +688,7 @@ void Platform_RunEvents( void )
SDL_Event event;
while( !host.crashed && !host.shutdown_issued && SDL_PollEvent( &event ) )
SDLash_EventFilter( &event );
SDLash_EventHandler( &event );
#if XASH_PSVITA
PSVita_InputUpdate();