textscreen: Don't allow input of unprintable characters.

If a Unicode character is not part of the Extended ASCII set that
we can display on screen, don't allow it to be typed (which would
display a backwards question mark). Thanks Alexandre-Xavier for this
suggestion on #229.
This commit is contained in:
Simon Howard 2014-10-19 16:52:36 -04:00
parent a8a5d2899a
commit 16c56ea0c4
3 changed files with 28 additions and 3 deletions

View file

@ -322,6 +322,29 @@ static void PutUnicodeChar(unsigned int c)
TXT_PutChar('\xa8');
}
int TXT_CanDrawCharacter(unsigned int c)
{
unsigned int i;
// Standard ASCII range?
if (c < 128)
{
return 1;
}
// Extended ASCII range?
for (i = 0; i < 128; ++i)
{
if (cp437_unicode[i] == c)
{
return 1;
}
}
// Nope.
return 0;
}
void TXT_DrawUTF8String(const char *s)
{
int x, y;

View file

@ -27,6 +27,7 @@ void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h);
void TXT_DrawSeparator(int x, int y, int w);
void TXT_DrawString(const char *s);
void TXT_DrawUTF8String(const char *s);
int TXT_CanDrawCharacter(unsigned int c);
void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range);
void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range);

View file

@ -237,10 +237,11 @@ static int TXT_InputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key)
c = TXT_KEY_TO_UNICODE(key);
if (c >= 128 || isprint(c))
// Add character to the buffer, but only if it's a printable character
// that we can represent on the screen.
if (isprint(c)
|| (c >= 128 && TXT_CanDrawCharacter(c)))
{
// Add character to the buffer
AddCharacter(inputbox, c);
}